Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommandations #512

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lacommunaute/surveys/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.contrib import admin

from lacommunaute.surveys.models import DSP
from lacommunaute.surveys.models import DSP, Recommendation


@admin.register(DSP)
class DSPAdmin(admin.ModelAdmin):
list_display = ("user", "created")
raw_id_fields = ("user",)


@admin.register(Recommendation)
class RecommendationAdmin(admin.ModelAdmin):
list_display = ("category", "text")
30 changes: 30 additions & 0 deletions lacommunaute/surveys/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
from pathlib import Path

import tomllib
from django.apps import AppConfig
from django.db import models


class ForumStatsAppConfig(AppConfig):
label = "surveys"
name = "lacommunaute.surveys"
verbose_name = "Survey"
verbose_name_plural = "Surveys"

def ready(self):
super().ready()
models.signals.post_migrate.connect(create_recommendations, sender=self)


def create_recommendations(*args, **kwargs):
from lacommunaute.surveys.models import Recommendation

recommendations_specfile = Path(__file__).parent / "recommendations.toml"
with open(recommendations_specfile, "rb") as f:
recommendation_specs = tomllib.load(f)
recommendations = []
codenames = []
for spec in recommendation_specs["recommendations"]:
codename = spec["codename"]
codenames.append(codename)
recommendations.append(
Recommendation(
codename=codename,
category=spec["category"],
text=spec["text"],
)
)
Recommendation.objects.bulk_create(recommendations, ignore_conflicts=True)
Recommendation.objects.exclude(codename__in=codenames).delete()
78 changes: 39 additions & 39 deletions lacommunaute/surveys/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,62 @@
from django.db import models


class DSPWorkCapacity(models.TextChoices):
LEVEL0 = "0", "Est dans l’incapacité immédiate d’occuper un poste de travail"
LEVEL1 = "1", "A besoin d’un accompagnement avant de pouvoir occuper un poste de travail"
LEVEL2 = "2", "Peut occuper un poste de travail dans des conditions aménagées"
LEVEL3 = "3", "Peut occuper un poste de travail dans des conditions ordinaires"
class DSPWorkCapacity(models.IntegerChoices):
LEVEL0 = 0, "Est dans l’incapacité immédiate d’occuper un poste de travail"
LEVEL1 = 1, "A besoin d’un accompagnement avant de pouvoir occuper un poste de travail"
LEVEL2 = 2, "Peut occuper un poste de travail dans des conditions aménagées"
LEVEL3 = 3, "Peut occuper un poste de travail dans des conditions ordinaires"


class DSPLanguageSkills(models.TextChoices):
LEVEL0 = "0", "Analphabète à illettré "
LEVEL1 = "1", "Relève d’une formation FLE et/ou savoirs de base"
LEVEL2 = "2", "Laborieuse à limitée"
LEVEL3 = "3", "Bonne à parfaite"
class DSPLanguageSkills(models.IntegerChoices):
LEVEL0 = 0, "Analphabète à illettré "
LEVEL1 = 1, "Relève d’une formation FLE et/ou savoirs de base"
LEVEL2 = 2, "Laborieuse à limitée"
LEVEL3 = 3, "Bonne à parfaite"


class DSPHousing(models.TextChoices):
LEVEL0 = "0", "Sans domicile fixe"
LEVEL1 = "1", "Hébergement collectif de type CHRS ou CADA…"
LEVEL2 = "2", "Hébergement hors structure sociale, logement insalubre, risque de perte de logement"
LEVEL3 = "3", "Logement stable"
class DSPHousing(models.IntegerChoices):
LEVEL0 = 0, "Sans domicile fixe"
LEVEL1 = 1, "Hébergement collectif de type CHRS ou CADA…"
LEVEL2 = 2, "Hébergement hors structure sociale, logement insalubre, risque de perte de logement"
LEVEL3 = 3, "Logement stable"


