新闻管理系统(五)完善新闻管理功能

本文档介绍了如何在新闻管理系统中完善新闻管理功能,包括在`news_dao.py`中添加新闻列表、计算总页数及删除新闻的实现,同时更新了`news_service.py`以支持这些操作,并最终在`app.py`中完成整合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

news_dao.py添加新闻列表、总页数、删除新闻功能

#!/usr/bin/python3
# -*- coding: utf-8 -*-

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值