栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

新闻管理系统(三)封装Service和App

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

新闻管理系统(三)封装Service和App

Service模块

  • service_user.py
#!/usr/bin/python3# -*- coding: utf-8 -*-from vega.db.user_dao import UserDaoclass UserService(object):    __user_dao=UserDao()    # 验证用户登录    def login(self, username, password):        result=self.__user_dao.login(username,password)        return result    # 根据用户名搜索角色    def search_user_role(self,username):        role=self.__user_dao.search_user_role(username)        return role

APP程序的作用

  • APP程序用来处理控制台的输入和输出的,因为控制台的操作询问是轮询执行的,所以我们需要在APP中使用死循环
  • app.py
#!/usr/bin/python3# -*- coding: utf-8 -*-import osimport sysimport timefrom colorama import Fore,Stylefrom getpass import getpassfrom service.user_service import UserService__user_service=UserService()while True:    os.system('cls')  # 清理控制台    print(Fore.LIGHTBLUE_EX,"nt=======================")    print(Fore.LIGHTBLUE_EX,"nt欢迎使用新闻管理系统")    print(Fore.LIGHTBLUE_EX,"nt=======================")    print(Fore.LIGHTGREEN_EX,"nt1.登录系统")    print(Fore.LIGHTGREEN_EX,"nt2.退出系统")    print(Style.RESET_ALL)    opt=input("nt输入操作编号:")    if opt=="1":        username=input("nt用户名:")        password=getpass("nt密码:")        result=__user_service.login(username,password)  # getpass可以隐藏密码        # 登录成功        if result:            # 查询角色            role=__user_service.search_user_role(username)            os.system("cls")            while True:                if role=="新闻编辑":print("test")                elif role=="管理员":print(Fore.LIGHTGREEN_EX,"nt1.新闻管理")print(Fore.LIGHTGREEN_EX,"nt2.用户管理")print(Fore.LIGHTRED_EX,"ntback.退出登录")print(Fore.LIGHTRED_EX,"ntexit.退出系统")print(Style.RESET_ALL)opt = input("nt输入操作编号:")if opt=='1': while True:     os.system("cls")     print(Fore.LIGHTGREEN_EX, "nt1.审批新闻")     print(Fore.LIGHTGREEN_EX, "nt2.删除新闻")     print(Fore.LIGHTRED_EX, "ntback.返回上一层")     print(Style.RESET_ALL)     opt = input("nt输入操作编号:")  # TODO:新闻操作elif opt=="back": breakelif opt=="exit": sys.exit(0)        else:            print("nt登录失败(3秒自动返回)")            time.sleep(3)    elif opt=="2":        sys.exit(0)  # 退出系统

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/268459.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号