Skip to content

Commit

Permalink
finish and debuged
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon-Francis committed Jul 13, 2021
1 parent 5fc1e03 commit c2615f2
Show file tree
Hide file tree
Showing 3,221 changed files with 484,862 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
26 changes: 26 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# coding='utf-8'
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
import pymysql, os

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:123456@127.0.0.1:3306/project3"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = 'gtflyissixsixsix'
app.config['UP_DIR'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/uploads/') # 设置上传文件保存路径
app.config['FC_DIR'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/uploads/users/') # 设置上传文件保存路径
app.debug = True

db = SQLAlchemy(app)

from app.home import home as home_blueprint
from app.admin import admin as admin_blueprint

app.register_blueprint(home_blueprint)
app.register_blueprint(admin_blueprint, url_prefix="/admin")


# 404错误处理
@app.errorhandler(404)
def page_not_found(error):
return render_template('home/404.html'), 404
6 changes: 6 additions & 0 deletions app/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding='utf-8'
from flask import Blueprint

admin = Blueprint("admin", __name__)

import app.admin.views
314 changes: 314 additions & 0 deletions app/admin/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
# coding: utf8
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, FileField, TextAreaField, SelectField, SelectMultipleField
from wtforms.validators import DataRequired, ValidationError, EqualTo
from app.models import Admin, Tag, Role
from flask import session


class LoginForm(FlaskForm):
# 管理员登录表单
account = StringField(
label='账号',
validators=[
DataRequired("请输入账号!")
],
description="账号",
render_kw={
'class': "form-control",
'placeholder': "请输入账号!",
# 'required': 'required' # 输入框如果为空则点登录时会提示
}
)

pwd = PasswordField(
label='密码',
validators=[
DataRequired("请输入密码!")
],
description="密码",
render_kw={
'class': "form-control",
'placeholder': "请输入密码!",
# 'required': 'required'
}
)

submit = SubmitField(
'登录',
render_kw={
'class': "btn btn-primary btn-block btn-flat"
}
)

def validate_account(self, field): # validate + 字段名
account = field.data # 获取到用户名输入
admin = Admin.query.filter_by(name=account).count() # 数据库查询
if admin == 0:
raise ValidationError("账号不存在") # 显示到前端


# 修改密码表单
class PwdForm(FlaskForm):
old_pwd = PasswordField(
label='旧密码',
validators=[
DataRequired("请输入旧密码!")
],
description="旧密码",
render_kw={
'class': "form-control",
'placeholder': "请输入密码!",
}
)

new_pwd = PasswordField(
label='新密码',
validators=[
DataRequired("请输入新密码!")
],
description="新密码",
render_kw={
'class': "form-control",
'placeholder': "请输入新密码!",
}
)

submit = SubmitField(
'确定',
render_kw={
'class': "btn btn-primary btn-block btn-flat"
}
)

def validate_old_pwd(self, field): # validate + 字段名
pwd = field.data # 获取到用户名输入
name = session['admin']
admin = Admin.query.filter_by(name=name).first() # 数据库查询
if not admin.check_pwd(pwd):
raise ValidationError("旧密码错误!") # 显示到前端

def validate_new_pwd(self, field):
pwds = field.data
if len(pwds) < 6:
raise ValidationError("新密码长度不低于6位!")


# 标签Form
class TagForm(FlaskForm):
name = StringField(
label='名称',
validators=[
DataRequired("请输入标签!")
],
description='标签',
render_kw={
'class': "form-control",
'id': "input_name",
'placeholder': "请输入标签名称!"
}
)

submit = SubmitField(
'添加',
render_kw={
'class': "btn btn-primary"
}
)


class MovieForm(FlaskForm):
# 电影片名
title = StringField(
label='片名',
validators=[
DataRequired("请输入片名!")
],
description='片名',
render_kw={
'class': "form-control",
'id': "input_title",
'placeholder': "请输入片名!"
}
)

# 电影文件
url = FileField(
label='文件',
validators=[
DataRequired("请上传文件!")
],
description="文件"
)

# 电影简介
info = TextAreaField(
label='简介',
validators=[
DataRequired("请输入简介!")
],
description='简介',
render_kw={
'class': "form-control",
'rows': "10",
}
)

# 电影封面
logo = FileField(
label='封面',
validators=[
DataRequired("请上传封面!")
],
description="封面"
)

# 电影星级
star = SelectField(
label='星级',
validators=[
DataRequired("请选择星级!")
],
coerce=int,
choices=[(1, "1星"), (2, "2星"), (3, "3星"), (4, "4星"), (5, "5星")],
description="星级",
render_kw={
'class': "form-control",
}
)

# 电影标签
tag_id = SelectField(
label='标签',
validators=[
DataRequired("请选择标签!")
],
coerce=int,
choices=[(v.id, v.name) for v in Tag.query.all()], # 列表生成器生成标签选项
description="标签",
render_kw={
'class': "form-control",
}
)

# 上映地区
area = StringField(
label='地区',
validators=[
DataRequired("请输入地区!")
],
description='地区',
render_kw={
'class': "form-control",
'placeholder': "请输入地区!"
}
)

# 片长
length = StringField(
label='片长',
validators=[
DataRequired("请输入片长!")
],
description='片长',
render_kw={
'class': "form-control",
'placeholder': "请输入片长!"
}
)

# 上映时间
release_time = StringField(
label='上映时间',
validators=[
DataRequired("请选择上映时间!")
],
description='上映时间',
render_kw={
'class': "form-control",
'placeholder': "请选择上映时间!",
'id': 'input_release_time'
}
)

submit = SubmitField(
'确定',
render_kw={
'class': "btn btn-primary"
}
)



class RoleForm(FlaskForm):
name = StringField(
label='角色名称',
validators=[
DataRequired("请输入角色名称!")
],
description='角色名称',
render_kw={
'class': "form-control",
'placeholder': "请输入角色名称!"
}
)

submit = SubmitField(
'确定',
render_kw={
'class': "btn btn-primary"
}
)


class AdminForm(FlaskForm):
name = StringField(
label='管理员名称',
validators=[
DataRequired("请输入管理员名称!")
],
description='管理员名称',
render_kw={
'class': "form-control",
'placeholder': "请输入管理员名称!"
}
)

pwd = StringField(
label='管理员密码',
validators=[
DataRequired("请输入管理员密码!")
],
description='管理员密码',
render_kw={
'class': "form-control",
}
)

repwd = StringField(
label='管理员重复密码',
validators=[
DataRequired("请输入管理员重复密码!"),
EqualTo('pwd', message='两次密码输入不一致!')
],
description='管理员重复密码',
render_kw={
'class': "form-control",
}
)

role_id = SelectField(
label='所属角色',
coerce=int,
choices=[(v.id, v.name) for v in Role.query.all()],
render_kw={
'class': "form-control",
}
)

submit = SubmitField(
'确定',
render_kw={
'class': "btn btn-primary"
}
)
Loading

0 comments on commit c2615f2

Please sign in to comment.