class DSPRightsAccess(models.TextChoices):
LEVEL0 = "0", "Ne connait pas ses droits, en situation de non recours"
LEVEL1 = "1", "Renoncement ou en rupture ou difficulté de renouvellement de droits"
LEVEL2 = "2", "Connait ses droits et démarches en cours"
LEVEL3 = "3", "Bénéficie des droits afférents à sa situation"
class DSPRightsAccess(models.IntegerChoices):
LEVEL0 = 0, "Ne connait pas ses droits, en situation de non recours"
LEVEL1 = 1, "Renoncement ou en rupture ou difficulté de renouvellement de droits"
LEVEL2 = 2, "Connait ses droits et démarches en cours"
LEVEL3 = 3, "Bénéficie des droits afférents à sa situation"


class DSPMobility(models.TextChoices):
LEVEL0 = "0", "Ne sait pas se rendre seul à son lieu de travail"
class DSPMobility(models.IntegerChoices):
LEVEL0 = 0, "Ne sait pas se rendre seul à son lieu de travail"
LEVEL1 = (
"1",
1,
(
"Sait organiser son covoiturage et/ou possède un véhicule"
" mais problème de mise en règle (assurance, contrôle technique…)"
),
)
LEVEL2 = "2", "Sait utiliser les transports en commun et/ou possède un véhicule 2 roues"
LEVEL3 = "3", "Possède un véhicule et permis de conduire conformes et covoitureur possible"
LEVEL2 = 2, "Sait utiliser les transports en commun et/ou possède un véhicule 2 roues"
LEVEL3 = 3, "Possède un véhicule et permis de conduire conformes et covoiturage possible"


class DSPResources(models.TextChoices):
LEVEL0 = "0", "Situation de surendettement sans dépôt de dossier et/ou sans ressources"
LEVEL1 = "1", "Surendettement avec dossier déposé et suivi"
LEVEL2 = "2", "Besoins primaires assurés au jour le jour et/ou mesure de protection type curatelle"
LEVEL3 = "3", "Sait gérer son budget ; avec capacité de financer par exemple un permis de conduire"
class DSPResources(models.IntegerChoices):
LEVEL0 = 0, "Situation de surendettement sans dépôt de dossier et/ou sans ressources"
LEVEL1 = 1, "Surendettement avec dossier déposé et suivi"
LEVEL2 = 2, "Besoins primaires assurés au jour le jour et/ou mesure de protection type curatelle"
LEVEL3 = 3, "Sait gérer son budget ; avec capacité de financer par exemple un permis de conduire"


class DSPJudicial(models.TextChoices):
LEVEL_0 = "0", "Exécution de peine en cours "
LEVEL_1 = "1", "Suivi SPIP/PJJ après exécution de peine"
LEVEL_2 = "2", "Aucun suivi en cours"
class DSPJudicial(models.IntegerChoices):
LEVEL0 = 0, "Exécution de peine en cours "
LEVEL1 = 1, "Suivi SPIP/PJJ après exécution de peine"
LEVEL2 = 2, "Aucun suivi en cours"


class DSPAvailability(models.TextChoices):
LEVEL0 = "0", "Faible voire difficile (garde d’enfant ; ascendant ; famille)"
LEVEL1 = "1", "A organiser"
LEVEL2 = "2", "Immédiate avec des contraintes horaires"
LEVEL3 = "3", "Immédiate et sans contraintes horaires"
class DSPAvailability(models.IntegerChoices):
LEVEL0 = 0, "Faible voire difficile (garde d’enfant ; ascendant ; famille)"
LEVEL1 = 1, "A organiser"
LEVEL2 = 2, "Immédiate avec des contraintes horaires"
LEVEL3 = 3, "Immédiate et sans contraintes horaires"
17 changes: 14 additions & 3 deletions lacommunaute/surveys/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import factory

from lacommunaute.surveys.models import DSP
from lacommunaute.surveys.recommendations import get_recommendations
from lacommunaute.users.factories import UserFactory


Expand All @@ -9,6 +10,16 @@ class Meta:
model = DSP

