Factorisation du code des formulaires/vues/templates/urls

parent e4e1297d
......@@ -2,6 +2,42 @@
from django import forms
from django.contrib.admin import widgets
REGISTERED_FORMS = {}
def register_form(category, id, title, url=None):
"""
Register a form class with configuration options so it can be displayed
automatically with the proper URL/template/title:
@register_form(category='form_category', id='form_id', title='Hello')
class MyFormClass():
...
Would serve the form MyFormClass on /form_category/form_id, with the
page title being "hello".
If you provide the url argument, the form url will use that instead of the {category}/{id} scheme.
"""
def decorator(form_class):
if category:
full_id = '{}_{}'.format(category, id)
url_path = url or '{}/{}'.format(category, id)
else:
full_id = id
url_path = url or id
REGISTERED_FORMS[full_id] = {
'form_class': form_class,
'url_path': url_path,
'title': title,
'category': category,
}
return form_class
return decorator
@register_form(category=None, id="chgmtprenom", title="Nouvelle attestation de changement de prénom")
class ChgmtPrenomForm(forms.Form):
procurantfirstname = forms.CharField(label="Prénom (le vrai hein) de la personne trans")
procurantlastname = forms.CharField(label="Nom de famille de la personne trans")
......@@ -54,24 +90,29 @@ class ProcurationForm(forms.Form):
personaddress2 = forms.CharField(label="Code postal et Ville")
persongender = forms.ChoiceField(label="Accord de la personne", choices=((0, "féminin"), (1, "masculin")))
@register_form(category='procuration', id="cpam", title="Nouvelle procuration pour la CPAM")
class CPAMProcuration(ProcurationForm):
procurantdepartement = forms.CharField(label="Département de la caisse de CPAM de la personne faisant la procuration")
procurantss = forms.IntegerField(label="Numéro de sécu")
@register_form(category='procuration', id="ecole", title="Nouvelle procuration pour une École/Université")
class EcoleProcuration(ProcurationForm):
procurantecole = forms.CharField(label="École/Université de la personne faisant la procuration")
@register_form(category='procuration', id="banque", title="Nouvelle procuration pour une Banque")
class BanqueProcuration(ProcurationForm):
procurantbanque = forms.CharField(label="Banque de la personne faisant la procuration")
@register_form(category='procuration', id="entreprise", title="Nouvelle procuration pour une entreprise avec numéro de contrat")
class EntrepriseProcuration(ProcurationForm):
procurantentreprise = forms.CharField(label="Entreprise de la personne faisant la procuration")
procurantcontrat = forms.CharField(label="Numéro de contrat")
@register_form(category='procuration', id="free", title="Nouvelle procuration pour Free")
class FreeProcuration(ProcurationForm):
pass
@register_form(category='procuration', id="impots", title="Nouvelle procuration pour les impôts")
class ImpotsProcuration(ProcurationForm):
procurantimpots = forms.CharField(label="Ville dont on dépend pour les impots")
procurantfiscal = forms.CharField(label="Numéro fiscal")
......@@ -79,21 +120,27 @@ class ImpotsProcuration(ProcurationForm):
class RelanceProcurationForm(ProcurationForm):
datepremiercourrier = forms.DateField(label="Date du premier courrier", widget=forms.SelectDateWidget(years=range(2019, 3000)))
@register_form(category='procuration_relance', id="cpam", title="Relance procuration pour la CPAM", url='procuration/relance/cpam')
class CPAMRelanceProcuration(RelanceProcurationForm, CPAMProcuration):
pass
@register_form(category='procuration_relance', id="ecole", title="Relance une École/Université", url='procuration/relance/ecole')
class EcoleRelanceProcuration(RelanceProcurationForm, EcoleProcuration):
pass
@register_form(category='procuration_relance', id="banque", title="Relance pour une Banque", url='procuration/relance/banque')
class BanqueRelanceProcuration(RelanceProcurationForm, BanqueProcuration):
pass
@register_form(category='procuration_relance', id="entreprise", title="Relance pour entreprise avec numéro de contrat", url='procuration/relance/entreprise')
class EntrepriseRelanceProcuration(RelanceProcurationForm, EntrepriseProcuration):
pass
@register_form(category='procuration_relance', id="free", title="Relance pour Free", url='procuration/relance/free')
class FreeRelanceProcuration(RelanceProcurationForm, FreeProcuration):
pass
@register_form(category='procuration_relance', id="impots", title="Relance pour les impôts", url='procuration/relance/impots')
class ImpotsRelanceProcuration(RelanceProcurationForm, ImpotsProcuration):
pass
......@@ -112,24 +159,29 @@ class StandaloneForm(forms.Form):
deadname = forms.CharField(label="Deadname (seulement le prénom)")
date = forms.DateField(label="Date du courrier", widget=forms.SelectDateWidget(years=range(1900, 3000)))
@register_form(category='standalone', id="cpam", title="CPAM")
class CPAMStandalone(StandaloneForm):
departement = forms.CharField(label="Département de la caisse de CPAM ")
ss = forms.IntegerField(label="Numéro de sécu")
@register_form(category='standalone', id="ecole", title="École/Université")
class EcoleStandalone(StandaloneForm):
ecole = forms.CharField(label="École/Université ")
@register_form(category='standalone', id="banque", title="Banque")
class BanqueStandalone(StandaloneForm):
banque = forms.CharField(label="Banque ")
@register_form(category='standalone', id="entreprise", title="entreprise avec numéro de contrat")
class EntrepriseStandalone(StandaloneForm):
entreprise = forms.CharField(label="Entreprise ")
contrat = forms.CharField(label="Numéro de contrat")
@register_form(category='standalone', id="free", title="Free")
class FreeStandalone(StandaloneForm):
pass
@register_form(category='standalone', id="impots", title="Impôts")
class ImpotsStandalone(StandaloneForm):
impots = forms.CharField(label="Ville dont on dépend pour les impots")
fiscal = forms.CharField(label="Numéro fiscal")
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle procuration pour la CPAM</h1>
<h1>{{ title }}</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
<legend>
{% if category == 'procuration' %}
Génération de la procuration
{% else %}
Génération de la lettre
{% endif %}
</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
......
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>CPAM</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la lettre</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Relance procuration pour la CPAM</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle procuration pour une Banque</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Banque</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la lettre</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Relance pour une Banque</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle attestation de changement de prénom</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de l'attestation</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle procuration pour une École/Université</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>École/Université</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la lettre</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Relance une École/Université</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle procuration pour une entreprise avec numéro de contrat</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>entreprise avec numéro de contrat</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la lettre</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Relance pour entreprise avec numéro de contrat</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Nouvelle procuration pour Free</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la procuration</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}
{% extends 'pdfgenerator/base.html' %}
{% block content %}
<h1>Free</h1>
<div class="container">
<form class="form-horizontal" method="post">{% csrf_token %}
<fieldset>
<legend>Génération de la lettre</legend>
{% for field in form %}
{% if field.errors %}
<div class="form-group error">
<label class="form-label">{{ field.label }}</label>
<div class="forms">{{ field }}
<span class="help-inline">
{% for error in field.errors %}{{ error }}{% endfor %}
</span>
</div>
</div>
{% else %}
<div class="form-group">
<label class="form-label">{{ field.label }}</label>
<div class="form">{{ field }}
{% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Générer</button>
</div>
</form>
</div>
{% endblock %}