Skip to content

Commit

Permalink
revert fix add/edit item's show query
Browse files Browse the repository at this point in the history
  • Loading branch information
tuz666 committed Dec 7, 2024
1 parent 2d8da9e commit 822f8c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions arcsi/api/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ItemDetailsSchema(Schema):
shows = fields.List(
fields.Nested(
"ShowDetailsSchema",
only=("id", "name", "archive_lahmastore_base_url", "users"),
only=("id", "name", "archive_lahmastore_base_url"),
),
required=True,
)
Expand Down Expand Up @@ -130,14 +130,15 @@ def archon_add_item():
# work around ImmutableDict type
item_metadata = request.form.to_dict()
# TODO if we could send JSON payloads w/ ajax then this prevalidation isn't needed
item_metadata.pop("show_name", None)
item_metadata["shows"] = (
db.session.query(Show)
.filter(Show.id.in_(item_metadata["shows"]))
.all()
)
item_metadata["shows"] = [
{
"id": item_metadata["shows"],
"name": item_metadata["show_name"]
}
]
item_metadata["tags"] = [ { "display_name": tag_name.strip() } for tag_name in item_metadata["taglist"].split(",") ]
item_metadata["tags"] = [dict(t) for t in {tuple(d.items()) for d in item_metadata["tags"]}]
item_metadata.pop("show_name", None)
item_metadata.pop("taglist", None)

# validate payload
Expand All @@ -157,6 +158,12 @@ def archon_add_item():
play_file = None
play_file_name = None
archive_lahmastore_canonical_url = ""
external_url = ""
shows = (
db.session.query(Show)
.filter(Show.id.in_((show.id for show in item_metadata.shows)))
.all()
)
tags = (
get_or_create( Tag, display_name=tag.display_name, clean_name=normalise(tag.display_name) ) for tag in item_metadata.tags
)
Expand All @@ -177,7 +184,7 @@ def archon_add_item():
archived=archived,
download_count=download_count,
uploader=item_metadata.uploader,
shows=item_metadata.shows,
shows=shows,
tags=tags
)

Expand Down Expand Up @@ -358,15 +365,13 @@ def archon_edit_item(id):
item_metadata = request.form.to_dict()

# TODO if we could send JSON payloads w/ ajax then this prevalidation isn't needed
item_metadata.pop("show_name", None)
item_metadata["shows"] = (
db.session.query(Show)
.filter(Show.id.in_(item_metadata["shows"]))
.all()
)
item_metadata["shows"] = [
{"id": item_metadata["shows"], "name": item_metadata["show_name"]}
]
item_metadata["tags"] = [ { "display_name": tag_name.strip() } for tag_name in item_metadata["taglist"].split(",") ]
item_metadata["tags"] = [dict(t) for t in {tuple(d.items()) for d in item_metadata["tags"]}]
item_metadata.pop("taglist", None)
item_metadata.pop("show_name", None)

# validate payload
# TODO handle what happens on f.e: empty payload?
Expand Down Expand Up @@ -399,7 +404,11 @@ def archon_edit_item(id):
item.external_url = item_metadata.external_url

# conflict between shows from detached object load(item_metadata) added to session vs original persistent object item from query
item.shows = item_metadata.shows
item.shows = (
db.session.query(Show)
.filter(Show.id.in_((show.id for show in item_metadata.shows)))
.all()
)
item.tags = (
get_or_create(Tag, display_name=tag.display_name, clean_name=normalise(tag.display_name)) for tag in item_metadata.tags
)
Expand Down
2 changes: 1 addition & 1 deletion arcsi/templates/item/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2>{% block title %}{{item.name}}{% endblock %}</h2>
{% endfor %}
</ul>
<hr>
{% if current_user.has_role("admin") or (current_user.has_role("host") and current_user in item.shows[0].users) %}
{% if current_user.has_role("admin") or current_user.has_role("host") %}
<p><a href="{{ url_for('router.edit_item', id=item['id']) }}">Edit Episode</a> || <a
href="{{ url_for('arcsi.archon_delete_item', id=item['id']) }}">Delete Episode</a></p>
{% endif %}
Expand Down

0 comments on commit 822f8c1

Please sign in to comment.