From cab836955872a8455ddf7567367b0180b4e7b119 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 23 Sep 2024 23:59:29 +0200 Subject: [PATCH] feat(services): Add an icon, and a transitive redirect view --- src/dgsi/migrations/0003_service_icon.py | 19 +++++++++++++++++++ src/dgsi/models.py | 1 + src/dgsi/templates/dgsi/service_list.html | 18 ++++++++++++++++++ src/dgsi/urls.py | 5 +++++ src/dgsi/views.py | 11 ++++++++++- src/shared/static/bulma/bulma.scss | 8 ++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/dgsi/migrations/0003_service_icon.py create mode 100644 src/dgsi/templates/dgsi/service_list.html diff --git a/src/dgsi/migrations/0003_service_icon.py b/src/dgsi/migrations/0003_service_icon.py new file mode 100644 index 0000000..25666b9 --- /dev/null +++ b/src/dgsi/migrations/0003_service_icon.py @@ -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" + ), + ), + ] diff --git a/src/dgsi/models.py b/src/dgsi/models.py index 4c4b670..404ff51 100644 --- a/src/dgsi/models.py +++ b/src/dgsi/models.py @@ -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}]" diff --git a/src/dgsi/templates/dgsi/service_list.html b/src/dgsi/templates/dgsi/service_list.html new file mode 100644 index 0000000..2c7b2bb --- /dev/null +++ b/src/dgsi/templates/dgsi/service_list.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} + +{% load i18n %} + +{% block content %} +

{% trans "Services accessibles via la DGNum" %}

+
+ + +{% endblock content %} diff --git a/src/dgsi/urls.py b/src/dgsi/urls.py index 7c2f866..848df88 100644 --- a/src/dgsi/urls.py +++ b/src/dgsi/urls.py @@ -17,4 +17,9 @@ urlpatterns = [ name="dgn-forbidden_account", ), path("services/", views.ServiceListView.as_view(), name="dgn-services"), + path( + "services/redirect/", + views.ServiceRedirectView.as_view(), + name="dgn-services_redirect", + ), ] diff --git a/src/dgsi/views.py b/src/dgsi/views.py index 54231bf..a9b2e7a 100644 --- a/src/dgsi/views.py +++ b/src/dgsi/views.py @@ -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 diff --git a/src/shared/static/bulma/bulma.scss b/src/shared/static/bulma/bulma.scss index a465188..fd9e8a7 100644 --- a/src/shared/static/bulma/bulma.scss +++ b/src/shared/static/bulma/bulma.scss @@ -33,6 +33,14 @@ body { ); } +.bt-links { + justify-content: space-evenly; +} + +.bt-links > .button { + width: 47.5%; +} + .grid.groups { --bulma-grid-column-min: 24rem; }