-
Notifications
You must be signed in to change notification settings - Fork 27
feat: add unique URLs for Artwork, Marker, Object, and Exhibit #957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vjpixel
wants to merge
2
commits into
develop
Choose a base branch
from
claude/scan-repo-bugs-35wDb
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| {% extends '/core/base.jinja2' %} | ||
| {% block content %} | ||
| <div class="Container"> | ||
| <h1>{{ artwork.title }}</h1> | ||
| <p>{{ _("Author") }}: {{ artwork.author }}</p> | ||
| {% if artwork.marker %} | ||
| <p>{{ _("Marker") }}: <a href="{{ artwork.marker.get_absolute_url() }}">{{ artwork.marker.title }}</a></p> | ||
| {% endif %} | ||
| {% if artwork.augmented %} | ||
| <p>{{ _("Object") }}: <a href="{{ artwork.augmented.get_absolute_url() }}">{{ artwork.augmented.title }}</a></p> | ||
| {% endif %} | ||
| <p>{{ _("Uploaded") }}: {{ artwork.uploaded_at }}</p> | ||
| </div> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {% extends '/core/base.jinja2' %} | ||
| {% block content %} | ||
| <div class="Container"> | ||
| <h1>{{ marker.title }}</h1> | ||
| <p>{{ _("Author") }}: {{ marker.author }}</p> | ||
| {% if marker.source %} | ||
| <img src="/media/public/{{ marker.source.name }}" alt="{{ marker.title }}" style="max-width: 100%;"> | ||
| {% endif %} | ||
| <p>{{ _("Uploaded") }}: {{ marker.uploaded_at }}</p> | ||
| </div> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| {% extends '/core/base.jinja2' %} | ||
| {% block content %} | ||
| <div class="Container"> | ||
| <h1>{{ object.title }}</h1> | ||
| <p>{{ _("Author") }}: {{ object.author }}</p> | ||
| {% if object.source %} | ||
| <video src="/media/public/{{ object.source.name }}" controls style="max-width: 100%;"></video> | ||
| {% endif %} | ||
| {% if object.thumbnail %} | ||
| <img src="{{ object.thumbnail.url }}" alt="{{ object.title }}" style="max-width: 100%;"> | ||
| {% endif %} | ||
| <p>{{ _("Uploaded") }}: {{ object.uploaded_at }}</p> | ||
| </div> | ||
| {% endblock %} |
29 changes: 29 additions & 0 deletions
29
src/core/migrations/0045_add_slug_to_marker_object_artwork.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Renumbered from 0028 when develop was merged in: two 0028_* migrations | ||
| # would leave the graph with conflicting leaf nodes. | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("core", "0044_populate_sound_in_use_fields"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='marker', | ||
| name='slug', | ||
| field=models.SlugField(blank=True, max_length=80, unique=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='object', | ||
| name='slug', | ||
| field=models.SlugField(blank=True, max_length=80, unique=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='artwork', | ||
| name='slug', | ||
| field=models.SlugField(blank=True, max_length=80, unique=True), | ||
| ), | ||
| ] |
141 changes: 141 additions & 0 deletions
141
src/core/migrations/0046_remove_artwork_insert_insert_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Generated by Django 6.1.1 on 2026-09-17 18:12 | ||
|
|
||
| import pgtrigger.compiler | ||
| import pgtrigger.migrations | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("core", "0045_add_slug_to_marker_object_artwork"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="artwork", | ||
| name="insert_insert", | ||
| ), | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="artwork", | ||
| name="update_update", | ||
| ), | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="marker", | ||
| name="insert_insert", | ||
| ), | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="marker", | ||
| name="update_update", | ||
| ), | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="object", | ||
| name="insert_insert", | ||
| ), | ||
| pgtrigger.migrations.RemoveTrigger( | ||
| model_name="object", | ||
| name="update_update", | ||
| ), | ||
| migrations.AddField( | ||
| model_name="artworkevent", | ||
| name="slug", | ||
| field=models.SlugField(blank=True, db_index=False, max_length=80), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="markerevent", | ||
| name="slug", | ||
| field=models.SlugField(blank=True, db_index=False, max_length=80), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="objectevent", | ||
| name="slug", | ||
| field=models.SlugField(blank=True, db_index=False, max_length=80), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="artwork", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="insert_insert", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| func='INSERT INTO "core_artworkevent" ("augmented_id", "author_id", "created", "description", "id", "marker_id", "modified", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "position_x", "position_y", "scale_x", "scale_y", "slug", "sound_id", "title") VALUES (NEW."augmented_id", NEW."author_id", NEW."created", NEW."description", NEW."id", NEW."marker_id", NEW."modified", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."position_x", NEW."position_y", NEW."scale_x", NEW."scale_y", NEW."slug", NEW."sound_id", NEW."title"); RETURN NULL;', | ||
| hash="5e63367fae81726ac16a46d352593ae1168af728", | ||
| operation="INSERT", | ||
| pgid="pgtrigger_insert_insert_65595", | ||
| table="core_artwork", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="artwork", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="update_update", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)", | ||
| func='INSERT INTO "core_artworkevent" ("augmented_id", "author_id", "created", "description", "id", "marker_id", "modified", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "position_x", "position_y", "scale_x", "scale_y", "slug", "sound_id", "title") VALUES (NEW."augmented_id", NEW."author_id", NEW."created", NEW."description", NEW."id", NEW."marker_id", NEW."modified", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."position_x", NEW."position_y", NEW."scale_x", NEW."scale_y", NEW."slug", NEW."sound_id", NEW."title"); RETURN NULL;', | ||
| hash="e9552c93dd966d86637b42bc885edeb99574e593", | ||
| operation="UPDATE", | ||
| pgid="pgtrigger_update_update_1ac7c", | ||
| table="core_artwork", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="marker", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="insert_insert", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| func='INSERT INTO "core_markerevent" ("author", "created", "file_size", "id", "in_use", "is_used_by_other_user", "marker_img", "modified", "owner_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "print_img", "slug", "source", "thumb_img", "title") VALUES (NEW."author", NEW."created", NEW."file_size", NEW."id", NEW."in_use", NEW."is_used_by_other_user", NEW."marker_img", NEW."modified", NEW."owner_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."print_img", NEW."slug", NEW."source", NEW."thumb_img", NEW."title"); RETURN NULL;', | ||
| hash="2c58d9fb44016e14cab644eaf1f1f09296c5a5d3", | ||
| operation="INSERT", | ||
| pgid="pgtrigger_insert_insert_719b2", | ||
| table="core_marker", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="marker", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="update_update", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)", | ||
| func='INSERT INTO "core_markerevent" ("author", "created", "file_size", "id", "in_use", "is_used_by_other_user", "marker_img", "modified", "owner_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "print_img", "slug", "source", "thumb_img", "title") VALUES (NEW."author", NEW."created", NEW."file_size", NEW."id", NEW."in_use", NEW."is_used_by_other_user", NEW."marker_img", NEW."modified", NEW."owner_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."print_img", NEW."slug", NEW."source", NEW."thumb_img", NEW."title"); RETURN NULL;', | ||
| hash="a20e0970e5fa5c2c399575dd7f2cba6e20db9b6e", | ||
| operation="UPDATE", | ||
| pgid="pgtrigger_update_update_9a032", | ||
| table="core_marker", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="object", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="insert_insert", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| func='INSERT INTO "core_objectevent" ("audio_description", "author", "created", "file_extension", "file_name_original", "file_size", "height", "id", "in_use", "is_used_by_other_user", "modified", "owner_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "slug", "sound_id", "source", "spritesheet_file", "spritesheet_metadata", "thumbnail", "title", "width") VALUES (NEW."audio_description", NEW."author", NEW."created", NEW."file_extension", NEW."file_name_original", NEW."file_size", NEW."height", NEW."id", NEW."in_use", NEW."is_used_by_other_user", NEW."modified", NEW."owner_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."slug", NEW."sound_id", NEW."source", NEW."spritesheet_file", NEW."spritesheet_metadata", NEW."thumbnail", NEW."title", NEW."width"); RETURN NULL;', | ||
| hash="dd7898ed958ac123fbbe20c2568791dea1f5319a", | ||
| operation="INSERT", | ||
| pgid="pgtrigger_insert_insert_25a7e", | ||
| table="core_object", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| pgtrigger.migrations.AddTrigger( | ||
| model_name="object", | ||
| trigger=pgtrigger.compiler.Trigger( | ||
| name="update_update", | ||
| sql=pgtrigger.compiler.UpsertTriggerSql( | ||
| condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)", | ||
| func='INSERT INTO "core_objectevent" ("audio_description", "author", "created", "file_extension", "file_name_original", "file_size", "height", "id", "in_use", "is_used_by_other_user", "modified", "owner_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "slug", "sound_id", "source", "spritesheet_file", "spritesheet_metadata", "thumbnail", "title", "width") VALUES (NEW."audio_description", NEW."author", NEW."created", NEW."file_extension", NEW."file_name_original", NEW."file_size", NEW."height", NEW."id", NEW."in_use", NEW."is_used_by_other_user", NEW."modified", NEW."owner_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."slug", NEW."sound_id", NEW."source", NEW."spritesheet_file", NEW."spritesheet_metadata", NEW."thumbnail", NEW."title", NEW."width"); RETURN NULL;', | ||
| hash="29621b17da2a972b7b6334e955fe8c8c37fa1065", | ||
| operation="UPDATE", | ||
| pgid="pgtrigger_update_update_27852", | ||
| table="core_object", | ||
| when="AFTER", | ||
| ), | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Guard the ordering of the <slug:slug> detail routes. | ||
|
|
||
| They were originally inserted alphabetically, which put them *before* their | ||
| literal siblings. Django matches in order and "upload", "edit", "create" and | ||
| "convert-spritesheet" all satisfy the slug converter, so every POST to those | ||
| endpoints resolved to a GET-only detail view and came back 405. | ||
| """ | ||
|
|
||
| from django.test import TestCase | ||
| from django.urls import resolve, reverse | ||
|
|
||
| # Each literal route that a sibling <slug:slug> pattern could swallow. | ||
| LITERAL_ROUTES = [ | ||
| ("create-artwork", "create_artwork"), | ||
| ("edit-artwork", "edit_artwork"), | ||
| ("edit-marker", "edit_marker"), | ||
| ("marker-upload", "marker_upload"), | ||
| ("edit-object", "edit_object"), | ||
| ("object-upload", "object_upload"), | ||
| ("convert-spritesheet", "convert_gif_to_spritesheet"), | ||
| ] | ||
|
|
||
| DETAIL_VIEWS = {"artwork_detail", "marker_detail", "object_detail"} | ||
|
|
||
|
|
||
| class TestUrlResolutionOrder(TestCase): | ||
| def test_literal_routes_are_not_swallowed_by_a_slug_pattern(self): | ||
| for route_name, expected_view in LITERAL_ROUTES: | ||
| with self.subTest(route=route_name): | ||
| match = resolve(reverse(route_name)) | ||
| assert match.func.__name__ == expected_view, ( | ||
| f"{route_name} resolved to {match.func.__name__}; a " | ||
| "<slug:slug> pattern is matching before it" | ||
| ) | ||
| assert match.func.__name__ not in DETAIL_VIEWS | ||
|
|
||
| def test_the_slug_routes_still_resolve_for_a_real_slug(self): | ||
| for route_name, expected_view in [ | ||
| ("artwork-detail", "artwork_detail"), | ||
| ("marker-detail", "marker_detail"), | ||
| ("object-detail", "object_detail"), | ||
| ]: | ||
| with self.subTest(route=route_name): | ||
| url = reverse(route_name, kwargs={"slug": "some-real-slug"}) | ||
| assert resolve(url).func.__name__ == expected_view |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using this counter in a while. If it conflicts with an existing slug, use directly the ID which is unique, not a counter in a while