fix: safely resolve AppView urls and purge obsolete schools AppView

This commit is contained in:
kdeterme 2026-09-19 13:54:49 +02:00
parent 63bed7737d
commit 1ab3c71754
3 changed files with 33 additions and 1 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 6.0.7
from django.db import migrations
def remove_obsolete_schools_appview(apps, schema_editor):
AppView = apps.get_model('common', 'AppView')
AppView.objects.filter(code='schools').delete()
class Migration(migrations.Migration):
dependencies = [
('common', '0014_userconfig_inspection_list_filters_and_more'),
]
operations = [
migrations.RunPython(remove_obsolete_schools_appview, reverse_code=migrations.RunPython.noop),
]

View file

@ -85,6 +85,17 @@ class AppView(models.Model):
return self.name_nl
return self.name_fr
@property
def url(self):
"""Renvoie l'URL résolue de la vue ou None si la route n'est pas enregistrée."""
if not self.url_name:
return None
try:
from django.urls import reverse
return reverse(self.url_name)
except Exception:
return None
def __str__(self):
return self.name

View file

@ -216,11 +216,13 @@
</button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="viewSwitcherDropdown">
{% for view in accessible_views %}
{% if view.url %}
<li>
<a class="dropdown-item {% if current_view and view.code == current_view.code %}active{% endif %}" href="{% url view.url_name %}">
<a class="dropdown-item {% if current_view and view.code == current_view.code %}active{% endif %}" href="{{ view.url }}">
<i class="bi {{ view.icon }} me-2"></i>{{ view.name }}
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</li>