diff --git a/server/app.py b/server/app.py index a879550..3a48159 100644 --- a/server/app.py +++ b/server/app.py @@ -1169,6 +1169,46 @@ def api_media_element(media_id: int) -> ResponseReturnValue: }, 405 +@flask_app.route("/api/media/add_blocking", methods=["POST"]) +def api_media_add_blocking() -> ResponseReturnValue: + data = request.form.to_dict() + blocked_by_id = data.get("blocked_by") + is_blocking_id = data.get("is_blocking") + blocked_by: Optional[MediaElement] = ( + MediaElement.get(id=blocked_by_id) if blocked_by_id else None + ) + is_blocking: Optional[MediaElement] = ( + MediaElement.get(id=is_blocking_id) if is_blocking_id else None + ) + if not blocked_by or not is_blocking: + return { + "status": False, + "error": f"Object not found", + }, 404 + blocked_by.is_blocking.add(is_blocking) + return redirect_back_or_okay() + + +@flask_app.route("/api/media/remove_blocking", methods=["POST"]) +def api_media_remove_blocking() -> ResponseReturnValue: + data = request.form.to_dict() + blocked_by_id = data.get("blocked_by") + is_blocking_id = data.get("is_blocking") + blocked_by: Optional[MediaElement] = ( + MediaElement.get(id=blocked_by_id) if blocked_by_id else None + ) + is_blocking: Optional[MediaElement] = ( + MediaElement.get(id=is_blocking_id) if is_blocking_id else None + ) + if not blocked_by or not is_blocking: + return { + "status": False, + "error": f"Object not found", + }, 404 + blocked_by.is_blocking.remove(is_blocking) + return redirect_back_or_okay() + + def _api_media_set_x(call: Callable[[MediaElement], Any]) -> ResponseReturnValue: data = request.form.to_dict() ids = _parse_cs_ids(data.get("ids", "NULL")) diff --git a/server/templates/media_element.htm b/server/templates/media_element.htm index 80947b9..0aeec0f 100644 --- a/server/templates/media_element.htm +++ b/server/templates/media_element.htm @@ -81,6 +81,52 @@
  • {{ link.uri | as_link }} {% if element.uri == link.uri %}*{% endif %}
  • {% endfor %} +

    Blocked By

    +
    + {{ macros.hidden_redirect_back() }} + + + +
    + {% if element.blocked_by %} +
    + {% for sub_elem in element.blocked_by %} + {% call macros.media_thumbnail_view( + element=sub_elem, + check_considered=True, + ) %} + {% call macros.post_form("/api/media/remove_blocking", "blocked_by", sub_elem.id|string, "X") %} + + {% endcall %} + {% endcall %} + {% endfor %} +
    + {% endif %} +

    Is Blocking

    +
    + {{ macros.hidden_redirect_back() }} + + + +
    + {% if element.is_blocking %} +
    + {% for sub_elem in element.is_blocking %} + {% call macros.media_thumbnail_view( + element=sub_elem, + check_considered=True, + ) %} + {% call macros.post_form("/api/media/remove_blocking", "is_blocking", sub_elem.id|string, "X") %} + + {% endcall %} + {% endcall %} + {% endfor %} +
    + {% endif %}