Allow editing filtered entities from session list

This commit is contained in:
Lukáš Kucharczyk 2023-02-20 17:16:19 +01:00
parent 4086c078bd
commit 38b25ff27e
4 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,6 @@
## Unreleased
* Allow editing filtered entities from session list
* Add wikidata ID and year for editions
* Allow filtering by game, edition, purchase from the session list
* Add icons for the above

View File

@ -18,7 +18,22 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 inline">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</a>Filtering by "{% firstof purchase platform game edition ownership_type %}"
</a>
{% if purchase %}
Filtering by purchase "{{ purchase }}"
(<a href="{% url 'edit_purchase' purchase.id %}" class="hover:underline dark:text-white">Edit</a>)
{% elif platform %}
Filtering by purchase "{{ platform }}"
(<a href="{% url 'edit_platform' platform.id %}" class="hover:underline dark:text-white">Edit</a>)
{% elif game %}
Filtering by purchase "{{ game }}"
(<a href="{% url 'edit_game' game.id %}" class="hover:underline dark:text-white">Edit</a>)
{% elif edition %}
Filtering by purchase "{{ edition }}"
(<a href="{% url 'edit_edition' edition.id %}" class="hover:underline dark:text-white">Edit</a>)
{% elif ownership_type %}
Filtering by ownership type "{{ ownership_type }}"
{% endif%}
</span>
{% if purchase %}<a class="dark:text-white hover:underline block" href="{% url 'list_sessions_by_edition' purchase.edition.id %}">See all platforms</a>{% endif %}
{% endif %}

View File

@ -31,6 +31,8 @@ urlpatterns = [
path("add-purchase/", views.add_purchase, name="add_purchase"),
path("add-edition/", views.add_edition, name="add_edition"),
path("edit-edition/<int:edition_id>", views.edit_edition, name="edit_edition"),
path("edit-game/<int:game_id>", views.edit_game, name="edit_game"),
path("edit-platform/<int:platform_id>", views.edit_platform, name="edit_platform"),
path("add-device/", views.add_device, name="add_device"),
path("edit-session/<int:session_id>", views.edit_session, name="edit_session"),
path("edit-purchase/<int:purchase_id>", views.edit_purchase, name="edit_purchase"),

View File

@ -79,6 +79,30 @@ def edit_purchase(request, purchase_id=None):
return render(request, "add.html", context)
def edit_game(request, game_id=None):
context = {}
purchase = Game.objects.get(id=game_id)
form = GameForm(request.POST or None, instance=purchase)
if form.is_valid():
form.save()
return redirect("list_sessions")
context["title"] = "Edit Game"
context["form"] = form
return render(request, "add.html", context)
def edit_platform(request, platform_id=None):
context = {}
purchase = Platform.objects.get(id=platform_id)
form = PlatformForm(request.POST or None, instance=purchase)
if form.is_valid():
form.save()
return redirect("list_sessions")
context["title"] = "Edit Platform"
context["form"] = form
return render(request, "add.html", context)
def edit_edition(request, edition_id=None):
context = {}
edition = Edition.objects.get(id=edition_id)