Revamp all model relationships to use backref attributes properly

- Fix new post form not including a CSRF token
- Removed some old leftover comment profanity validation, changed to validate_on_submit() for first time
- Include rest of pluralize macro work with this commit + used pluralizing logic where there once was none
This commit is contained in:
Xevion
2022-03-29 18:12:07 -05:00
parent db560b7c41
commit fd35443a9a
8 changed files with 47 additions and 52 deletions

View File

@@ -4,6 +4,7 @@
{% block content %}
{% if current_user.is_authenticated %}
<form method="POST" class="form post-form">
{{ form.csrf_token }}
{{ render_field(form.text, show_label=False) }}
<input type=submit value="Create Post">
</form>
@@ -11,13 +12,15 @@
<hr style="margin: 2em 0">
{% for post, author in posts_and_authors %}
{% for post in posts %}
<div class="post-box">
{{ post.text }}
<div class="post-author no-border">
<em>Posted by <a href="{{ url_for('main.view_user', username=author.username) }}">{{ author.name }}</a></em> <span
title="{{ post.date_posted }}">{{ post.get_time_ago() }} ago</span>. |
<a href="{{ url_for('main.view_post', post_id=post.id) }}"><span>{{ post.comments|length }} comments</span></a>
{% with comment_count = post.comments|length %}
<em>Posted by <a href="{{ url_for('main.view_user', username=post.author.username) }}">{{ post.author.name }}</a></em>
<span title="{{ post.date_posted }}">{{ post.get_time_ago() }} ago</span>. |
<a href="{{ url_for('main.view_post', post_id=post.id) }}"><span> {{ comment_count }} comment{{ comment_count|pluralize }}</span></a>
{% endwith %}
</div>
</div>
{% endfor %}

View File

@@ -4,33 +4,25 @@
{{ post.text }}
<br>
<div class="post-author">
<em>Posted by <a href="{{ url_for('main.view_user', username=author.username) }}">{{ author.name }}</a></em> <span
<em>Posted by <a href="{{ url_for('main.view_user', username=post.author.username) }}">{{ post.author.name }}</a></em> <span
title="{{ post.date_posted }}">{{ post.get_time_ago() }} ago</span>.
</div>
<div class="post-comments">
{% if current_user.is_authenticated %}
{% with messages = get_flashed_messages() %}
{% if messages %}
<span class="error-message">
{{ messages[0] }}
</span>
{% endif %}
{% endwith %}
<div class="post-comment add-comment">
<form method="POST" action="{{ url_for('forms.add_comment', post_id=post.id) }}">
<label>
<input type="text" name="comment-text">
</label>
<button>Add Comment</button>
{{ form.csrf_token }}
{{ form.text }}
<input type=submit value="Add Comment">
</form>
</div>
{% endif %}
{% for comment, author in comments_and_authors %}
{% for comment in post.comments %}
<div class="post-comment">
<span class="comment-text">"{{ comment.text }}"</span><a class="comment-author"
href="{{ url_for('main.view_user', username=author.username) }}">{{ author.name }}</a>
<span class="comment-text">"{{ comment.text }}"</span>
<a class="comment-author"
href="{{ url_for('main.view_user', username=comment.author) }}">{{ comment.author.name }}
</a>
</div>
{% endfor %}
</div>

View File

@@ -3,7 +3,7 @@
{% block content %}
<div class="profile-title">
<span class="profile-username">{{ user.name }}</span>
{% if current_user.is_admin or current_user.id == user.id %}
{% if current_user.is_admin or current_user == user %}
<a href="{{ url_for('main.edit_user', username=current_user.username) }}"><i class="fas fa-pencil-alt fa-sm" style="padding-bottom: 3px; padding-left: 0.5em;"></i></a>
{% endif %}
{% with seen_text = user.get_last_seen() %}
@@ -22,7 +22,7 @@
<span title="{{ user.time_registered }}">Registered {{ user.get_registration_delta() }} ago</span><br>
{# 0 likes<br>#}
{% with post_count = user.get_post_count() %}
{{ post_count }} post{% if post_count > 1 %}s{% endif %}<br>
{{ post_count }} post{{ post_count|pluralize() }}<br>
{% endwith %}
</div>
</div>