Browse Source

Convert Lock and Remove buttons to use new macro

This uses the "post action toggle button" macro for Lock and Remove as
well, which is now most of them.
merge-requests/69/head
Deimos 6 years ago
parent
commit
c4056f705a
  1. 2
      tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2
  2. 12
      tildes/tildes/templates/macros/buttons.jinja2
  3. 22
      tildes/tildes/templates/macros/comments.jinja2
  4. 44
      tildes/tildes/templates/topic.jinja2
  5. 20
      tildes/tildes/views/api/web/comment.py
  6. 44
      tildes/tildes/views/api/web/topic.py

2
tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2

@ -3,4 +3,4 @@
{% from 'macros/buttons.jinja2' import post_action_toggle_button with context %} {% from 'macros/buttons.jinja2' import post_action_toggle_button with context %}
{{ post_action_toggle_button("bookmark", subject, is_toggled) }}
{{ post_action_toggle_button(name, subject, is_toggled) }}

12
tildes/tildes/templates/macros/buttons.jinja2

@ -12,6 +12,16 @@
{% if name == "bookmark" %} {% if name == "bookmark" %}
{% set normal_label = "Bookmark" %} {% set normal_label = "Bookmark" %}
{% set toggled_label = "Unbookmark" %} {% set toggled_label = "Unbookmark" %}
{% elif name == "lock" %}
{% set normal_label = "Lock" %}
{% set toggled_label = "Unlock" %}
{% set normal_confirm = "Lock this topic?" %}
{% set toggled_confirm = "Unlock this topic?" %}
{% elif name == "remove" %}
{% set normal_label = "Remove" %}
{% set toggled_label = "Un-remove" %}
{% set normal_confirm = "Remove this " + type_name + "?" %}
{% set toggled_confirm = "Un-remove this " + type_name + "?" %}
{% endif %} {% endif %}
<li> <li>
@ -19,11 +29,13 @@
<button class="btn-post-action" <button class="btn-post-action"
data-ic-put-to="{{ _post_action_toggle_button_url(route_name, subject) }}" data-ic-put-to="{{ _post_action_toggle_button_url(route_name, subject) }}"
data-ic-replace-target="true" data-ic-replace-target="true"
{% if normal_confirm %}data-ic-confirm="{{ normal_confirm }}"{% endif %}
>{{ normal_label }}</button> >{{ normal_label }}</button>
{% else %} {% else %}
<button class="btn-post-action btn-post-action-used" <button class="btn-post-action btn-post-action-used"
data-ic-delete-from="{{ _post_action_toggle_button_url(route_name, subject) }}" data-ic-delete-from="{{ _post_action_toggle_button_url(route_name, subject) }}"
data-ic-replace-target="true" data-ic-replace-target="true"
{% if toggled_confirm %}data-ic-confirm="{{ toggled_confirm }}"{% endif %}
>{{ toggled_label }}</button> >{{ toggled_label }}</button>
{% endif %} {% endif %}
</li> </li>

22
tildes/tildes/templates/macros/comments.jinja2

@ -212,27 +212,7 @@
{% endif %} {% endif %}
{% if request.has_permission("remove", comment) %} {% if request.has_permission("remove", comment) %}
<li>
{% if not comment.is_removed %}
<button class="btn-post-action"
data-ic-put-to="{{ request.route_url(
'ic_comment_remove',
comment_id36=comment.comment_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Remove this comment?"
>Remove</button>
{% else %}
<button class="btn-post-action"
data-ic-delete-from="{{ request.route_url(
'ic_comment_remove',
comment_id36=comment.comment_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Un-remove this comment?"
>Un-remove</button>
{% endif %}
</li>
{{ post_action_toggle_button("remove", comment, comment.is_removed) }}
{% endif %} {% endif %}
{% if request.has_permission('reply', comment) %} {% if request.has_permission('reply', comment) %}

44
tildes/tildes/templates/topic.jinja2

@ -141,27 +141,7 @@
{% endif %} {% endif %}
{% if request.has_permission('lock', topic) %} {% if request.has_permission('lock', topic) %}
<li>
{% if not topic.is_locked %}
<button class="btn-post-action"
data-ic-put-to="{{ request.route_url(
'ic_topic_lock',
topic_id36=topic.topic_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Lock this topic?"
>Lock</button>
{% else %}
<button class="btn-post-action"
data-ic-delete-from="{{ request.route_url(
'ic_topic_lock',
topic_id36=topic.topic_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Unlock this topic?"
>Unlock</button>
{% endif %}
</li>
{{ post_action_toggle_button("lock", topic, topic.is_locked) }}
{% endif %} {% endif %}
{% if request.has_permission('bookmark', topic) %} {% if request.has_permission('bookmark', topic) %}
@ -169,27 +149,7 @@
{% endif %} {% endif %}
{% if request.has_permission("remove", topic) %} {% if request.has_permission("remove", topic) %}
<li>
{% if not topic.is_removed %}
<button class="btn-post-action"
data-ic-put-to="{{ request.route_url(
'ic_topic_remove',
topic_id36=topic.topic_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Remove this topic?"
>Remove</button>
{% else %}
<button class="btn-post-action"
data-ic-delete-from="{{ request.route_url(
'ic_topic_remove',
topic_id36=topic.topic_id36,
) }}"
data-ic-replace-target="true"
data-ic-confirm="Un-remove this topic?"
>Un-remove</button>
{% endif %}
</li>
{{ post_action_toggle_button("remove", topic, topic.is_removed) }}
{% endif %} {% endif %}
</menu> </menu>
<div class="btn-post-settings"></div> <div class="btn-post-settings"></div>

