news_dao.py添加新闻列表、总页数、删除新闻功能
from db.mysql_db import pool
class NewsDao(object):
def search_unreview_list(self, page):
try:
con = pool.get_connection()
cursor = con.cursor()
sql="SELECT n.id,n.title,u.username,t.type,n.state " \
"FROM t_news n JOIN t_type t ON n.type_id=t.id " \
"JOIN t_user u ON u.id=n.editor_id " \
"WHERE n.state=%s " \
"ORDER BY n.create_time DESC " \
"LIMIT %s,%s;"
cursor.execute(sql, ('待审批', (page-1)*10, 10))
result = cursor.fetchall()
return result
except Exception as e:
print(e)
finally:
if "con" in dir():
con.close()
def search_unreview_count_page(self):
try:
con = pool.get_connection()
cursor = con.cursor()
sql="SELECT CEIL(COUNT(*)/10) FROM t_news WHERE state=%s"
cursor.execute(sql, ["待审批"])
count_page = cursor.fetchone()[0]
return count_page
except Exception as e:
print(e)
finally:
if "con" in dir():
con.close()
def update_unreview_news(self, id):
try:
con = pool.get_connection()
con.start_transaction()
cursor = con.cursor()
sql="UPDATE t_news SET state=%s WHERE id=%s"
cursor.execute(sql, ("已审批",id))
con.commit()
except Exception as e:
if "con" in dir():
con.rollback()
print(e)
finally:
if "con" in dir():
con.close()
def search_list(self, page):
try:
con