Add is_status_update to thread replies

This commit is contained in:
rubenwardy 2022-04-23 20:53:38 +01:00
parent ee2311025c
commit f3ff44203c
6 changed files with 71 additions and 8 deletions

@ -145,6 +145,7 @@ def delete_review(package, reviewer):
reply.thread = thread
reply.author = current_user
reply.comment = "_converted review into a thread_"
reply.is_status_update = True
db.session.add(reply)
thread.review = None

@ -136,6 +136,8 @@ class ThreadReply(db.Model):
author_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
author = db.relationship("User", back_populates="replies", foreign_keys=[author_id])
is_status_update = db.Column(db.Boolean, server_default="0", nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
def get_url(self):

@ -32,4 +32,8 @@
height: 60px;
object-fit: cover;
}
.status-update p {
margin: 0;
}
}

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}title{% endblock %} - {{ config.USER_APP_NAME }}</title>
<link rel="stylesheet" type="text/css" href="/static/libs/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=34">
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=35">
<link rel="search" type="application/opensearchdescription+xml" href="/static/opensearch.xml" title="ContentDB" />
<link rel="shortcut icon" href="/favicon-16.png" sizes="16x16">
<link rel="icon" href="/favicon-128.png" sizes="128x128">

@ -1,9 +1,6 @@
{% macro render_thread(thread, current_user, form=None) -%}
{% macro render_reply(r, thread, current_user) -%}
{% from "macros/reviews.html" import render_review_vote %}
{% from "macros/reviews.html" import render_review_vote %}
<ul class="comments mt-4 mb-0">
{% for r in thread.replies %}
<li class="row my-2 mx-0">
<div class="col-md-1 p-1">
<a href="{{ url_for('users.profile', username=r.author.username) }}">
@ -77,6 +74,43 @@
</div>
</div>
</li>
{% endmacro %}
{% macro render_status_update(r, thread, current_user) -%}
<li class="row my-2 mx-0 align-items-center">
<div class="col-md-1 p-1">
<a href="{{ url_for('users.profile', username=r.author.username) }}">
<img class="img-fluid user-photo img-thumbnail img-thumbnail-1" src="{{ r.author.getProfilePicURL() }}">
</a>
</div>
<div class="col-auto">
<a class="author {{ r.author.rank.name }}"
href="{{ url_for('users.profile', username=r.author.username) }}">
{{ r.author.display_name }}
</a>
</div>
<div class="col pr-0 status-update">
{{ r.comment | markdown }}
</div>
<div class="col-auto">
<a name="reply-{{ r.id }}" class="text-muted float-right"
href="{{ r.get_url() }}">
{{ r.created_at | datetime }}
</a>
</div>
</li>
{% endmacro %}
{% macro render_thread(thread, current_user, form=None) -%}
<ul class="comments mt-4 mb-0">
{% for r in thread.replies %}
{% if r.is_status_update %}
{{ render_status_update(r, thread, current_user) }}
{% else %}
{{ render_reply(r, thread, current_user) }}
{% endif %}
{% endfor %}
</ul>
@ -115,8 +149,7 @@
<input class="btn btn-primary" type="submit" disabled value="Comment" />
</div>
{% elif form %}
{% from "macros/forms.html" import render_field, render_submit_field %}
{% from "macros/forms.html" import render_field, render_submit_field %}
<form method="post" action="{{ url_for('threads.view', id=thread.id)}}" class="card-body">
{{ form.hidden_tag() }}
{{ render_field(form.comment, fieldclass="form-control markdown", label="") }}

@ -0,0 +1,23 @@
"""empty message
Revision ID: 8807a5279793
Revises: 01f8d5de29e1
Create Date: 2022-04-23 19:45:00.301875
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '8807a5279793'
down_revision = '01f8d5de29e1'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('thread_reply', sa.Column('is_status_update', sa.Boolean(), server_default='0', nullable=False))
def downgrade():
op.drop_column('thread_reply', 'is_status_update')