hanze/programmeerles-ouderen

code clean-up (86e6f424a17825a0fc819fab653c90b43a3a0064)
Repositories

commit 86e6f424a17825a0fc819fab653c90b43a3a0064
parent c26c604e9f9283186b0d0298bb42528f7f21ab18
Author: Friedel Schön <[email protected]>
Date:   Fri, 15 Apr 2022 14:46:12 +0200

code clean-up

Diffstat:
Mpgmles/flaskcalendar.py12+++---------
Mpgmles/forms.py73+++++++++++++++++++++++++++++--------------------------------------------
Mpgmles/models.py13+++----------
Mpgmles/routes.py63++++++++++++++++++++++-----------------------------------------
Mpgmles/site.db0
Mpgmles/templates/admin.html54+++++++++++++++++++++++++++---------------------------
Mpgmles/templates/course.html20+++++++++-----------
Dpgmles/templates/create_post.html40----------------------------------------
Dpgmles/templates/home1.html27---------------------------
Mpgmles/templates/index.html18++++++++----------
Mpgmles/templates/layout.html4++--
Dpgmles/templates/post.html41-----------------------------------------
Rpgmles/templates/update_lang.html -> pgmles/templates/update_course.html0
Dpgmles/templates/user_post.html28----------------------------
14 files changed, 103 insertions(+), 290 deletions(-)

