diff --git a/.pylintrc b/.pylintrc index e7b333c..1ed7d1c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,3 @@ [DEFAULT] ignored-classes=scoped_session,SQLAlchemy -disable=too-few-public-methods,R0201 \ No newline at end of file +disable=too-few-public-methods,R0201,E0237,no-else-return,cyclic-import \ No newline at end of file diff --git a/main/forms.py b/main/forms.py index 634b58b..e8bda37 100644 --- a/main/forms.py +++ b/main/forms.py @@ -6,14 +6,12 @@ # Imports -from flask_wtf import FlaskForm +from flask_wtf import FlaskForm, file from wtforms.fields.core import BooleanField, StringField from wtforms.fields.simple import PasswordField, SubmitField, TextAreaField from wtforms.validators import DataRequired, Email, EqualTo, Length, ValidationError -from flask_wtf.file import FileField, FileAllowed -from main.models import User from flask_login import current_user - +from main.models import User # Form To Make The User Registered @@ -29,7 +27,8 @@ class RegistrationForm(FlaskForm): username = StringField('Username',validators=[DataRequired(), Length(min=2, max=20)]) email = StringField('Email', validators=[DataRequired(), Email()]) password = PasswordField('Password', validators=[DataRequired()]) - password_confirm = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')]) + password_confirm = PasswordField('Confirm Password', + validators=[DataRequired(), EqualTo('password')]) submit = SubmitField('Register') def validate_username(self, username): @@ -56,7 +55,7 @@ def validate_email(self, email): raise ValidationError( 'That email is taken. Please choose a different one.') - + # Login Form class LoginForm(FlaskForm): @@ -152,7 +151,8 @@ class UpdateAccountForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(min=2, max=20)]) email = StringField('Email', validators=[DataRequired(), Email()]) description = TextAreaField('Description', validators=[DataRequired(), Length(3)]) - picture = FileField('Profile Picture', validators=[FileAllowed(['jpg', 'png', 'gif'])]) + picture = file.FileField('Profile Picture', + validators=[file.FileAllowed(['jpg', 'png', 'gif'])]) submit = SubmitField('Update') def validate_username(self, username): diff --git a/main/models.py b/main/models.py index e4bac57..223121b 100644 --- a/main/models.py +++ b/main/models.py @@ -41,7 +41,8 @@ class User(db.Model, UserMixin): email = db.Column(db.String(1000), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) profile_picture = db.Column(db.String(1000), nullable=False, default="default.png") - about_user = db.Column(db.Text, nullable=False, default="This user likes to keep themselves secret, apparently...") + about_user = db.Column(db.Text, nullable=False, + default="This user likes to keep themselves secret, apparently...") post = db.relationship('Post', backref='author', lazy=True) diff --git a/main/routes.py b/main/routes.py index 29c4882..2f67615 100644 --- a/main/routes.py +++ b/main/routes.py @@ -14,7 +14,9 @@ from flask import render_template, redirect, url_for, flash, abort, request from flask_mail import Message from main.models import User, Post -from main.forms import RegistrationForm, LoginForm, NewPostForm, ResetPWDForm, RequestResetPWDForm, UpdateAccountForm +from main.forms import (RegistrationForm, LoginForm, + NewPostForm, ResetPWDForm, + RequestResetPWDForm, UpdateAccountForm) from main import app, bcrypt, db, newsapi, mail @@ -202,6 +204,12 @@ def send_reset_email(user): @app.route("/account", methods=["GET", "POST"]) @login_required def account(): + + """ + :params:none + Page where user can update their info + """ + form = UpdateAccountForm() if form.validate_on_submit(): @@ -216,7 +224,8 @@ def account(): current_user.email = form.email.data current_user.about_user = form.description.data db.session.commit() - flash(f"You account's email was updated to {current_user.email} and username was updated to {current_user.username}", "info") + flash(f"You account's email was updated to {current_user.email} and\ + username was updated to {current_user.username}", "info") return redirect(url_for('account')) elif request.method == "GET": form.username.data = current_user.username @@ -231,11 +240,22 @@ def account(): # User account page (if the user is not the same) @app.route("/user/") def user_info(username): + + """ + :params: username + Returns information about the user + """ + user = User.query.filter_by(username=username).first_or_404() profile_picture = url_for('static', filename=f'profile_pics/{user.profile_picture}') page = request.args.get('page', 1, type=int) - posts = Post.query.filter_by(author=user).order_by(Post.date_posted.desc()).paginate(page=page, per_page=6) - return render_template('user_info.html', profile_picture=profile_picture, posts=posts, user=user) + posts = Post.query.filter_by(author=user).order_by(Post.date_posted.desc()) + posts = posts.paginate(page=page, per_page=6) + return render_template('user_info.html', + profile_picture=profile_picture, + posts=posts, + user=user) + # DevNews