hanze/programmeerles-ouderen

fill.py (43cad8b776692bf46ef4140772871d29e59ea233)
Repositories

commit 43cad8b776692bf46ef4140772871d29e59ea233
parent c2d4aa0de5282f208e5b9610bf68019ce0d43821
Author: Friedel Schön <[email protected]>
Date:   Mon,  4 Apr 2022 14:49:15 +0200

fill.py

Diffstat:
Mflaskblog/forms.py41+++++++++++++++++++++++++----------------
Mflaskblog/models.py2--
Mflaskblog/site.db0
Ainsert.py4++++
4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/flaskblog/forms.py b/flaskblog/forms.py @@ -1,8 +1,11 @@ -from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed from flask_login import current_user -from wtforms import StringField, PasswordField, SubmitField, BooleanField, TextAreaField -from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError +from flask_wtf import FlaskForm +from flask_wtf.file import FileAllowed, FileField +from wtforms import (BooleanField, PasswordField, StringField, SubmitField, + TextAreaField) +from wtforms.validators import (DataRequired, Email, EqualTo, Length, + ValidationError) + from .models import User @@ -19,12 +22,14 @@ class RegistrationForm(FlaskForm): def validate_username(self, username): user = User.query.filter_by(username=username.data).first() if user: - raise ValidationError('That username is taken. Please choose a different one.') + raise ValidationError( + 'That username is taken. Please choose a different one.') def validate_email(self, email): user = User.query.filter_by(email=email.data).first() if user: - raise ValidationError('That email is taken. Please choose a different one.') + raise ValidationError( + 'That email is taken. Please choose a different one.') class LoginForm(FlaskForm): @@ -34,26 +39,31 @@ class LoginForm(FlaskForm): remember = BooleanField('Remember Me') submit = SubmitField('Login') + class UpdateAccountForm(FlaskForm): - username = StringField('Username', - validators=[DataRequired(), Length(min=2, max=20)]) - email = StringField('Email', - validators=[DataRequired(), Email()]) - picture = FileField('Update Profile Picture',validators=[FileAllowed(['jpg','png'])]) + username = StringField('Username', validators=[ + DataRequired(), Length(min=2, max=20)]) + email = StringField('Email', validators=[DataRequired(), Email()]) + picture = FileField('Update Profile Picture', validators=[ + FileAllowed(['jpg', 'png'])]) submit = SubmitField('Update') def validate_username(self, username): if username.data != current_user.username: user = User.query.filter_by(username=username.data).first() if user: - raise ValidationError('That username is taken. Please choose a different one.') + raise ValidationError( + 'That username is taken. Please choose a different one.') def validate_email(self, email): - if email.data != current_user.email: + if email.data != current_user.email: user = User.query.filter_by(email=email.data).first() if user: - raise ValidationError('That email is taken. Please choose a different one.') + raise ValidationError( + 'That email is taken. Please choose a different one.') + + class PostForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) content = TextAreaField('Content', validators=[DataRequired()]) - submit = SubmitField('Post') -\ No newline at end of file + submit = SubmitField('Post') diff --git a/flaskblog/models.py b/flaskblog/models.py @@ -1,5 +1,3 @@ -from datetime import datetime - from flask_login import UserMixin from . import db, login_manager diff --git a/flaskblog/site.db b/flaskblog/site.db Binary files differ. diff --git a/insert.py b/insert.py @@ -0,0 +1,4 @@ +from flaskblog import bcrypt, db, models + +db.session.add(models.User(type='admin', username='admin', email='[email protected]', + password=bcrypt.generate_password_hash('password').decode('utf-8')))