diff --git a/pgmles/flaskcalendar.py b/pgmles/flaskcalendar.py @@ -1,16 +1,10 @@ -import enum import random from calendar import Calendar as Month from datetime import datetime -from glob import glob -from pydoc import doc -from sqlalchemy import true +lesson_names = [ 'Python', 'C', 'C++', 'Java', 'JavaScript', None, None, None, None, None, None, None, None ] -lesson_names = ['Python', 'C', 'C++', 'Java', - 'JavaScript', None, None, None, None, None, None, None, None] - -lessons = [None] * 31 +lessons = [ None ] * 31 class Calendar: @@ -35,4 +29,4 @@ class Calendar: for days in m.monthdayscalendar(today.year, today.month): self.rows.append([(i, d, lessons[d]) for i, d in enumerate(days)]) - print(self.rows) +# print(self.rows) diff --git a/pgmles/forms.py b/pgmles/forms.py @@ -1,83 +1,68 @@ from flask_login import current_user from flask_wtf import FlaskForm from flask_wtf.file import FileAllowed, FileField -from wtforms import (BooleanField, HiddenField, PasswordField, StringField, - SubmitField, TextAreaField, SelectField) -from wtforms.validators import (DataRequired, Email, EqualTo, Length, - ValidationError) +from wtforms import BooleanField, HiddenField, PasswordField, SelectField, StringField, SubmitField, TextAreaField +from wtforms.validators import DataRequired, Email, EqualTo, Length, ValidationError from .models import User class RegistrationForm(FlaskForm): - username = StringField('Username', - validators=[DataRequired(), Length(min=2, max=20)]) - email = StringField('Email', - validators=[DataRequired(), Email()]) - password = PasswordField('Password', validators=[DataRequired()]) - confirm_password = PasswordField('Confirm Password', - validators=[DataRequired(), EqualTo('password')]) + username = StringField('Username', validators=[ DataRequired(), Length(min=2, max=20) ]) + email = StringField('Email', validators=[ DataRequired(), Email() ]) + password = PasswordField('Password', validators=[ DataRequired() ]) + confirm_password = PasswordField('Confirm Password', validators=[ DataRequired(), EqualTo('password') ]) submit = SubmitField('Sign Up') 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.') + if User.query.filter_by(username=username.data).first(): + 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.') + if User.query.filter_by(email=email.data).first(): + raise ValidationError('That email is taken. Please choose a different one.') class LoginForm(FlaskForm): - email = StringField('Email', - validators=[DataRequired(), Email()]) - password = PasswordField('Password', validators=[DataRequired()]) + email = StringField('Email', validators=[ DataRequired(), Email() ]) + password = PasswordField('Password', validators=[ DataRequired() ]) 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: 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 LanguageForm(FlaskForm): - name = StringField('Name', validators=[DataRequired()]) - info = TextAreaField('Info', validators=[DataRequired()]) + name = StringField('Name', validators=[ DataRequired() ]) + info = TextAreaField('Info', validators=[ DataRequired() ]) submit = SubmitField('Update') + class NewCourseForm(FlaskForm): - name = StringField('Title', validators=[ - DataRequired(), Length(min=1, max=100)]) - description = TextAreaField('Description', validators=[DataRequired()]) - teacher_id = SelectField('Teacher', validators=[DataRequired()], coerce=int) - weekday = StringField('Weekday', validators=[DataRequired()]) - start = StringField('Start', validators=[DataRequired()]) - end = StringField('End', validators=[DataRequired()]) - location = StringField('Location', validators=[ - DataRequired(), Length(min=1, max=100)]) + name = StringField('Title', validators=[ DataRequired(), Length(min=1, max=100) ]) + description = TextAreaField('Description', validators=[ DataRequired() ]) + teacher_id = SelectField('Teacher', validators=[ DataRequired() ], coerce=int) + weekday = StringField('Weekday', validators=[ DataRequired() ]) + start = StringField('Start', validators=[ DataRequired() ]) + end = StringField('End', validators=[ DataRequired() ]) + location = StringField('Location', validators=[ DataRequired(), Length(min=1, max=100) ]) submit = SubmitField('Add') @@ -92,6 +77,6 @@ class UnsubscribeForm(FlaskForm): class PostForm(FlaskForm): # redundant - title = StringField('Title', validators=[DataRequired()]) - content = TextAreaField('Content', validators=[DataRequired()]) + title = StringField('Title', validators=[ DataRequired() ]) + content = TextAreaField('Content', validators=[ DataRequired() ]) submit = SubmitField('Post') diff --git a/pgmles/models.py b/pgmles/models.py @@ -15,8 +15,7 @@ class User(db.Model, UserMixin): type = db.Column(db.String(6), nullable=False, default="client") username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) - image_file = db.Column(db.String(20), nullable=False, - default='default.jpg') + image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) def __repr__(self): @@ -27,8 +26,7 @@ class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) description = db.Column(db.Text, nullable=False) - teacher_id = db.Column( - db.Integer, db.ForeignKey('user.id'), nullable=False) + teacher_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) weekday = db.Column(db.Integer, nullable=False) start = db.Column(db.String(10), nullable=False, default=datetime.utcnow) end = db.Column(db.String(10), nullable=False, default=datetime.utcnow) @@ -40,10 +38,5 @@ class Course(db.Model): class CourseMember(db.Model): id = db.Column(db.Integer, primary_key=True) - course_id = db.Column(db.Integer, db.ForeignKey( - 'course.id'), nullable=False) + course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) - -# date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) -# content = db.Column(db.Text, nullable=False) -# user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) diff --git a/pgmles/routes.py b/pgmles/routes.py @@ -1,13 +1,12 @@ import os import secrets -from flask import abort, flash, redirect, render_template, request, url_for +from flask import flash, redirect, render_template, request, url_for from flask_login import current_user, login_required, login_user, logout_user from PIL import Image from . import app, bcrypt, calendar, db -from .forms import (LanguageForm, LoginForm, PostForm, RegistrationForm, - SubscribeForm, UnsubscribeForm, UpdateAccountForm, NewCourseForm) +from .forms import LoginForm, NewCourseForm, RegistrationForm, SubscribeForm, UnsubscribeForm, UpdateAccountForm from .models import Course, CourseMember, User @@ -15,30 +14,23 @@ from .models import Course, CourseMember, User def index(): courses = Course.query.all() subscriptions = [] - teachers = [[teacher.id, teacher.username] for teacher in User.query.filter_by(type='teacher')] + teachers = User.query.filter_by(type='teacher') if current_user.is_authenticated: - subscriptions = [cm.course_id for cm in CourseMember.query.filter_by( - user_id=current_user.id)] -# for coursemember in members: -# course[] = Course.id + subscriptions = [ cm.course_id for cm in CourseMember.query.filter_by(user_id=current_user.id) ] return render_template('index.html', calendar=calendar, courses=courses, subs=subscriptions, teachers=teachers) - @app.route("/about") def about(): return render_template('about.html', calendar=calendar, title='About') - @app.route("/register", methods=['GET', 'POST']) def register(): if current_user.is_authenticated: return redirect('/') form = RegistrationForm() if form.validate_on_submit(): - hashed_password = bcrypt.generate_password_hash( - form.password.data).decode('utf-8') - user = User(username=form.username.data, - email=form.email.data, password=hashed_password) + hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') + user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') @@ -56,24 +48,21 @@ def login(): if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') - return redirect(next_page) if next_page else redirect('/') + return redirect(next_page if next_page else '/') else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', calendar=calendar, title='Login', form=form) - @app.route("/logout") def logout(): logout_user() return redirect('/') - def save_picture(form_picture): random_hex = secrets.token_hex(8) _, f_ext = os.path.splitext(form_picture.filename) picture_fn = random_hex + f_ext - picturepath = os.path.join( - app.root_path, 'static/profile_pics', picture_fn) + picturepath = os.path.join(app.root_path, 'static/profile_pics', picture_fn) output_size = (125, 125) i = Image.open(form_picture) @@ -82,8 +71,7 @@ def save_picture(form_picture): return picture_fn - [email protected]("/account", methods=['GET', 'POST']) [email protected]("/account", methods=[ 'GET', 'POST' ]) @login_required def account(): form = UpdateAccountForm() @@ -99,35 +87,31 @@ def account(): elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email - image_file = url_for( - 'static', filename='profile_pics/' + current_user.image_file) + image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('account.html', calendar=calendar, title='Account', image_file=image_file, form=form) - @app.route("/admin") def admin(): courses = Course.query.all() return render_template('admin.html', calendar=calendar, title='Administration Page', courses=courses) [email protected]("/admin/new_course", methods=['GET', 'POST']) + [email protected]("/admin/new_course", methods=[ 'GET', 'POST' ]) def new_course(): form = NewCourseForm() - form.teacher_id.choices = [(g.id, g.username) for g in User.query.filter_by(type='teacher')] + form.teacher_id.choices = [ (g.id, g.username) for g in User.query.filter_by(type='teacher') ] if form.validate_on_submit(): - course = Course(name=form.name.data, description=form.description.data,\ - teacher_id=form.teacher_id.data, weekday=form.weekday.data,\ - start=form.start.data, end=form.end.data, location=form.location.data) + course = Course(name=form.name.data, description=form.description.data, teacher_id=form.teacher_id.data, weekday=form.weekday.data, start=form.start.data, end=form.end.data, location=form.location.data) db.session.add(course) db.session.commit() flash('The course has been created!', 'success') return redirect(url_for('admin')) return render_template('new_course.html', calendar=calendar, title='New Course', form=form) - [email protected]("/admin/update/<int:course_id>", methods=['GET', 'POST']) [email protected]("/admin/update/<int:course_id>", methods=[ 'GET', 'POST' ]) def update_lang(course_id): form = NewCourseForm() - form.teacher_id.choices = [(g.id, g.username) for g in User.query.filter_by(type='teacher')] + form.teacher_id.choices = [ (g.id, g.username) for g in User.query.filter_by(type='teacher') ] course = Course.query.get_or_404(course_id) if form.validate_on_submit(): course.name = form.name.data @@ -148,18 +132,16 @@ def update_lang(course_id): form.start.data = course.start form.end.data = course.end form.location.data = course.location - return render_template('update_lang.html', calendar=calendar, form=form, legend='Update Language') - + return render_template('update_course.html', calendar=calendar, form=form, legend='Update Language') [email protected]("/course/<int:course_id>", methods=['GET', 'POST']) [email protected]("/course/<int:course_id>", methods=[ 'GET', 'POST' ]) def course(course_id): form = SubscribeForm() form2 = UnsubscribeForm() - teachers = [[teacher.id, teacher.username] for teacher in User.query.filter_by(type='teacher')] + teachers = User.query.filter_by(type='teacher') subscribed = None if current_user.is_authenticated: - subscribed = CourseMember.query.filter_by( - user_id=current_user.id, course_id=course_id).first() + subscribed = CourseMember.query.filter_by(user_id=current_user.id, course_id=course_id).first() if form.validate_on_submit() and not subscribed: course = CourseMember(user_id=current_user.id, course_id=course_id) @@ -177,9 +159,9 @@ def course(course_id): course = Course.query.get_or_404(course_id) return render_template('course.html', calendar=calendar, title=course.name, course=course, form=form, form2=form2, show=not subscribed, teachers=teachers) [email protected]("/delete_course/<int:course_id>", methods=['GET','POST']) [email protected]("/delete_course/<int:course_id>", methods=['GET', 'POST']) def delete_course(course_id): course = Course.query.get_or_404(course_id) db.session.delete(course) db.session.commit() - return redirect(url_for('index')) -\ No newline at end of file + return redirect(url_for('index')) diff --git a/pgmles/site.db b/pgmles/site.db Binary files differ. diff --git a/pgmles/templates/admin.html b/pgmles/templates/admin.html @@ -1,34 +1,34 @@ {% extends "layout.html" %} {% block content %} -<a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('new_course') }}">New Course</a> - {% for course in courses %} - <article class="media content-section"> - <div class="media-body"> - <h2><a class="article-title" href="{{url_for('course', course_id=course.id)}}">{{course.name}}</a></h2> - <div> - <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('update_lang', course_id = course.id) }}">Update</a> - <button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button> - </div> + <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('new_course') }}">New Course</a> + {% for course in courses %} + <article class="media content-section"> + <div class="media-body"> + <h2><a class="article-title" href="{{ url_for('course', course_id=course.id) }}">{{course.name}}</a></h2> + <div> + <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('update_lang', course_id = course.id) }}">Update</a> + <button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button> </div> - </article> - <!-- Modal --> - <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true"> - <div class="modal-dialog" role="document"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="deleteModalLabel">Delete Post?</h5> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"> - <span aria-hidden="true">&times;</span> - </button> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> - <form action="{{ url_for('delete_course', course_id=course.id) }}" method="POST"> - <input class="btn btn-danger" type="submit" value="Delete"> - </form> - </div> + </div> + </article> + <!-- Modal --> + <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="deleteModalLabel">Delete Post?</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">&times;</span> + </button> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> + <form action="{{ url_for('delete_course', course_id=course.id) }}" method="POST"> + <input class="btn btn-danger" type="submit" value="Delete"> + </form> </div> </div> </div> - {% endfor %} + </div> + {% endfor %} {% endblock content %} diff --git a/pgmles/templates/course.html b/pgmles/templates/course.html @@ -3,19 +3,17 @@ <article class="media content-section"> <div class="media-body"> <h2><a class="article-title" href="{{url_for('course', course_id=course.id)}}"> - {{course.name}} - {% if course.id in subs %}(subscribed){% endif %} + {{ course.name }} + {{ '(subscribed)' if course.id in subs }} </a></h2> - <p> {{course.description}}</p> - <p>De Cursus {{course.name}} wordt gegeven door - {%for x in teachers%} - {%if x[0] == course.teacher_id%} - {{x[1]}} - {%endif%} - {%endfor%} + <p>{{course.description}}</p> + <p>De cursus <b>{{course.name}}</b> wordt gegeven door + {% for teacher in teachers %} + {{ teacher.username if teacher.id == course.teacher_id }} + {% endfor %} </p> - <p>Start elke {{course.weekday}} vanaf {{course.start}} tot {{course.end}} op locatie: {{course.location}}</p> - </div> + <p>Elke {{ ['maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag', 'zondag'][course.weekday] }}, {{ course.start }} uur t/m {{ course.end }} uur op locatie: {{ course.location }}</p> + </div> <div class="article-metadata"> {% if current_user.is_authenticated %} {% if show %} diff --git a/pgmles/templates/create_post.html b/pgmles/templates/create_post.html @@ -1,40 +0,0 @@ -{% extends "layout.html" %} -{% block content %} -<div class="content-section"> - <form method="POST" action=""> - {{ form.hidden_tag() }} - <fieldset class="form-group"> - <legend class="border-bottom mb-4">{{ legend }}</legend> - <div class="form-group"> - {{ form.title.label(class="form-control-label") }} - {% if form.title.errors %} - {{ form.title(class="form-control form-control-lg is-invalid") }} - <div class="invalid-feedback"> - {% for error in form.title.errors %} - <span>{{ error }}</span> - {% endfor %} - </div> - {% else %} - {{ form.title(class="form-control form-control-lg") }} - {% endif %} - </div> - <div class="form-group"> - {{ form.content.label(class="form-control-label") }} - {% if form.content.errors %} - {{ form.content(class="form-control form-control-lg is-invalid") }} - <div class="invalid-feedback"> - {% for error in form.content.errors %} - <span>{{ error }}</span> - {% endfor %} - </div> - {% else %} - {{ form.content(class="form-control form-control-lg") }} - {% endif %} - </div> - </fieldset> - <div class="form-group"> - {{ form.submit(class="btn btn-outline-info") }} - </div> - </form> -</div> -{% endblock content %} diff --git a/pgmles/templates/home1.html b/pgmles/templates/home1.html @@ -1,27 +0,0 @@ -{% extends "layout.html" %} -{% block content %} - {% for language in language.items %} - <article class="media content-section"> - <!-- <img class="rounded-circle article-img" src="{{ url_for('static', filename='profile_pics/' + post.author.image_file) }}">--> - <div class="media-body"> - <div class="article-metadata"> - <!--<a class="mr-2" href="{{ url_for('user_posts', username=language.author.username)}}">{{ post.author.username }}</a> - <small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>--> - </div> - <!--<h2><a class="article-title" href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}</a></h2>--> - <!--<p class="article-content">{{ post.content }}</p>--> - </div> - </article> - {% endfor %} - <!--{% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %} - {% if page_num %} - {% if posts.page == page_num%} - <a class="btn btn-info mb-4"href="{{url_for('home', page=page_num)}}">{{page_num}}</a> - {% else %} - <a class="btn btn-outline-info mb-4"href="{{url_for('home', page=page_num)}}">{{page_num}}</a> - {% endif %} - {% else %} - ... - {% endif %} - {% endfor %}--> -{% endblock content %} diff --git a/pgmles/templates/index.html b/pgmles/templates/index.html @@ -4,18 +4,16 @@ <article class="media content-section"> <div class="media-body"> <h2><a class="article-title" href="{{url_for('course', course_id=course.id)}}"> - {{course.name}} - {% if course.id in subs %}(subscribed){% endif %} + {{ course.name }} + {{ '(subscribed)' if course.id in subs }} </a></h2> - <p> {{course.description}}</p> - <p>De Cursus {{course.name}} wordt gegeven door - {%for x in teachers%} - {%if x[0] == course.teacher_id%} - {{x[1]}} - {%endif%} - {%endfor%} + <p>{{course.description}}</p> + <p>De cursus <b>{{course.name}}</b> wordt gegeven door + {% for teacher in teachers %} + {{ teacher.username if teacher.id == course.teacher_id }} + {% endfor %} </p> - <p>Start elke {{course.weekday}} vanaf {{course.start}} tot {{course.end}} op locatie: {{course.location}}</p> + <p>Elke {{ ['maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag', 'zondag'][course.weekday] }}, {{ course.start }} uur t/m {{ course.end }} uur op locatie: {{ course.location }}</p> </div> </article> {% endfor %} diff --git a/pgmles/templates/layout.html b/pgmles/templates/layout.html @@ -26,8 +26,8 @@ </button> <div class="collapse navbar-collapse" id="navbarToggle"> <div class="navbar-nav mr-auto"> - <a class="nav-item nav-link" href="{{ '/' }}">Home</a> - <a class="nav-item nav-link" href="{{ '/' }}">About</a> + <a class="nav-item nav-link" href="/">Home</a> + <a class="nav-item nav-link" href="/">About</a> </div> <!-- Navbar Right Side --> <div class="navbar-nav"> diff --git a/pgmles/templates/post.html b/pgmles/templates/post.html @@ -1,41 +0,0 @@ -{% extends "layout.html" %} -{% block content %} - <article class="media content-section"> - <img class="rounded-circle article-img" src="{{ url_for('static', filename='profile_pics/' + post.author.image_file) }}"> - <div class="media-body"> - <div class="article-metadata"> - <a class="mr-2" href="{{ url_for('user_posts', username=post.author.username)}}">{{ post.author.username }}</a> - <small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small> - {% if post.author == current_user %} - <div> - <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{{ url_for('update_post', post_id=post.id)}}">Update</a> - <button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deletemodal">Delete</button> - </div> - {% endif %} - </div> - <h2 class="article-title">{{ post.title }}</h2> - <p class="article-content">{{ post.content }}</p> - </div> - </article> - <!-- Modal --> - <div class="modal fade" id="deletemodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> - <div class="modal-dialog" role="document"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="deletemodal">Delete Post?</h5> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"> - <span aria-hidden="true">&times;</span> - </button> - </div> - <div class="modal-body"> - Are you sure you want to delete this post? - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> - <form action="{{ url_for('delete_post', post_id=post.id) }}" method="POST"> - <input class="btn btn-danger" type="submit" value="Delete"> - </div> - </div> - </div> - </div> -{% endblock content %} diff --git a/pgmles/templates/update_lang.html b/pgmles/templates/update_course.html diff --git a/pgmles/templates/user_post.html b/pgmles/templates/user_post.html @@ -1,28 +0,0 @@ -{% extends "layout.html" %} -{% block content %} - <h1 class="mb-3">Posts by {{ user.username }} ({{ posts.total }})</h1> - {% for post in posts.items %} - <article class="media content-section"> - <img class="rounded-circle article-img" src="{{ url_for('static', filename='profile_pics/' + post.author.image_file) }}"> - <div class="media-body"> - <div class="article-metadata"> - <a class="mr-2" href="{{ url_for('user_posts', username=post.author.username)}}">{{ post.author.username }}</a> - <small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small> - </div> - <h2><a class="article-title" href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}</a></h2> - <p class="article-content">{{ post.content }}</p> - </div> - </article> - {% endfor %} - {% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %} - {% if page_num %} - {% if posts.page == page_num%} - <a class="btn btn-info mb-4"href="{{url_for('user_posts', username=user.username, page=page_num)}}">{{page_num}}</a> - {% else %} - <a class="btn btn-outline-info mb-4" href="{{url_for('user_posts', username=user.username, page=page_num)}}">{{page_num}}</a> - {% endif %} - {% else %} - ... - {% endif %} - {% endfor %} -{% endblock content %}