Skip to content
Snippets Groups Projects
Commit a39a5311 authored by Benjamin Hättasch's avatar Benjamin Hättasch Committed by Nadja Geisler
Browse files

Introduce detail and edit URLs as properties in AK model

This way, the frontend views will be used when AKSubmission is installed and active, or otherwise the link to the built-in AK edit form in backend
This reduces the coupling between AKSubmission and other apps that previously needed that app
Use that new property in all places where previously an URL to the submission view was used (for consistency and to allow changes in one place in AKSubmission, too)
This implements #166
parent 32b2471c
Branches
No related tags found
No related merge requests found
Showing
with 44 additions and 33 deletions
......@@ -48,8 +48,7 @@ class DashboardEventView(DetailView):
text = _('AK "%(ak)s" deleted.') % {'ak': s.name}
icon = ('times', 'fas')
recent_changes.append({'icon': icon, 'text': text, 'link': reverse_lazy('submit:ak_detail', kwargs={
'event_slug': context['event'].slug, 'pk': s.id}), 'timestamp': s.history_date})
recent_changes.append({'icon': icon, 'text': text, 'link': s.instance.detail_url, 'timestamp': s.history_date})
# Changes in plan
if apps.is_installed("AKPlan"):
......@@ -59,8 +58,7 @@ class DashboardEventView(DetailView):
for changed_slot in last_changed_slots:
recent_changes.append({'icon': ('clock', 'far'),
'text': _('AK "%(ak)s" (re-)scheduled.') % {'ak': changed_slot.ak.name},
'link': reverse_lazy('submit:ak_detail', kwargs={
'event_slug': context['event'].slug, 'pk': changed_slot.ak.id}),
'link': changed_slot.ak.detail_url,
'timestamp': changed_slot.updated})
# Sort by change date...
......
......@@ -308,7 +308,7 @@ class AKSlotAdmin(admin.ModelAdmin):
@display(description=_('AK Details'))
def ak_details_link(self, akslot):
if apps.is_installed("AKSubmission") and akslot.ak is not None:
link = f"<a href={reverse('submit:ak_detail', args=[akslot.event.slug, akslot.ak.pk])}>{str(akslot.ak)}</a>"
link = f"<a href={{ akslot.detail_url }}>{str(akslot.ak)}</a>"
return mark_safe(link)
return "-"
......
......@@ -2,6 +2,7 @@ import itertools
from datetime import timedelta
from django.db import models
from django.apps import apps
from django.db.models import Count
from django.urls import reverse_lazy
from django.utils import timezone
......@@ -326,6 +327,18 @@ class AK(models.Model):
def availabilities(self):
return "Availability".objects.filter(ak=self)
@property
def edit_url(self):
if apps.is_installed("AKScheduling"):
return reverse_lazy('submit:ak_edit', kwargs={'event_slug': self.event.slug, 'pk': self.id})
return reverse_lazy('admin:AKModel_ak_change', kwargs={'object_id': self.id})
@property
def detail_url(self):
if apps.is_installed("AKScheduling"):
return reverse_lazy('submit:ak_detail', kwargs={'event_slug': self.event.slug, 'pk': self.id})
return self.edit_url
class Room(models.Model):
""" A room describes where an AK can be held.
......
......@@ -4,7 +4,7 @@
<span class="text-secondary float-end">
{{ message.timestamp|date:"Y-m-d H:i:s" }}
</span>
<h5><a href="{% url 'submit:ak_detail' event_slug=message.ak.event.slug pk=message.ak.pk %}">{{ message.ak }}</a></h5>
<h5><a href="{{ message.ak.detail_url }}">{{ message.ak }}</a></h5>
<p>{{ message.text }}</p>
</td></tr>
{% endfor %}
......
......@@ -23,11 +23,11 @@
<td>{{ ak }}</td>
{% if "AKSubmission"|check_app_installed %}
<td class="text-end">
<a href="{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
<a href="{{ ak.detail_url }}" data-bs-toggle="tooltip"
title="{% trans 'Details' %}"
class="btn btn-primary">{% fa6_icon 'info' 'fas' %}</a>
{% if event.active %}
<a href="{% url 'submit:ak_edit' event_slug=event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
<a href="{{ ak.edit_url }}" data-bs-toggle="tooltip"
title="{% trans 'Edit' %}"
class="btn btn-success">{% fa6_icon 'pencil-alt' 'fas' %}</a>
{% endif %}
......
......@@ -12,7 +12,7 @@
'resourceId': '{{ slot.room.title }}',
'backgroundColor': '{{ slot|highlight_change_colors }}',
'borderColor': '{{ slot.ak.category.color }}',
'url': '{% url 'submit:ak_detail' event_slug=event.slug pk=slot.ak.pk %}'
'url': '{{ slot.ak.detail_url }}'
},
{% endif %}
{% endfor %}
......
......@@ -21,7 +21,7 @@
{'title': '{{ slot.ak }}',
'start': '{{ slot.start | timezone:event.timezone | date:"Y-m-d H:i:s" }}',
'end': '{{ slot.end | timezone:event.timezone | date:"Y-m-d H:i:s" }}',
'url': '{% url 'submit:ak_detail' event_slug=event.slug pk=slot.ak.pk %}',
'url': '{{ slot.ak.detail_url }}',
'borderColor': '{{ slot.ak.track.color }}',
'color': '{{ slot.ak.category.color }}',
},
......
......@@ -19,7 +19,7 @@
{'title': '{{ slot.ak }} @ {{ slot.room }}',
'start': '{{ slot.start | timezone:event.timezone | date:"Y-m-d H:i:s" }}',
'end': '{{ slot.end | timezone:event.timezone | date:"Y-m-d H:i:s" }}',
'url': '{% url 'submit:ak_detail' event_slug=event.slug pk=slot.ak.pk %}',
'url': '{{ slot.ak.detail_url }}',
'color': '{{ track.color }}',
'borderColor': '{{ slot.ak.category.color }}',
},
......
......@@ -4,7 +4,7 @@
<table class="table table-striped">
{% for akslot in slots %}
<tr>
<td class="breakWord"><b><a href="{% url 'submit:ak_detail' event_slug=event.slug pk=akslot.ak.pk %}">{{ akslot.ak.name }}</a></b></td>
<td class="breakWord"><b><a href="{{ akslot.ak.detail_url }}">{{ akslot.ak.name }}</a></b></td>
<td>{{ akslot.start | time:"H:i" }} - {{ akslot.end | time:"H:i" }}</td>
<td class="breakWord">{% if akslot.room and akslot.room.pk != '' %}
<a href="{% url 'plan:plan_room' event_slug=event.slug pk=akslot.room.pk %}">{{ akslot.room }}</a>
......
......@@ -13,14 +13,14 @@
{% block content %}
<h4 class="mt-4 mb-4">{% trans "AKs with public notes" %}</h4>
{% for ak in aks_with_comment %}
<a href="{% url "submit:ak_edit" event_slug=event.slug pk=ak.pk %}">{{ ak }}</a><br>{{ ak.notes }}<br><br>
<a href="{{ ak.edit_url }}">{{ ak }}</a><br>{{ ak.notes }}<br><br>
{% empty %}
-
{% endfor %}
<h4 class="mt-4 mb-4">{% trans "AKs without availabilities" %}</h4>
{% for ak in aks_without_availabilities %}
<a href="{% url "submit:ak_edit" event_slug=event.slug pk=ak.pk %}">{{ ak }}</a><br>
<a href="{{ ak.edit_url }}">{{ ak }}</a><br>
{% empty %}
-<br>
{% endfor %}
......@@ -30,7 +30,7 @@
<h4 class="mt-4 mb-4">{% trans "AK wishes with slots" %}</h4>
{% for ak in ak_wishes_with_slots %}
<a href="{% url "submit:ak_detail" event_slug=event.slug pk=ak.pk %}">{{ ak }}</a> <a href="{% url "admin:AKModel_akslot_changelist" %}?ak={{ ak.pk }}">({{ ak.akslot__count }})</a><br>
<a href="{{ ak.detail_url }}">{{ ak }}</a> <a href="{% url "admin:AKModel_akslot_changelist" %}?ak={{ ak.pk }}">({{ ak.akslot__count }})</a><br>
{% empty %}
-<br>
{% endfor %}
......@@ -39,7 +39,7 @@
<h4 class="mt-4 mb-4">{% trans "AKs without slots" %}</h4>
{% for ak in aks_without_slots %}
<a href="{% url "submit:ak_detail" event_slug=event.slug pk=ak.pk %}">{{ ak }}</a><br>
<a href="{{ ak.detail_url }}">{{ ak }}</a><br>
{% empty %}
-<br>
{% endfor %}
......
......@@ -17,7 +17,7 @@
<li>
{% with group.grouper as ak %}
{% if "AKSubmission"|check_app_installed %}
<a href="{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}">{{ ak }}</a>
<a href="{{ ak.detail_url }}">{{ ak }}</a>
{% else %}
{{ ak }}
{% endif %}
......
......@@ -14,7 +14,7 @@ def orga_message_saved_handler(sender, instance: AKOrgaMessage, created, **kwarg
if created and settings.SEND_MAILS:
host = 'https://' + settings.ALLOWED_HOSTS[0] if len(settings.ALLOWED_HOSTS) > 0 else 'http://127.0.0.1:8000'
url = f"{host}{reverse_lazy('submit:ak_detail', kwargs={'pk': instance.ak.pk, 'event_slug': instance.ak.event.slug})}"
url = f"{host}{instance.ak.detail_url}"
mail = EmailMessage(
f"[AKPlanning] New message for AK '{instance.ak}' ({instance.ak.event})",
......@@ -31,7 +31,7 @@ def slot_created_handler(sender, instance: AKSlot, created, **kwargs):
if created and settings.SEND_MAILS and apps.is_installed("AKPlan") and not instance.event.plan_hidden and instance.room is None and instance.start is None:
host = 'https://' + settings.ALLOWED_HOSTS[0] if len(settings.ALLOWED_HOSTS) > 0 else 'http://127.0.0.1:8000'
url = f"{host}{reverse_lazy('submit:ak_detail', kwargs={'pk': instance.ak.pk, 'event_slug': instance.ak.event.slug})}"
url = f"{host}{instance.ak.detail_url}"
mail = EmailMessage(
f"[AKPlanning] New slot for AK '{instance.ak}' ({instance.ak.event}) added",
......
......@@ -120,7 +120,7 @@
<a href="{% url 'submit:akmessage_add' event_slug=ak.event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
title="{% trans 'Add confidential message to organizers' %}"
class="btn btn-warning">{% fa6_icon 'envelope' 'fas' %}</a>
<a href="{% url 'submit:ak_edit' event_slug=ak.event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
<a href="{{ ak.edit_url }}" data-bs-toggle="tooltip"
title="{% trans 'Edit' %}"
class="btn btn-success">{% fa6_icon 'pencil-alt' 'fas' %}</a>
{% endif %}
......
......@@ -12,7 +12,7 @@
<li class="breadcrumb-item"><a
href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li>
<li class="breadcrumb-item"><a
href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}">{{ ak.short_name }}</a></li>
href="{{ ak.detail_url }}">{{ ak.short_name }}</a></li>
<li class="breadcrumb-item active">{% trans "Edit" %}</li>
{% endblock %}
......
......@@ -15,7 +15,7 @@
<li class="breadcrumb-item"><a
href="{% url 'submit:submission_overview' event_slug=ak.event.slug %}">{% trans "AK Submission" %}</a></li>
<li class="breadcrumb-item"><a
href='{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}'>{{ ak.short_name }}</a></li>
href='{{ ak.detail_url }}'>{{ ak.short_name }}</a></li>
<li class="breadcrumb-item active">{% trans 'History' %}</li>
{% endblock %}
......@@ -23,7 +23,7 @@
{% include "messages.html" %}
<div class="float-end">
<a href='{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}' data-bs-toggle="tooltip"
<a href='{{ ak.detail_url }}' data-bs-toggle="tooltip"
title="{% trans 'Back' %}"
class="btn btn-info">{% fa6_icon 'arrow-circle-left' 'fas' %}</a>
</div>
......
......@@ -2,7 +2,7 @@
{% if forloop.counter0 > 0 %}
,&nbsp;
{% endif %}
<a href="{% url 'submit:ak_detail' event_slug=slug pk=ak.pk %}">{{ ak }}</a>
<a href="{{ ak.detail_url }}">{{ ak }}</a>
{% empty %}
-
{% endfor %}
......@@ -16,7 +16,7 @@
{% for ak in AKs %}
<tr>
<td>
<a href="{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}"
<a href="{{ ak.detail_url }}"
class="text-dark text-decoration-none font-weight-bold">
{{ ak.name }}
</a>
......@@ -38,7 +38,7 @@
</td>
<td>{% category_linked_badge ak.category event.slug %}</td>
<td class="text-end" style="white-space: nowrap;">
<a href="{% url 'submit:ak_detail' event_slug=ak.event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
<a href="{{ ak.detail_url }}" data-bs-toggle="tooltip"
title="{% trans 'Details' %}"
class="btn btn-primary">{% fa6_icon 'info' 'fas' %}</a>
{% if ak.link %}
......@@ -47,7 +47,7 @@
class="btn btn-info">{% fa6_icon 'external-link-alt' 'fas' %}</a>
{% endif %}
{% if event.active %}
<a href="{% url 'submit:ak_edit' event_slug=event.slug pk=ak.pk %}" data-bs-toggle="tooltip"
<a href="{{ ak.edit_url }}" data-bs-toggle="tooltip"
title="{% trans 'Edit' %}"
class="btn btn-success">{% fa6_icon 'pencil-alt' 'fas' %}</a>
{% if interest_indication_active %}
......
......@@ -12,7 +12,7 @@
<li class="breadcrumb-item"><a
href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li>
<li class="breadcrumb-item"><a
href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}">{{ ak.short_name }}</a></li>
href="{{ ak.detail_url }}">{{ ak.short_name }}</a></li>
<li class="breadcrumb-item active">{% trans "Add confidential message to organizers" %}</li>
{% endblock %}
......@@ -31,7 +31,7 @@
{% fa6_icon "undo-alt" 'fas' %} {% trans "Reset Form" %}
</button>
<a href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}" class="btn btn-secondary">
<a href="{{ ak.detail_url }}" class="btn btn-secondary">
{% fa6_icon "times" 'fas' %} {% trans "Cancel" %}
</a>
</form>
......
......@@ -11,7 +11,7 @@
<li class="breadcrumb-item"><a
href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li>
<li class="breadcrumb-item"><a
href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}">{{ ak.short_name }}</a></li>
href="{{ ak.detail_url }}">{{ ak.short_name }}</a></li>
<li class="breadcrumb-item active">{% trans "AK Duration(s)" %}</li>
{% endblock %}
......@@ -29,7 +29,7 @@
{% fa6_icon "undo-alt" 'fas' %} {% trans "Reset Form" %}
</button>
<a href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}" class="btn btn-secondary">
<a href="{{ ak.detail_url }}" class="btn btn-secondary">
{% fa6_icon "times" 'fas' %} {% trans "Cancel" %}
</a>
</form>
......
......@@ -11,7 +11,7 @@
<li class="breadcrumb-item"><a
href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li>
<li class="breadcrumb-item"><a
href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}">{{ ak.short_name }}</a></li>
href="{{ ak.detail_url }}">{{ ak.short_name }}</a></li>
<li class="breadcrumb-item active">{% trans "AK Duration(s)" %}</li>
{% endblock %}
......@@ -41,7 +41,7 @@
{% fa6_icon "check" 'fas' %} {% trans "Confirm" %}
</button>
<a href="{% url 'submit:ak_detail' event_slug=event.slug pk=ak.pk %}" class="btn btn-secondary">
<a href="{{ ak.detail_url }}" class="btn btn-secondary">
{% fa6_icon "times" 'fas' %} {% trans "Cancel" %}
</a>
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment