feat(services): Add an icon, and a transitive redirect view

This commit is contained in:
Tom Hubrecht 2024-09-23 23:59:29 +02:00
parent 8c3cba0af8
commit cab8369558
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
6 changed files with 61 additions and 1 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2.12 on 2024-09-23 21:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("dgsi", "0002_service"),
]
operations = [
migrations.AddField(
model_name="service",
name="icon",
field=models.CharField(
blank=True, max_length=255, verbose_name="Icône du service"
),
),
]

View file

@ -17,6 +17,7 @@ ADMIN_GROUP = "dgnum_admins@sso.dgnum.eu"
class Service(models.Model):
name = models.CharField(_("Nom du service proposé"), max_length=255)
url = models.URLField(_("Adresse du service"))
icon = models.CharField(_("Icône du service"), max_length=255, blank=True)
def __str__(self) -> str:
return f"{self.name} [{self.url}]"

View file

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<h2 class="subtitle">{% trans "Services accessibles via la DGNum" %}</h2>
<hr>
<div class="buttons bt-links">
{% for service in service_list %}
<a class="button is-medium"
href="{% url "dgsi:dgn-services_redirect" service.pk %}">
<span class="icon"><i class="ti ti-{{ service.icon }}"></i></span>
<span>{{ service.name }}</span>
</a>
{% endfor %}
</div>
{% endblock content %}

View file

@ -17,4 +17,9 @@ urlpatterns = [
name="dgn-forbidden_account",
),
path("services/", views.ServiceListView.as_view(), name="dgn-services"),
path(
"services/redirect/<int:pk>",
views.ServiceRedirectView.as_view(),
name="dgn-services_redirect",
),
]

View file

@ -1,3 +1,4 @@
from typing import Any
from asgiref.sync import async_to_sync
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
@ -5,7 +6,8 @@ from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView, ListView, TemplateView
from django.views.generic import FormView, ListView, RedirectView, TemplateView
from django.views.generic.detail import SingleObjectMixin
from dgsi.forms import CreateKanidmAccountForm
from dgsi.mixins import StaffRequiredMixin
@ -30,6 +32,13 @@ class ServiceListView(LoginRequiredMixin, ListView):
model = Service
class ServiceRedirectView(LoginRequiredMixin, SingleObjectMixin, RedirectView):
model = Service
def get_redirect_url(self, *args: Any, **kwargs: Any) -> str:
return self.get_object().url
##
# INFO: Below are views related to the administration of DGSI

View file

@ -33,6 +33,14 @@ body {
);
}
.bt-links {
justify-content: space-evenly;
}
.bt-links > .button {
width: 47.5%;
}
.grid.groups {
--bulma-grid-column-min: 24rem;
}