diff --git a/app/main/forms.py b/app/main/forms.py
index 454fc75..c7e71db 100644
--- a/app/main/forms.py
+++ b/app/main/forms.py
@@ -54,3 +54,8 @@ class EditProfileAdminForm(FlaskForm):
class PostForm(FlaskForm):
body = PageDownField("What's on your mind?", validators=[DataRequired()])
submit = SubmitField('Submit')
+
+
+class CommentForm(FlaskForm):
+ body = StringField('', validators=[DataRequired()])
+ submit = SubmitField('Submit')
diff --git a/app/main/views.py b/app/main/views.py
index 003dbbc..c14c365 100644
--- a/app/main/views.py
+++ b/app/main/views.py
@@ -2,9 +2,9 @@ from flask import render_template, redirect, url_for, flash, request, \
current_app, abort, make_response
from flask_login import login_required, current_user
from . import main
-from .forms import EditProfileForm, EditProfileAdminForm, PostForm
+from .forms import EditProfileForm, EditProfileAdminForm, PostForm, CommentForm
from .. import db
-from ..models import User, Role, Permission, Post
+from ..models import User, Role, Permission, Post, Comment
from ..decorators import admin_required, permission_required
@@ -91,10 +91,28 @@ def edit_profile_admin(id):
return render_template('edit_profile.html', form=form, user=user)
-@main.route('/post/
Member since {{ moment(user.member_since).format('L') }}.
Last seen {{ moment(user.last_seen).fromNow() }}.
- {{ user.posts.count() }} blog post{% if user.posts.count() > 1 %}s{% endif %}.
+ {{ user.posts.count() }} blog post{% if user.posts.count() != 1 %}s{% endif %}.
+ {{ user.comments.count() }} comment{% if user.comments.count() != 1 %}s{% endif %}.
+
+ {% for comment in comments %}
+
diff --git a/app/templates/_macros.html b/app/templates/_macros.html
index b5d55a3..a4789c8 100644
--- a/app/templates/_macros.html
+++ b/app/templates/_macros.html
@@ -1,7 +1,7 @@
-{% macro pagination_widget(pagination, endpoint) %}
+{% macro pagination_widget(pagination, endpoint, fragment='') %}
Comments
+{% if current_user.can(Permission.COMMENT) %}
+
{% if current_user.can(Permission.FOLLOW) and user != current_user %} diff --git a/config.py b/config.py index 7094673..af99e58 100644 --- a/config.py +++ b/config.py @@ -16,6 +16,7 @@ class Config: SQLALCHEMY_TRACK_MODIFICATIONS = False FLASKY_POSTS_PER_PAGE = 20 FLASKY_FOLLOWERS_PER_PAGE = 50 + FLASKY_COMMENTS_PER_PAGE = 30 @staticmethod def init_app(app): diff --git a/flasky.py b/flasky.py index a379daf..ba0afa9 100644 --- a/flasky.py +++ b/flasky.py @@ -1,7 +1,7 @@ import os from flask_migrate import Migrate from app import create_app, db -from app.models import User, Role, Permission, Post, Follow +from app.models import User, Role, Permission, Post, Follow, Comment app = create_app(os.getenv('FLASK_CONFIG') or 'default') @@ -11,7 +11,7 @@ migrate = Migrate(app, db) @app.shell_context_processor def make_shell_context(): return dict(db=db, User=User, Follow=Follow, Role=Role, - Permission=Permission, Post=Post) + Permission=Permission, Post=Post, Comment=Comment) @app.cli.command() diff --git a/migrations/versions/643e9b785c28_.py b/migrations/versions/643e9b785c28_.py new file mode 100644 index 0000000..985b3f1 --- /dev/null +++ b/migrations/versions/643e9b785c28_.py @@ -0,0 +1,41 @@ +"""empty message + +Revision ID: 643e9b785c28 +Revises: d1ab608c102a +Create Date: 2018-11-24 23:31:37.923248 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '643e9b785c28' +down_revision = 'd1ab608c102a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('comments', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('body', sa.Text(), nullable=True), + sa.Column('body_html', sa.Text(), nullable=True), + sa.Column('timestamp', sa.DateTime(), nullable=True), + sa.Column('disabled', sa.Boolean(), nullable=True), + sa.Column('author_id', sa.Integer(), nullable=True), + sa.Column('post_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['author_id'], ['users.id'], ), + sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_comments_timestamp'), 'comments', ['timestamp'], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_comments_timestamp'), table_name='comments') + op.drop_table('comments') + # ### end Alembic commands ###