user = factory.SubFactory(UserFactory)
recommendations = {
"Recommandations": "Parcours SIAE",
}
work_capacity = factory.Faker("pyint", min_value=0, max_value=3)
language_skills = factory.Faker("pyint", min_value=0, max_value=3)
housing = factory.Faker("pyint", min_value=0, max_value=3)
rights_access = factory.Faker("pyint", min_value=0, max_value=3)
mobility = factory.Faker("pyint", min_value=0, max_value=3)
resources = factory.Faker("pyint", min_value=0, max_value=3)
judicial = factory.Faker("pyint", min_value=0, max_value=2)
availability = factory.Faker("pyint", min_value=0, max_value=3)

@factory.post_generation
def recommendations(obj, create, extracted, **kwargs):
if create and isinstance(extracted, int):
obj.recommendations.set(get_recommendations(obj))
84 changes: 15 additions & 69 deletions lacommunaute/surveys/forms.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,10 @@
from django import forms

from lacommunaute.surveys.enums import (
DSPAvailability,
DSPHousing,
DSPJudicial,
DSPLanguageSkills,
DSPMobility,
DSPResources,
DSPRightsAccess,
DSPWorkCapacity,
)

from .models import DSP
from lacommunaute.surveys.models import DSP
from lacommunaute.surveys.recommendations import get_recommendations


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 = [
Expand All @@ -84,3 +17,16 @@ class Meta:
"judicial",
"availability",
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
model = self._meta.model
for fieldname, formfield in self.fields.items():
modelfield = model._meta.get_field(fieldname)
formfield.widget = forms.RadioSelect(choices=modelfield.choices)

def save(self, commit=True):
instance = super().save(commit=commit)
recommendations = get_recommendations(instance)
instance.recommendations.set(recommendations)
return instance
4 changes: 2 additions & 2 deletions lacommunaute/surveys/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Migration(migrations.Migration):
),
],
options={
"verbose_name": "Diagnostic socio-professionnel",
"verbose_name_plural": "Diagnostics socio-professionnels",
"verbose_name": "diagnostic parcours IAE",
"verbose_name_plural": "diagnostics parcours IAE",
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from django.db import migrations, models

from lacommunaute.surveys import enums


class Migration(migrations.Migration):
dependencies = [
("surveys", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Recommendation",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("codename", models.CharField(editable=False, max_length=100, unique=True)),
("category", models.CharField(editable=False, max_length=100)),
("text", models.TextField()),
],
options={},
),
migrations.AlterField(
model_name="dsp",
name="availability",
field=models.PositiveIntegerField(
choices=enums.DSPAvailability.choices,
verbose_name="disponibilité",
),
),
migrations.AlterField(
model_name="dsp",
name="housing",
field=models.PositiveIntegerField(
choices=enums.DSPHousing.choices,
verbose_name="logement",
),
),
migrations.AlterField(
model_name="dsp",
name="judicial",
field=models.PositiveIntegerField(
choices=enums.DSPJudicial.choices,
verbose_name="situation judiciaire",
),
),
migrations.AlterField(
model_name="dsp",
name="language_skills",
field=models.PositiveIntegerField(
choices=enums.DSPLanguageSkills.choices,
verbose_name="maîtrise de la langue française",
),
),
migrations.AlterField(
model_name="dsp",
name="mobility",
field=models.PositiveIntegerField(
choices=enums.DSPMobility.choices,
verbose_name="mobilité",
),
),
migrations.RemoveField(
model_name="dsp",
name="recommendations",
),
migrations.AlterField(
model_name="dsp",
name="resources",
field=models.PositiveIntegerField(
choices=enums.DSPResources.choices,
verbose_name="ressources",
),
),
migrations.AlterField(
model_name="dsp",
name="rights_access",
field=models.PositiveIntegerField(
choices=enums.DSPRightsAccess.choices,
verbose_name="accès aux droits",
),
),
migrations.AlterField(
model_name="dsp",
name="work_capacity",
field=models.PositiveIntegerField(
choices=enums.DSPWorkCapacity.choices,
verbose_name="capacité à occuper un poste de travail",
),
),
migrations.AddField(
model_name="dsp",
name="recommendations",
field=models.ManyToManyField(to="surveys.recommendation"),
),
]
Loading
Loading