Skip to content

Commit

Permalink
Format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmishra committed Jul 3, 2021
1 parent ae23ef8 commit 7505800
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[DEFAULT]
ignored-classes=scoped_session,SQLAlchemy
disable=too-few-public-methods,R0201
disable=too-few-public-methods,R0201,E0237,no-else-return,cyclic-import
14 changes: 7 additions & 7 deletions main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
28 changes: 24 additions & 4 deletions main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -231,11 +240,22 @@ def account():
# User account page (if the user is not the same)
@app.route("/user/<string:username>")
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
Expand Down

0 comments on commit 7505800

Please sign in to comment.