Skip to content

Commit

Permalink
feat(surveys): setup views and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 14, 2023
1 parent 64285d0 commit 5801747
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
86 changes: 86 additions & 0 deletions lacommunaute/surveys/forms.py
Original file line number Diff line number Diff line change
@@ -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",
]
11 changes: 11 additions & 0 deletions lacommunaute/surveys/urls.py
Original file line number Diff line number Diff line change
@@ -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/<int:pk>/", views.DSPDetailView.as_view(), name="dsp_detail"),
]
33 changes: 33 additions & 0 deletions lacommunaute/surveys/views.py
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 27 additions & 0 deletions lacommunaute/templates/surveys/dsp_detail.html
Original file line number Diff line number Diff line change
@@ -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 %}

<h1>Les recommandations suite à votre diagnostic</h1>

{% for label, recommendation in object.recommendations.items %}
<div class="row mt-3">
<div class="col-12">
<div class="card post-edit">
<div class="card-header">
<h3 class="m-0 h4 card-title">{{label}}</h3>
</div>
<div class="card-body">
{{ recommendation }}
</div>
</div>
</div>
</div>
{% endfor %}


{% endblock content %}
31 changes: 31 additions & 0 deletions lacommunaute/templates/surveys/dsp_form.html
Original file line number Diff line number Diff line change
@@ -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 %}

<h1>Diagnostic socio-professionnel</h1>

<form method="post">
{% csrf_token %}

{% for field in form %}
<div class="row mt-3">
<div class="col-12">
<div class="card post-edit">
<div class="card-header">
<h3 class="m-0 h4 card-title">{{ field.label_tag }}</h3>
</div>
<div class="card-body">
{{ field }}
</div>
</div>
</div>
</div>
{% endfor %}
<input type="submit" class="btn btn-sm btn-secondary mt-3" value="Valider">
</form>

{% endblock content %}

0 comments on commit 5801747

Please sign in to comment.