From 5801747b830043888d7d3c1995bf2b8f99700716 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Thu, 14 Sep 2023 18:38:36 +0200 Subject: [PATCH] =?UTF-8?q?feat(surveys):=C2=A0setup=20views=20and=20forms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/surveys/forms.py | 86 +++++++++++++++++++ lacommunaute/surveys/urls.py | 11 +++ lacommunaute/surveys/views.py | 33 +++++++ .../templates/surveys/dsp_detail.html | 27 ++++++ lacommunaute/templates/surveys/dsp_form.html | 31 +++++++ 5 files changed, 188 insertions(+) create mode 100644 lacommunaute/surveys/forms.py create mode 100644 lacommunaute/surveys/urls.py create mode 100644 lacommunaute/surveys/views.py create mode 100644 lacommunaute/templates/surveys/dsp_detail.html create mode 100644 lacommunaute/templates/surveys/dsp_form.html diff --git a/lacommunaute/surveys/forms.py b/lacommunaute/surveys/forms.py new file mode 100644 index 000000000..2a0dc7901 --- /dev/null +++ b/lacommunaute/surveys/forms.py @@ -0,0 +1,86 @@ +from django import forms + +from lacommunaute.surveys.enums import ( + DSPAvailability, + DSPHousing, + DSPJudicial, + DSPLanguageSkills, + DSPMobility, + DSPResources, + DSPRightsAccess, + DSPWorkCapacity, +) + +from .models import DSP + + +class DSPForm(forms.ModelForm): + work_capacity = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPWorkCapacity.choices, + label="Capacité à occuper un poste de travail", + initial=None, + required=True, + ) + language_skills = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPLanguageSkills.choices, + label="Maîtrise de la langue française", + initial=None, + required=True, + ) + housing = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPHousing.choices, + label="Logement", + initial=None, + required=True, + ) + rights_access = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPRightsAccess.choices, + label="Accès aux droits", + initial=None, + required=True, + ) + mobility = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPMobility.choices, + label="Mobilité", + initial=None, + required=True, + ) + resources = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPResources.choices, + label="Ressources", + initial=None, + required=True, + ) + judicial = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPJudicial.choices, + label="Situation judiciaire", + initial=None, + required=True, + ) + availability = forms.ChoiceField( + widget=forms.RadioSelect, + choices=DSPAvailability.choices, + label="Disponibilité", + initial=None, + required=True, + ) + + class Meta: + model = DSP + fields = [ + "work_capacity", + "language_skills", + "housing", + "rights_access", + "mobility", + "resources", + "judicial", + "availability", + ] diff --git a/lacommunaute/surveys/urls.py b/lacommunaute/surveys/urls.py new file mode 100644 index 000000000..b560d23da --- /dev/null +++ b/lacommunaute/surveys/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from lacommunaute.surveys import views + + +app_name = "surveys" + +urlpatterns = [ + path("dsp/create/", views.DSPCreateView.as_view(), name="dsp_create"), + path("dsp//", views.DSPDetailView.as_view(), name="dsp_detail"), +] diff --git a/lacommunaute/surveys/views.py b/lacommunaute/surveys/views.py new file mode 100644 index 000000000..77e7ebd62 --- /dev/null +++ b/lacommunaute/surveys/views.py @@ -0,0 +1,33 @@ +from django.contrib.auth.mixins import LoginRequiredMixin +from django.urls import reverse_lazy +from django.views.generic.detail import DetailView +from django.views.generic.edit import CreateView + +from lacommunaute.surveys.forms import DSPForm +from lacommunaute.surveys.models import DSP + + +class DSPCreateView(LoginRequiredMixin, CreateView): + model = DSP + template_name = "surveys/dsp_form.html" + form_class = DSPForm + + def get_recommendations(self): + return { + "Recommandations": "Parcours SIAE", + "Logement": "lien vers la recherche de solutions de logement DORA", + "Mobilité": "lien vers la recherche de solutions de mobilité DORA", + } + + def get_success_url(self): + return reverse_lazy("surveys:dsp_detail", kwargs={"pk": self.object.pk}) + + def form_valid(self, form): + form.instance.user = self.request.user + form.instance.recommendations = self.get_recommendations() + return super().form_valid(form) + + +class DSPDetailView(LoginRequiredMixin, DetailView): + model = DSP + template_name = "surveys/dsp_detail.html" diff --git a/lacommunaute/templates/surveys/dsp_detail.html b/lacommunaute/templates/surveys/dsp_detail.html new file mode 100644 index 000000000..b4ed7fdcf --- /dev/null +++ b/lacommunaute/templates/surveys/dsp_detail.html @@ -0,0 +1,27 @@ +{% extends 'board_base.html' %} +{% load i18n %} + +{% block title %}Diagnostic Socio Professionnel{{ block.super }}{% endblock %} +{% block meta_description %}Recommandations{% endblock meta_description %}" + +{% block content %} + +

Les recommandations suite à votre diagnostic

+ + {% for label, recommendation in object.recommendations.items %} +
+
+
+
+

{{label}}

+
+
+ {{ recommendation }} +
+
+
+
+ {% endfor %} + + +{% endblock content %} diff --git a/lacommunaute/templates/surveys/dsp_form.html b/lacommunaute/templates/surveys/dsp_form.html new file mode 100644 index 000000000..153a7268c --- /dev/null +++ b/lacommunaute/templates/surveys/dsp_form.html @@ -0,0 +1,31 @@ +{% extends 'board_base.html' %} +{% load i18n %} + +{% block title %}Diagnostic Socio Professionnel{{ block.super }}{% endblock %} +{% block meta_description %}DSP{% endblock meta_description %}" + +{% block content %} + +

Diagnostic socio-professionnel

+ +
+ {% csrf_token %} + + {% for field in form %} +
+
+
+
+

{{ field.label_tag }}

+
+
+ {{ field }} +
+
+
+
+ {% endfor %} + +
+ +{% endblock content %}