mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Limit Exemplary comment label to one/day/user
Limit Exemplary comment label to one/day/user
This is a bit of a hacky way of doing it in a few aspects and definitely still needs some work, but it's a reasonable start. Specifically, a major miss is that there's no way to remove an Exemplary label unless you currently have one available. This should definitely be fixed, but I'm not sure what might be the best approach yet.merge-requests/40/head
Deimos
6 years ago
9 changed files with 123 additions and 6 deletions
-
56tildes/alembic/versions/8e54f422541c_user_track_last_usage_of_exemplary_label.py
-
3tildes/scss/modules/_btn.scss
-
7tildes/scss/modules/_comment.scss
-
19tildes/sql/init/triggers/comment_labels/users.sql
-
12tildes/static/js/behaviors/comment-label-button.js
-
8tildes/tildes/models/comment/comment_label.py
-
15tildes/tildes/models/user/user.py
-
5tildes/tildes/templates/macros/comments.jinja2
-
4tildes/tildes/views/api/web/comment.py
@ -0,0 +1,56 @@ |
|||
"""User: track last usage of exemplary label |
|||
|
|||
Revision ID: 8e54f422541c |
|||
Revises: 5cd2db18b722 |
|||
Create Date: 2018-09-26 00:22:02.728425 |
|||
|
|||
""" |
|||
from alembic import op |
|||
import sqlalchemy as sa |
|||
from sqlalchemy.dialects import postgresql |
|||
|
|||
# revision identifiers, used by Alembic. |
|||
revision = "8e54f422541c" |
|||
down_revision = "5cd2db18b722" |
|||
branch_labels = None |
|||
depends_on = None |
|||
|
|||
|
|||
def upgrade(): |
|||
op.add_column( |
|||
"users", |
|||
sa.Column( |
|||
"last_exemplary_label_time", sa.TIMESTAMP(timezone=True), nullable=True |
|||
), |
|||
) |
|||
|
|||
op.execute( |
|||
""" |
|||
CREATE OR REPLACE FUNCTION update_user_last_exemplary_label_time() RETURNS TRIGGER AS $$ |
|||
BEGIN |
|||
UPDATE users |
|||
SET last_exemplary_label_time = NOW() |
|||
WHERE user_id = NEW.user_id; |
|||
|
|||
RETURN NULL; |
|||
END |
|||
$$ LANGUAGE plpgsql; |
|||
""" |
|||
) |
|||
|
|||
op.execute( |
|||
""" |
|||
CREATE TRIGGER update_user_last_exemplary_label_time |
|||
AFTER INSERT ON comment_labels |
|||
FOR EACH ROW |
|||
WHEN (NEW.label = 'EXEMPLARY') |
|||
EXECUTE PROCEDURE update_user_last_exemplary_label_time(); |
|||
""" |
|||
) |
|||
|
|||
|
|||
def downgrade(): |
|||
op.execute("DROP TRIGGER update_user_last_exemplary_label_time ON comment_labels") |
|||
op.execute("DROP FUNCTION update_user_last_exemplary_label_time()") |
|||
|
|||
op.drop_column("users", "last_exemplary_label_time") |
@ -0,0 +1,19 @@ |
|||
-- Copyright (c) 2018 Tildes contributors <code@tildes.net> |
|||
-- SPDX-License-Identifier: AGPL-3.0-or-later |
|||
|
|||
CREATE OR REPLACE FUNCTION update_user_last_exemplary_label_time() RETURNS TRIGGER AS $$ |
|||
BEGIN |
|||
UPDATE users |
|||
SET last_exemplary_label_time = NOW() |
|||
WHERE user_id = NEW.user_id; |
|||
|
|||
RETURN NULL; |
|||
END |
|||
$$ LANGUAGE plpgsql; |
|||
|
|||
|
|||
CREATE TRIGGER update_user_last_exemplary_label_time |
|||
AFTER INSERT ON comment_labels |
|||
FOR EACH ROW |
|||
WHEN (NEW.label = 'EXEMPLARY') |
|||
EXECUTE PROCEDURE update_user_last_exemplary_label_time(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue