Remaster (#38)
* setup new 'statistiques' module * added 'graphos' package and created first test graph * put graphos in requirements, deleted local folder * added "load_csv" management command ! * added update of premiere_rencontre field in 'load_csv' management command * added missing urls.py file * added 'merge' action and view * added 'info_completed' ratio * linked sujets:merge views inside suivi:details * added link to maraudes:details in notes table headers, if any * Major reorganisation, moved 'suivi' and 'sujets' to 'notes', cleanup in 'maraudes', dropping 'website' mixins (mostly useless) * small cleanup * worked on Maraude and Sujet lists * corrected missing line in notes.__init__ * restored 'details' view for maraudes and sujets insie 'notes' module * worked on 'notes': added navigation between maraude's compte-rendu, right content in details, header to list tables * changed queryset for CompteRenduDetailsView to all notes of same date, minor layout changes * added right content to 'details-sujet', created 'statistiques' view and update templates * restored 'statistiques' ajax view in 'details-sujet', fixed 'merge_two' util function * added auto-creation of FicheStatistique (plus some tests), pagination for notes in 'details-sujet' * added error-prone cases in paginator * fixed non-working modals, added titles * added UpdateStatistiques capacity in CompteRenduCreate view * fixed missing AjaxTemplateMixin for CreateSujetView, worked on compte-rendu creation scripts * fixed MaraudeManager.all_of() for common Maraudeurs, added color hints in planning * re-instated statistiques module link and first test page * added FinalizeView to send a mail before finalizing compte-rendu * Added PieChart view for FicheStatistique fields * small style updates, added 'age' and 'genre' fields from sujets in statistiques.PieChartView * worked on statistiques, fixed small issues in 'notes' list views * small theme change * removed some dead code * fixed notes.tests, fixed statistiques.info_completed display, added filter in SujetLisView * added some tests * added customised admin templates * added authenticate in CustomAuthenticatationBackend, more verbose login thanks to messages * added django-nose for test coverage * Corrected raising exception on first migration On first migration, qs.exists() would previously be called and raising an Exception, sot he migrations would fail. * Better try block * cleaned up custom settings.py, added some overrides of django base_settings * corrected bad dictionnary key
This commit is contained in:
@@ -1,22 +1,28 @@
|
||||
from django import forms
|
||||
from django.forms import inlineformset_factory
|
||||
from notes.forms import *
|
||||
from django.utils import timezone
|
||||
|
||||
from django_select2.forms import Select2Widget
|
||||
|
||||
# Models
|
||||
from .models import *
|
||||
from .notes import *
|
||||
from notes.forms import UserNoteForm, SimpleNoteForm
|
||||
from notes.models import Sujet, GENRE_CHOICES
|
||||
|
||||
|
||||
class MaraudeAutoDateForm(forms.ModelForm):
|
||||
""" Maraude ModelForm with disabled 'date' field """
|
||||
def current_year_range():
|
||||
""" Returns a range from year -1 to year + 2 """
|
||||
year = timezone.now().date().year
|
||||
return (year - 1, year, year + 1, year + 2)
|
||||
|
||||
|
||||
|
||||
class MaraudeHiddenDateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Maraude
|
||||
fields = ['date', 'heure_debut', 'referent', 'binome']
|
||||
widgets = {'date': forms.HiddenInput()}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['date'].disabled = True
|
||||
|
||||
|
||||
|
||||
@@ -29,34 +35,36 @@ class RencontreForm(forms.ModelForm):
|
||||
}
|
||||
|
||||
|
||||
ObservationInlineFormSet = inlineformset_factory( Rencontre, Observation,
|
||||
ObservationInlineFormSet = forms.inlineformset_factory( Rencontre, Observation,
|
||||
form=SimpleNoteForm,
|
||||
extra = 1,
|
||||
)
|
||||
|
||||
RencontreInlineFormSet = inlineformset_factory(
|
||||
RencontreInlineFormSet = forms.inlineformset_factory(
|
||||
Maraude, Rencontre,
|
||||
form = RencontreForm,
|
||||
extra = 0,
|
||||
)
|
||||
|
||||
ObservationInlineFormSetNoExtra = inlineformset_factory(
|
||||
ObservationInlineFormSetNoExtra = forms.inlineformset_factory(
|
||||
Rencontre, Observation,
|
||||
form = SimpleNoteForm,
|
||||
extra = 0
|
||||
)
|
||||
|
||||
|
||||
|
||||
class MonthSelectForm(forms.Form):
|
||||
|
||||
month = forms.ChoiceField(
|
||||
month = forms.ChoiceField(label="Mois",
|
||||
choices=[
|
||||
(1, 'Janvier'), (2, 'Février'), (3, 'Mars'), (4, 'Avril'),
|
||||
(5, 'Mai'), (6, 'Juin'), (7, 'Juillet'), (8, 'Août'),
|
||||
(9, 'Septembre'),(10, 'Octobre'),(11, 'Novembre'),(12, 'Décembre')
|
||||
],
|
||||
)
|
||||
year = forms.ChoiceField(
|
||||
choices = [(y, y) for y in [2015, 2016, 2017, 2018]]
|
||||
year = forms.ChoiceField(label="Année",
|
||||
choices = [(y, y) for y in current_year_range()]
|
||||
)
|
||||
|
||||
def __init__(self, *args, month=None, year=None, **kwargs):
|
||||
@@ -64,3 +72,48 @@ class MonthSelectForm(forms.Form):
|
||||
self.fields['month'].initial = month
|
||||
self.fields['year'].initial = year
|
||||
|
||||
|
||||
|
||||
class AppelForm(UserNoteForm):
|
||||
class Meta(UserNoteForm.Meta):
|
||||
model = Appel
|
||||
fields = ['sujet', 'text', 'entrant', 'created_date', 'created_time']
|
||||
|
||||
|
||||
|
||||
class SignalementForm(UserNoteForm):
|
||||
|
||||
nom = forms.CharField(64, required=False)
|
||||
prenom = forms.CharField(64, required=False)
|
||||
age = forms.IntegerField(required=False)
|
||||
genre = forms.ChoiceField(choices=GENRE_CHOICES)
|
||||
|
||||
class Meta(UserNoteForm.Meta):
|
||||
model = Signalement
|
||||
fields = ['text', 'source', 'created_date', 'created_time']
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if not self.cleaned_data['nom'] and not self.cleaned_data['prenom']:
|
||||
self.add_error('nom', '')
|
||||
self.add_error('prenom', '')
|
||||
raise forms.ValidationError("Entrez au moins un nom ou prénom")
|
||||
|
||||
def save(self, commit=True):
|
||||
sujet = Sujet.objects.create(
|
||||
nom=self.cleaned_data['nom'],
|
||||
prenom=self.cleaned_data['prenom'],
|
||||
genre=self.cleaned_data['genre'],
|
||||
age=self.cleaned_data['age']
|
||||
)
|
||||
instance = super().save(commit=False)
|
||||
instance.sujet = sujet
|
||||
if commit:
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class SendMailForm(forms.Form):
|
||||
|
||||
subject = forms.CharField(label="Objet")
|
||||
message = forms.CharField(widget=forms.Textarea, label="Contenu")
|
||||
|
||||
Reference in New Issue
Block a user