Skip to content

Commit

Permalink
Refactoring @778a0a code to match new template structure and now we h…
Browse files Browse the repository at this point in the history
…ave first version of #11 post editing.
  • Loading branch information
nigini committed Sep 6, 2024
1 parent 05cbf78 commit 20617d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,7 @@ async def admin_edit_text(
maybe_object = (
(
await db_session.execute(
select(models.OutboxObject)
.where(
select(models.OutboxObject).where(
models.OutboxObject.public_id == public_id,
models.OutboxObject.is_deleted.is_(False),
)
Expand Down Expand Up @@ -1271,8 +1270,7 @@ async def admin_actions_edit_text(
maybe_object = (
(
await db_session.execute(
select(models.OutboxObject)
.where(
select(models.OutboxObject).where(
models.OutboxObject.public_id == public_id,
models.OutboxObject.is_deleted.is_(False),
)
Expand All @@ -1297,7 +1295,6 @@ async def admin_actions_edit_text(
)



@router.post("/actions/vote", response_model=None)
async def admin_actions_vote(
request: Request,
Expand Down
5 changes: 3 additions & 2 deletions app/templates/admin_edit_text.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- import "utils.html" as utils with context -%}
{%- import "components/hidden_inputs.html" as hidden_inputs -%}
{% extends "layout.html" %}

{% block head %}
Expand All @@ -10,8 +11,8 @@
<div class="box">

<form class="form admin-new" action="{{ request.url_for("admin_actions_edit_text", public_id=public_id) }}" enctype="multipart/form-data" method="POST">
{{ utils.embed_csrf_token() }}
{{ utils.embed_redirect_url() }}
{{ hidden_inputs.embed_csrf_token(csrf_token) }}
{{ hidden_inputs.embed_redirect_url(request) }}

{% if outbox_object.ap_type == "Article" %}
<p>
Expand Down
7 changes: 7 additions & 0 deletions app/templates/components/admin_buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
</form>
{% endmacro %}

{% macro admin_edit_button(request, csrf_token, ap_object) %}
<form action="{{ request.url_for("admin_edit_text", public_id=ap_object.public_id) }}" class="object-edit-form" method="GET">
{{ hidden_inputs.embed_csrf_token(csrf_token) }}
<input type="submit" value="edit">
</form>
{% endmacro %}

{% macro admin_delete_button(request, csrf_token, ap_object) %}
<form action="{{ request.url_for("admin_actions_delete") }}" class="object-delete-form" method="POST">
{{ hidden_inputs.embed_csrf_token(csrf_token) }}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ <h3>Location</h3>
<ul>
{% if object.is_from_outbox %}
<li>
{{ admin_edit_button(object) }}
{{ admin_buttons.admin_edit_button(request, csrf_token, object) }}
</li>
<li>
{{ admin_buttons.admin_delete_button(request, csrf_token, object) }}
Expand Down

0 comments on commit 20617d9

Please sign in to comment.