20
tildes/tildes/views/api/web/comment.py

@ -398,28 +398,36 @@ def put_mark_comments_read(request: Request, mark_all_previous: bool) -> Respons
return IC_NOOP return IC_NOOP
@ic_view_config(route_name="comment_remove", request_method="PUT", permission="remove")
def put_comment_remove(request: Request) -> Response:
@ic_view_config(
route_name="comment_remove",
request_method="PUT",
permission="remove",
renderer="post_action_toggle_button.jinja2",
)
def put_comment_remove(request: Request) -> dict:
"""Remove a comment with Intercooler.""" """Remove a comment with Intercooler."""
comment = request.context comment = request.context
comment.is_removed = True comment.is_removed = True
request.db_session.add(LogComment(LogEventType.COMMENT_REMOVE, request, comment)) request.db_session.add(LogComment(LogEventType.COMMENT_REMOVE, request, comment))
return Response("Removed")
return {"name": "remove", "subject": comment, "is_toggled": True}
@ic_view_config( @ic_view_config(
route_name="comment_remove", request_method="DELETE", permission="remove"
route_name="comment_remove",
request_method="DELETE",
permission="remove",
renderer="post_action_toggle_button.jinja2",
) )
def delete_comment_remove(request: Request) -> Response:
def delete_comment_remove(request: Request) -> dict:
"""Un-remove a comment with Intercooler.""" """Un-remove a comment with Intercooler."""
comment = request.context comment = request.context
comment.is_removed = False comment.is_removed = False
request.db_session.add(LogComment(LogEventType.COMMENT_UNREMOVE, request, comment)) request.db_session.add(LogComment(LogEventType.COMMENT_UNREMOVE, request, comment))
return Response("Un-removed")
return {"name": "remove", "subject": comment, "is_toggled": False}
@ic_view_config( @ic_view_config(

44
tildes/tildes/views/api/web/topic.py

@ -236,48 +236,68 @@ def patch_move_topic(request: Request, path: str) -> dict:
return Response("Moved") return Response("Moved")
@ic_view_config(route_name="topic_remove", request_method="PUT", permission="remove")
def put_topic_remove(request: Request) -> Response:
@ic_view_config(
route_name="topic_remove",
request_method="PUT",
permission="remove",
renderer="post_action_toggle_button.jinja2",
)
def put_topic_remove(request: Request) -> dict:
"""Remove a topic with Intercooler.""" """Remove a topic with Intercooler."""
topic = request.context topic = request.context
topic.is_removed = True topic.is_removed = True
request.db_session.add(LogTopic(LogEventType.TOPIC_REMOVE, request, topic)) request.db_session.add(LogTopic(LogEventType.TOPIC_REMOVE, request, topic))
return Response("Removed")
return {"name": "remove", "subject": topic, "is_toggled": True}
@ic_view_config(route_name="topic_remove", request_method="DELETE", permission="remove")
def delete_topic_remove(request: Request) -> Response:
@ic_view_config(
route_name="topic_remove",
request_method="DELETE",
permission="remove",
renderer="post_action_toggle_button.jinja2",
)
def delete_topic_remove(request: Request) -> dict:
"""Un-remove a topic with Intercooler.""" """Un-remove a topic with Intercooler."""
topic = request.context topic = request.context
topic.is_removed = False topic.is_removed = False
request.db_session.add(LogTopic(LogEventType.TOPIC_UNREMOVE, request, topic)) request.db_session.add(LogTopic(LogEventType.TOPIC_UNREMOVE, request, topic))
return Response("Un-removed")
return {"name": "remove", "subject": topic, "is_toggled": False}
@ic_view_config(route_name="topic_lock", request_method="PUT", permission="lock")
def put_topic_lock(request: Request) -> Response:
@ic_view_config(
route_name="topic_lock",
request_method="PUT",
permission="lock",
renderer="post_action_toggle_button.jinja2",
)
def put_topic_lock(request: Request) -> dict:
"""Lock a topic with Intercooler.""" """Lock a topic with Intercooler."""
topic = request.context topic = request.context
topic.is_locked = True topic.is_locked = True
request.db_session.add(LogTopic(LogEventType.TOPIC_LOCK, request, topic)) request.db_session.add(LogTopic(LogEventType.TOPIC_LOCK, request, topic))
return Response("Locked")
return {"name": "lock", "subject": topic, "is_toggled": True}
@ic_view_config(route_name="topic_lock", request_method="DELETE", permission="lock")
def delete_topic_lock(request: Request) -> Response:
@ic_view_config(
route_name="topic_lock",
request_method="DELETE",
permission="lock",
renderer="post_action_toggle_button.jinja2",
)
def delete_topic_lock(request: Request) -> dict:
"""Unlock a topic with Intercooler.""" """Unlock a topic with Intercooler."""
topic = request.context topic = request.context
topic.is_locked = False topic.is_locked = False
request.db_session.add(LogTopic(LogEventType.TOPIC_UNLOCK, request, topic)) request.db_session.add(LogTopic(LogEventType.TOPIC_UNLOCK, request, topic))
return Response("Unlocked")
return {"name": "lock", "subject": topic, "is_toggled": False}
@ic_view_config( @ic_view_config(

Loading…
Cancel
Save