管理信息系统 课程设计
Posted pys965085265
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了管理信息系统 课程设计相关的知识,希望对你有一定的参考价值。
1、系统概要说明
本网站是一个“阅读分享”类型的网站,用户通过注册、登录到网站,可以进行发帖、评论、点赞、收藏等功能。用户可以修改自己的头像、密码。用户能够通过搜索,找到带有搜索关键字的文章,实现了组合查询、精确查询和分类查询。网站会根据点赞量前5,将文章推荐给用户。用户也可以查看自己的评论、发帖、收藏文章和个人信息。
网站的设计与实现使用了Python+Flask+mysql的web建设技术,并且使用html和CSS/DIV技术使网站页面更具灵活性。主要实现了用户的注册登录、文章分类搜索、个人信息、历史发布等10个功能模块。
2、网站结构设计
3、模块详细设计
3.1 登录、 注册、退出
3.2个人中心
3.3修改个人信息
3.4 搜索文章
3.5 文章分类
3.6 发布文章、评论
4、数据库设计
帖子分类表 cf
# 分类 class Cf(db.Model): __tablname__ = ‘cf‘ id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 数据库唯识别id name = db.Column(db.String(30)) # 文章名称 context = db.Column(db.TEXT) # 分类内容
收藏表 collection
# 收藏表 Collection = db.Table( ‘collection‘, db.Column(‘id‘, db.Integer, primary_key=True, autoincrement=True), db.Column(‘book_id‘, db.Integer, db.ForeignKey(‘question.id‘)), # 评论对应的文章的id db.Column(‘collection‘, db.Integer, db.ForeignKey(‘user.id‘)), # 收藏用户的id db.Column(‘createdate‘,db.DateTime, default=datetime.now()) # 发布时间 )
评论表 comment
class Comment(db.Model): __tablename__ = ‘comment‘ #评论表 id = db.Column(db.Integer, primary_key=True, autoincrement=True) author_id = db.Column(db.Integer, db.ForeignKey(‘user.id‘)) question_id = db.Column(db.Integer, db.ForeignKey(‘question.id‘)) creat_time = db.Column(db.DateTime, default=datetime.now()) detail = db.Column(db.TEXT, nullable=False) question = db.relationship(‘Question‘, backref=db.backref(‘comment‘)) author = db.relationship(‘User‘, backref=db.backref(‘comment‘, order_by=creat_time.desc)) #此表按发布评论时间,时间新的排在前面
存放帖子的表 question
class Question(db.Model): __tablename__ = ‘question‘ #发布问答表 id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) detail = db.Column(db.Text, nullable=False) creat_time = db.Column(db.DateTime, default=datetime.now) author_id = db.Column(db.Integer, db.ForeignKey(‘user.id‘)) cf = db.Column(db.Integer, db.ForeignKey(‘cf.id‘)) look = db.Column(db.Integer) click = db.Column(db.Integer) author = db.relationship(‘User‘, backref=db.backref(‘question‘)) cfClass = db.relationship(‘Cf‘, backref=db.backref(‘question‘))
用户表 user
class User(db.Model): __tablename__ = ‘user‘ # 建立一个表user id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(20), nullable=False) _password = db.Column(db.String(200), nullable=False) say = db.Column(db.String(50)) icon = db.Column(db.String(50)) collection = db.relationship(‘Question‘, secondary=Collection, backref=db.backref(‘user‘, lazy=‘dynamic‘), lazy=‘dynamic‘) @property #密码加密 def password(self): return self._password @password.setter def password(self, row_password): self._password = generate_password_hash(row_password) def check_password(self, row_password): return check_password_hash(self._password, row_password)
5、系统实现的关键算法与数据结构
注册、验证是否登录、登录、退出
# 注册 @app.route(‘/regist/‘, methods=[‘GET‘, ‘POST‘]) def regist(): if request.method == ‘GET‘: # 打开注册页的模板 return render_template(‘regist.html‘) else: # 收到用户上传的信息 username = request.form.get(‘username‘) password = request.form.get(‘password‘) user = User.query.filter(User.username == username).first() if user: return ‘error:user exitst‘ else: user = User(username=username, password=password) db.session.add(user) # 加入数据库 db.session.commit() return redirect(url_for(‘login‘)) # 定义一个装饰器出验证用户有是否是登陆 # 定义一个参数函数 def loginFirst(func): # 定义一个函数将其返回 @wraps(func) def wrapper(*args, **kwargs): if session.get(‘username‘): return func(*args, **kwargs) else: return redirect(url_for(‘login‘)) # 返回一个函数 return wrapper # 登陆 @app.route(‘/login/‘, methods=[‘GET‘, ‘POST‘]) def login(): if request.method == ‘GET‘: return render_template(‘login.html‘) else: username = request.form.get(‘username‘) password = request.form.get(‘password‘) user = User.query.filter(User.username == username).first() if user: if user.check_password(password): session[‘username‘] = user.username session[‘user_id‘] = user.id session.permanent = True # 重新定位到首页 return redirect(url_for(‘index‘)) else: # 重新定位到注册 return redirect(url_for(‘login‘)) else: return redirect(url_for(‘login‘)) # 退出 @app.route(‘/logout/‘) def logout(): session.pop(‘username‘) return redirect(url_for(‘index‘))
个人中心
# 上传头像 @app.route(‘/uploadLogo/<user_id>‘, methods=[‘GET‘, ‘POST‘]) def uploadLogo(user_id): user = User.query.filter(User.id == user_id).first() f = request.files[‘logo‘] basepath = os.path.dirname(__file__) # 当前文件所在路径 upload_path = os.path.join(basepath, ‘static/uploads‘, f.filename) # 注意:没有的文件夹一定要先创建,不然会提示没有该路径 f.save(upload_path) user.icon = ‘uploads/‘ + f.filename db.session.commit() return redirect(url_for(‘setPassword‘, id=user_id)); # 某用户发布过的所有评论 @app.route(‘/comment/<user_id>/<num>‘) def comment(user_id, num): user = User.query.filter(User.id == user_id).first() content = { ‘username‘: user.username, ‘comment‘: user.comment, ‘questions‘: user.question, ‘user2‘: user, } if (num == ‘1‘): return render_template(‘subComment1.html‘, **content, title=‘全部问题‘) elif (num == ‘2‘): return render_template(‘subComment2.html‘, **content,title=‘全部评论‘) elif (num == ‘3‘): return render_template(‘subComment3.html‘, **content) elif (num == ‘4‘): content = { ‘comment‘: user.comment, ‘questions‘: user.collection.all(), ‘user2‘: user, } return render_template(‘subComment1.html‘, **content, title=‘我的收藏‘) else: return render_template(‘subComment1.html‘, **content) #用户的收藏 @app.route(‘/c/<cf>‘) def c(cf): content = { ‘questions‘: Question.query.filter(Question.cf == cf).order_by(‘-creat_time‘).all(), ‘cf‘: Cf.query.all(), ‘hot‘: Question.query.order_by(‘-click‘).all()[0:5] } return render_template(‘index.html‘, **content)
搜索 查询
# 模糊查找 @app.route(‘/search‘) def search(): qu = request.args.get(‘q‘) c = ‘‘ if request.args.get(‘c‘) == ‘‘ else request.args.get(‘c‘) y = ‘‘ if request.args.get(‘y‘) == ‘‘ else request.args.get(‘y‘) query = Question.query.filter( or_( Question.title.contains(qu), Question.detail.contains(qu), ), Question.cf.like(‘%‘ + c + ‘%‘), Question.creat_time.like(‘%‘ + y + ‘%‘), ).order_by(‘-creat_time‘).all() context = { ‘questions‘: query, ‘cf‘: Cf.query.all(), ‘hot‘: Question.query.order_by(‘-click‘).all()[0:5] } return render_template(‘index.html‘, **context)
更改信息
#重置密码 @app.route(‘/setPassword/<id>‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def setPassword(id): if request.method == ‘GET‘: return render_template(‘setPassword.html‘) else: user = User.query.filter(User.id == id).first() if user: if user.check_password(request.form.get(‘old‘)): user.password = request.form.get(‘new1‘) db.session.commit() info = ‘修改成功‘ else: info = ‘原密码错误‘ else: info = ‘未知错误‘ return redirect(url_for(‘index‘, info=info))
详情页
# 详情页 @app.route(‘/detail/<question_id>‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def detail(question_id): quest = Question.query.filter(Question.id == question_id).first() u = User.query.filter(User.id == session.get(‘user_id‘)).first() if request.method == ‘POST‘: if request.form.get(‘click‘) == ‘1‘: quest.click = quest.click + 1 if request.form.get(‘collection‘) == ‘1‘: user = u user.collection.append(quest) db.session.add(user) col = u.collection.filter_by(id=question_id).first() if col is None: col = {} comment = Comment.query.filter(Comment.question_id == question_id).order_by(‘-creat_time‘).all() quest.look = quest.look + 1 content = { ‘ques‘: quest, ‘comment‘: comment, ‘col‘: col, ‘questions‘: Question.query.filter(Question.cf == quest.cf).all(), } db.session.commit() return render_template(‘detail.html‘, **content)
首页
# 首页 @app.route(‘/‘) def index(): if request.args.get(‘info‘): info = request.args.get(‘info‘) else: info = None; context = { ‘questions‘: Question.query.order_by(‘-creat_time‘).all(), ‘cf‘: Cf.query.all(), ‘info‘: info, ‘hot‘: Question.query.order_by(‘-click‘).all()[0:5] } return render_template(‘index.html‘, **context)
发布评论
# 发布评论 @app.route(‘/answer/‘, methods=[‘GET‘, ‘POST‘]) def answer(): if request.method == ‘POST‘: question_id = request.form.get(‘question_id‘) author_id = request.form.get(‘author_id‘) detail = request.form.get(‘detail‘) comment = Comment(question_id=question_id, author_id=author_id, detail=detail) db.session.add(comment) db.session.commit() return redirect(url_for(‘detail‘, question_id=question_id))
发布帖子
# 发布问答 @app.route(‘/question/‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def question(): if request.method == ‘GET‘: cf = Cf.query.all() return render_template(‘question.html‘, cf=cf) else: title = request.form.get(‘title‘) detail = request.form.get(‘detail‘) author_id = request.form.get(‘author_id‘) cf = request.form.get(‘cf‘) question = Question(title=title, detail=detail, author_id=author_id, cf=cf) db.session.add(question) # 加入数据库 db.session.commit() return redirect(url_for(‘index‘))
6、成品展示
首页
登录页面
注册页面
详情页面
发布帖子页面
更改信息页面
个人信息
以上是关于管理信息系统 课程设计的主要内容,如果未能解决你的问题,请参考以下文章
20155234 2017-2018-1《信息安全系统设计基础》课程总结