管理信息系统 课程设计

1          系统概要说明

        众所周知,当今社会信息科技日新月异,各种需要的、不需要的信息充斥网络各个角落。当网络用户对某种信息产生需求时,特定主题的网络论坛则是很好的信息来源。

        论坛如同雨后春笋般的出现,并迅速的发展壮大。现在的论坛几乎涵盖了我们生活的各个方面,几乎每一个人都可以找到自己感兴趣或者需要了解的论坛。但综合类的论坛由于广便难于精,于是专题性的论坛继而出现。

        爱美之心人皆有之。生活质量越来越高的今天,人们对于美的需求亦越来越大。但是网络上杂而糙的护肤、化妆的信息难以筛选,故而护肤、化妆方面的信息需要有一个整合信息,并且能够互相交流经验的平台。

        本网站的设计与实现使用了Python+Flask+MysqL的web建设技术,并且使用HTML和CSS/DIV技术使网站页面更具灵活性。主要实现了用户的注册登录、文章分类搜索、个人信息、历史发布等10个功能模块。

2         网站结构设计

3       模块详细设计

3.1         登录、注册、登出

3,2个人中心

 3.3 修改个人信息

 3.4  搜索文章

3.5 文章分类

 3.6  发布文章、评论

4       数据库设计

4.1  E-R图

4.2  数据字典

表4-2-1 用户信息表

表中列名

数据类型

是否为空

说明

id

Int

Not null(主键)

标识id

username

String

Not null

用户名

_password

String

Not null

密码

icon

String

Not null

头像文件名

表4-2-2 问答信息表

表中列名

数据类型

是否为空

说明

id

int

Not null(主键)

标识id

title

string

Not null

题目

detail

text

Not null

内容

creat_time

datetime

Not null

发布时间

author_id

Int

Not null(外键)

作者id

cf

Int

Not null(外键)

分类

look

Int

Not null

浏览量

click

int

Not null

点击量

表4-2-3  评论信息表

表中列名

数据类型

是否为空

说明

id

int

Not null(主键)

标识id

author_id

Int

Not null(外键)

作者id

question_id

Int

Not null(外键)

问答id

creat_time

datetime

Not null

发布时间

detial

text

Not null

内容

表4-2-4问答分类信息表

表中列名

数据类型

是否为空

说明

id

Int

Not null(主键)

标识id

name

string

Not null

分类名称

表4-2-5收藏信息表

表中列名

数据类型

是否为空

说明

id

Int

Not null(主键)

标识id

book_id

Int

Not null(外键)

问答id

collection

Int

Not null(外键)

收藏用户id

creat_time

datetime

Not null

收藏时间

 

5       系统实现的关键算法与数据结构

5.1 登录、注册、登出

# 退出
@app.route('/logout/')
def logout():
    session.pop('username')
    return redirect(url_for('index'))
# 登陆
@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('/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

5.2  个人中心

# 某用户发布过的所有问题、评论,个人信息、我的收藏
@app.route('/comment/<user_id>/<num>')
def comment(user_id, num):
    user = User.query.filter(User.id == user_id).first()
    content = {
        '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)
    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('/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('/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));

5.3 搜索文章

# 模糊查找
@app.route('/search')
def search():
    qu = request.args.get('q')
    c = '' if request.args.get('c') == '' else request.args.get('c')
    query = Question.query.filter(
        or_(
            Question.title.contains(qu),
            Question.detail.contains(qu),
        ),
        Question.cf.like('%' + c + '%'),
    ).order_by('-creat_time').all()
    context = {
        'questions': query,
        'cf': Cf.query.all(),
        'hot': Question.query.order_by('-click').all()[0:4]
    }
    return render_template('index.html', **context)

5.4  文章分类

@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()[0:4],
        'cf': Cf.query.all(),
        'info': info,
        'hot': Question.query.order_by('-click').all()[0:4]
    }
    return render_template('index.html', **context)

5.5  点赞收藏

@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(),
    }
    return render_template('detail.html', **content)

5.6  发布文章、评论

# 发布问答
@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'))
# 发布评论
@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))

 

6     成品展示

6.1首页

6.2 发布问答页

6.3  个人中心

6.4  详情页

6.5登录页

6.6 注册页

6.7 搜索

 

原文地址:https://www.cnblogs.com/888abc/p/9186611.html