Navigation Menu

Skip to content

Commit

Permalink
Add comments to site updates (#465)
Browse files Browse the repository at this point in the history
This is not very nice. Sorry.
  • Loading branch information
charmander committed Feb 15, 2019
1 parent 61dda2b commit c6455b4
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 72 deletions.
6 changes: 6 additions & 0 deletions assets/scss/site.scss
Expand Up @@ -3224,6 +3224,12 @@ img + #detail-art-text {
clear: both;
}

#site-update-comments {
margin-left: auto;
margin-right: auto;
max-width: 66em;
}

#detail-report {
padding-bottom: 3em;
}
Expand Down
@@ -0,0 +1,42 @@
"""Add comments to site updates
Revision ID: 9270baf773a5
Revises: 7f0e262d6370
Create Date: 2019-01-21 16:41:17.360120
"""

# revision identifiers, used by Alembic.
revision = '9270baf773a5'
down_revision = '7f0e262d6370'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('siteupdatecomment',
sa.Column('commentid', sa.Integer(), nullable=False),
sa.Column('userid', sa.Integer(), nullable=False),
sa.Column('targetid', sa.Integer(), nullable=False),
sa.Column('parentid', sa.Integer(), nullable=True),
sa.Column('content', sa.String(length=10000), nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text(u'now()'), nullable=False),
sa.Column('hidden_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
sa.Column('hidden_by', sa.Integer(), nullable=True),
sa.CheckConstraint(u'hidden_by IS NULL OR hidden_at IS NOT NULL', name='siteupdatecomment_hidden_check'),
sa.ForeignKeyConstraint(['hidden_by'], ['login.userid'], name='siteupdatecomment_hidden_by_fkey', ondelete='SET NULL'),
sa.ForeignKeyConstraint(['targetid', 'parentid'], ['siteupdatecomment.targetid', 'siteupdatecomment.commentid'], name='siteupdatecomment_parentid_fkey'),
sa.ForeignKeyConstraint(['targetid'], ['siteupdate.updateid'], name='siteupdatecomment_targetid_fkey'),
sa.ForeignKeyConstraint(['userid'], ['login.userid'], name='siteupdatecomment_userid_fkey'),
sa.PrimaryKeyConstraint('commentid'),
sa.UniqueConstraint('targetid', 'commentid')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('siteupdatecomment')
# ### end Alembic commands ###
24 changes: 23 additions & 1 deletion libweasyl/libweasyl/models/tables.py
@@ -1,5 +1,5 @@
from sqlalchemy import (
MetaData, Table, Column, CheckConstraint, ForeignKeyConstraint, Index,
MetaData, Table, Column, CheckConstraint, ForeignKeyConstraint, UniqueConstraint, Index,
Integer, String, Text, SMALLINT, text, DateTime, func, Boolean)
from sqlalchemy.dialects.postgresql import ARRAY, JSONB, TIMESTAMP

Expand Down Expand Up @@ -732,6 +732,28 @@ def default_fkey(*args, **kwargs):
)


siteupdatecomment = Table(
'siteupdatecomment', metadata,
Column('commentid', Integer(), primary_key=True, nullable=False),
Column('userid', Integer(), nullable=False),
Column('targetid', Integer(), nullable=False),
Column('parentid', Integer(), nullable=True),
Column('content', String(length=10000), nullable=False),
Column('created_at', TIMESTAMP(timezone=True), nullable=False, server_default=func.now()),
Column('hidden_at', TIMESTAMP(timezone=True), nullable=True),
Column('hidden_by', Integer(), nullable=True),
ForeignKeyConstraint(['targetid'], ['siteupdate.updateid'], name='siteupdatecomment_targetid_fkey'),
ForeignKeyConstraint(
['targetid', 'parentid'],
['siteupdatecomment.targetid', 'siteupdatecomment.commentid'],
name='siteupdatecomment_parentid_fkey'),
ForeignKeyConstraint(['userid'], ['login.userid'], name='siteupdatecomment_userid_fkey'),
ForeignKeyConstraint(['hidden_by'], ['login.userid'], name='siteupdatecomment_hidden_by_fkey', ondelete='SET NULL'),
CheckConstraint("hidden_by IS NULL OR hidden_at IS NOT NULL", name='siteupdatecomment_hidden_check'),
UniqueConstraint('targetid', 'commentid'),
)


submission = Table(
'submission', metadata,
Column('submitid', Integer(), primary_key=True, nullable=False),
Expand Down
2 changes: 2 additions & 0 deletions templates/common/comment_form.html
Expand Up @@ -9,6 +9,8 @@
feature = "charid"
elif feature == "journal":
feature = "journalid"
elif feature == "siteupdate":
feature = "updateid"

<form class="comment-form" action="/submit/${'shout' if feature in ['userid', 'staffnotes'] else 'comment'}" method="post">
$:{CSRF()}
Expand Down
4 changes: 4 additions & 0 deletions templates/etc/index.html
Expand Up @@ -97,6 +97,10 @@ <h5 class="date">${DATE(update['unixtime'])} <i>at</i> ${TIME(update['unixtime']
<div class="formatted-content">
$:{MARKDOWN(update['content'])}
</div>

$ comment_count = update.get('comment_count')
$if comment_count is not None:
<a href="/site-updates/${update['updateid']}" class="more more-block"><i>View</i> <span>This Update</span> <i>and</i> <span>${comment_count} Comment${'' if comment_count == 1 else 's'}</span></a>
</div>

<div id="hc-critique" class="clear">
Expand Down
11 changes: 10 additions & 1 deletion templates/etc/site_update.html
@@ -1,4 +1,4 @@
$def with (update)
$def with (myself, update, comments)
$ owner = update.get_display_owner()
<div id="home-content" class="content">
<div class="constrained">
Expand All @@ -18,4 +18,13 @@ <h5 class="date">${DATE(update.unixtime)} <i>at</i> ${TIME(update.unixtime)}</h5
$:{MARKDOWN(update.content)}
</div>
</div>

<div id="site-update-comments">
$if comments:
<div class="constrained"><h3>Comments</h3></div>
$:{RENDER("common/comment_thread.html", ["detail_comments", comments, "siteupdate", myself, update.updateid, update.userid])}
$if myself:
<div class="constrained"><h3>Leave a Comment</h3></div>
$:{RENDER("common/comment_form.html", [myself, update.updateid, "siteupdate"])}
</div>
</div>
20 changes: 16 additions & 4 deletions templates/message/notifications.html
Expand Up @@ -13,7 +13,8 @@
elif x in [4010, 4015]: return [4010, 4015]
elif x == 4016: return [4016]
elif x in [4020, 4025, 4050]: return [4020, 4025, 4050]
elif x in [4030, 4035]: return [4030, 4035]
elif x in [4030, 4035, 4060, 4065]:
return [4030, 4035, 4060, 4065]
elif x in [4040, 4045]: return [4040, 4045]
else: return []

Expand All @@ -30,7 +31,8 @@
elif x in [4010, 4015]: return "Shouts"
elif x == 4016: return "Staff Notes"
elif x in [4020, 4025, 4050]: return "Submission Comments"
elif x in [4030, 4035]: return "Journal Comments"
elif x in [4030, 4035, 4060, 4065]:
return "Journal Comments"
elif x in [4040, 4045]: return "Character Comments"
else: return "Miscellaneous"

Expand Down Expand Up @@ -83,7 +85,7 @@ <h3 class="notification-group-header">
if 'username' in i:
item_user = '<a href="/~' + LOGIN(i['username']) + '" class="username">' + escape_(i['username']) + '</a>'

if 'submitid' in i or 'journalid' in i or 'charid' in i:
if 'submitid' in i or 'journalid' in i or 'charid' in i or 'updateid' in i:
if 'submitid' in i:
folder = 'submission'
id = i['submitid']
Expand All @@ -93,8 +95,12 @@ <h3 class="notification-group-header">
elif 'charid' in i:
folder = 'character'
id = i['charid']
elif 'updateid' in i:
folder = 'site-updates'
id = i['updateid']
if 'title' in i:
item_base_url = '/%s/%i/%s' % (folder, id, SLUG(i['title']))
slug = '' if 'updateid' in i else '/%s' % (SLUG(i['title']),)
item_base_url = '/%s/%i%s' % (folder, id, slug)
item_link = '<a href="' + item_base_url + '">' + escape_(i['title']) + '</a>'
if 'commentid' in i:
comment_url = lambda id: item_base_url + '#cid' + STR(id)
Expand Down Expand Up @@ -185,6 +191,12 @@ <h3 class="notification-group-header">
$elif i['type'] == 4050:
$# comment on collected item
$:{item_user} left a $:{item_comment} on your collected submission $:{item_link}.
$elif i['type'] == 4060:
$# site update comment
$:{item_user} left a $:{item_comment} on your site update $:{item_link}.
$elif i['type'] == 4065:
$# site update comment reply
$:{item_user} left a $:{item_reply} to $:{item_your_comment} on the site update $:{item_link}.
$else:
${i}
<span class="date color-lighter">${DATE(i['unixtime'])} <em>at</em> ${TIME(i['unixtime'])}</span>
Expand Down

0 comments on commit c6455b4

Please sign in to comment.