Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Jan 25, 2025
1 parent 4cc9203 commit 33a1135
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion greybook/blueprints/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def show_post(post_id):
from_admin = False
reviewed = False

if form.validate_on_submit():
if post.can_comment and form.validate_on_submit():
author = form.author.data
email = form.email.data
site = form.site.data
Expand Down
2 changes: 1 addition & 1 deletion greybook/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def lorem_command(category, post, comment, reply):
db.drop_all()
db.create_all()

click.echo('Generated the administrator.')
fake_admin()
click.echo('Generated the administrator.')

fake_categories(category)
click.echo(f'Generated {category} categories.')
Expand Down
8 changes: 4 additions & 4 deletions greybook/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from datetime import datetime, timezone
from typing import List, Optional
from typing import Optional

from flask import current_app, url_for
from flask_login import UserMixin
Expand Down Expand Up @@ -46,7 +46,7 @@ class Category(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(30), unique=True)

posts: Mapped[List['Post']] = relationship(back_populates='category')
posts: Mapped[list['Post']] = relationship(back_populates='category')

def __repr__(self):
return f'<Category {self.id}: {self.name}>'
Expand All @@ -73,7 +73,7 @@ class Post(db.Model):
category_id: Mapped[int] = mapped_column(ForeignKey('category.id'))

category: Mapped['Category'] = relationship(back_populates='posts')
comments: Mapped[List['Comment']] = relationship(back_populates='post', cascade='all, delete-orphan')
comments: Mapped[list['Comment']] = relationship(back_populates='post', cascade='all, delete-orphan')

def __repr__(self):
return f'<Post {self.id}: {self.title}>'
Expand Down Expand Up @@ -113,7 +113,7 @@ class Comment(db.Model):
post_id: Mapped[int] = mapped_column(ForeignKey('post.id'))

post: Mapped['Post'] = relationship(back_populates='comments')
replies: Mapped[List['Comment']] = relationship(back_populates='replied', cascade='all, delete-orphan')
replies: Mapped[list['Comment']] = relationship(back_populates='replied', cascade='all, delete-orphan')
replied: Mapped['Comment'] = relationship(back_populates='replies', remote_side=[id])

def __repr__(self):
Expand Down
14 changes: 6 additions & 8 deletions greybook/templates/admin/manage_post.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ <h1>Posts
</td>
<td>{{ post.body|striptags|length }}</td>
<td>
<form class="inline" method="post"
action="{{ url_for('.set_comment', post_id=post.id, next=request.full_path) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<button type="submit"
class="btn {% if post.can_comment %}btn-outline-warning{% else %}btn-outline-success{% endif %} btn-sm">
{% if post.can_comment %}Disable{% else %}Enable{% endif %} Comment
</button>
</form>
{{ render_inline_form(
action=url_for('.set_comment', post_id=post.id, next=request.full_path),
button_style='outline-warning' if post.can_comment else 'outline-success',
button_text='Disable Comment' if post.can_comment else 'Enable Comment',
confirm=None,
) }}
<a class="btn btn-outline-info btn-sm"
href="{{ url_for('.edit_post', post_id=post.id) }}">
Edit
Expand Down

0 comments on commit 33a1135

Please sign in to comment.