diff --git a/README.md b/README.md index 9e5f08ec4e1e67652f6bc248270ceedbfd572598..e9e7bb16506c7699aceecc607777cc686e0b1313 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ 1、终端中设置环境变量`$env:FLASK_APP = "flasky.py"` -2、使用flask run启动 \ No newline at end of file +2、使用flask run启动 + +3、开启调试模式`$env:FLASK_DEBUG=1 ` \ No newline at end of file diff --git a/app/auth/forms.py b/app/auth/forms.py index 02d006fb1f4301f06feff13f7b8e84b68be6e838..7c583198ecdce4e5a1c86d15dee9032e43e2fe31 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -15,12 +15,14 @@ from ..models import User class RegistrationForm(FlaskForm): username = StringField('Username', validators=[ - DataRequired(), Length(1, 64), + DataRequired(), + Length(1, 64), Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, 'Usernames must have only letters, numbers, dots or ' 'underscores')]) password = PasswordField('Password', validators=[ - DataRequired(), EqualTo('password2', message='Passwords must match.')]) + DataRequired(), + EqualTo('password2', message='Passwords must match.')]) password2 = PasswordField('Confirm password', validators=[DataRequired()]) submit = SubmitField('Register') diff --git a/app/auth/views.py b/app/auth/views.py index f06f3d694207628e0a556644e88ecc12f68a4aff..ffdb14cd47fa6c6614f6b9c91229adc4ed0c3991 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -55,8 +55,3 @@ def register(): def before_request(): if current_user.is_authenticated: current_user.ping() - # if not current_user.confirmed \ - # and request.endpoint \ - # and request.blueprint != 'auth' \ - # and request.endpoint != 'static': - # return redirect(url_for('auth.unconfirmed')) diff --git a/app/fake.py b/app/fake.py new file mode 100644 index 0000000000000000000000000000000000000000..dd5b3c15be228ae4c6ed7243560eafe38c3f8c93 --- /dev/null +++ b/app/fake.py @@ -0,0 +1,35 @@ +from random import randint +from sqlalchemy.exc import IntegrityError +from faker import Faker +from . import db +from .models import User, Post + + +def users(count=100): + fake = Faker() + i = 0 + while i < count: + u = User(username=fake.user_name(), + password='password', + name=fake.name(), + location=fake.city(), + about_me=fake.text(), + member_since=fake.past_date()) + db.session.add(u) + try: + db.session.commit() + i += 1 + except IntegrityError: + db.session.rollback() + + +def posts(count=100): + fake = Faker() + user_count = User.query.count() + for i in range(count): + u = User.query.offset(randint(0, user_count - 1)).first() + p = Post(body=fake.text(), + timestamp=fake.past_date(), + author=u) + db.session.add(p) + db.session.commit() diff --git a/app/models.py b/app/models.py index 9c45e288ae38e913018f6fc61467b3a6d59ef90e..5d8a03a57e4183626c6515cffa20db6d049ca0ac 100644 --- a/app/models.py +++ b/app/models.py @@ -37,7 +37,6 @@ class Permission: ADMIN = 16 - class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=True) @@ -87,6 +86,7 @@ class Role(db.Model): db.session.add(role) db.session.commit() + class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) @@ -124,6 +124,7 @@ class Post(db.Model): raise ValidationError('post does not have a body') return Post(body=body) + class Follow(db.Model): __tablename__ = 'follows' follower_id = db.Column(db.Integer, db.ForeignKey('users.id'), @@ -132,6 +133,7 @@ class Follow(db.Model): primary_key=True) timestamp = db.Column(db.DateTime, default=datetime.utcnow) + class User(UserMixin, db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) @@ -260,6 +262,7 @@ class AnonymousUser(AnonymousUserMixin): login_manager.anonymous_user = AnonymousUser + class Comment(db.Model): __tablename__ = 'comments' id = db.Column(db.Integer, primary_key=True) @@ -278,6 +281,7 @@ class Comment(db.Model): markdown(value, output_format='html'), tags=allowed_tags, strip=True)) + db.event.listen(Comment.body, 'set', Comment.on_changed_body) @@ -285,4 +289,5 @@ db.event.listen(Comment.body, 'set', Comment.on_changed_body) def load_user(user_id): return User.query.get(int(user_id)) + db.event.listen(Post.body, 'set', Post.on_changed_body) diff --git a/app/templates/auth/login.html b/app/templates/auth/login.html index 6bffeb72174dc507944d11fb52d3e523d3d7d397..a939d0686a0ca3876de9ee21eba3062ab10e7662 100644 --- a/app/templates/auth/login.html +++ b/app/templates/auth/login.html @@ -4,17 +4,20 @@ {% block title %}Flasky - Login{% endblock %} {% block page_content %} - -
- {{ wtf.quick_form(form) }} -
-

- New user? - - Click here to register - -

+
+
+ + {{ wtf.form_field(form.username, class="form-control user-icon") }} + {{ wtf.form_field(form.password, class="form-control password-icon") }} + {{ wtf.form_field(form.remember_me) }} + {{ wtf.form_field(form.submit, class="btn btn-lg btn-primary btn-block") }} +

+ New user? + + Click here to register + +

+
+
{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index b9cf02e5ff3c234efe24b5ee1c25d08180067109..69b8979bc47c5b32507cf94cf28150efa23a0358 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,9 +1,16 @@ {% extends "bootstrap/base.html" %} -{% block title %}Flasky{% endblock %} +{% block title %}First_Blog{% endblock %} + +{% block head %} +{{ super() }} + + + +{% endblock %} {% block navbar %} -