fix: safely resolve AppView urls and purge obsolete schools AppView
This commit is contained in:
parent
63bed7737d
commit
1ab3c71754
3 changed files with 33 additions and 1 deletions
|
|
@ -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),
|
||||||
|
]
|
||||||
|
|
@ -85,6 +85,17 @@ class AppView(models.Model):
|
||||||
return self.name_nl
|
return self.name_nl
|
||||||
return self.name_fr
|
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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,11 +216,13 @@
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="viewSwitcherDropdown">
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="viewSwitcherDropdown">
|
||||||
{% for view in accessible_views %}
|
{% for view in accessible_views %}
|
||||||
|
{% if view.url %}
|
||||||
<li>
|
<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 }}
|
<i class="bi {{ view.icon }} me-2"></i>{{ view.name }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue