Skip to content

Commit

Permalink
add statistics stuff to indicator app
Browse files Browse the repository at this point in the history
  • Loading branch information
aliounedia committed Apr 6, 2011
1 parent ee926d7 commit 489f34a
Show file tree
Hide file tree
Showing 46 changed files with 851 additions and 1,037 deletions.
103 changes: 57 additions & 46 deletions apps/indicator/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PaysForm (forms.ModelForm):
'''
name =forms.CharField(
label =_("Pays") ,
widget= forms.TextInput({"size": "50"}))
widget= forms.TextInput())
class Meta:
model =Pays
fields = ("name")
Expand All @@ -24,10 +24,10 @@ class RegionForm(forms.Form):
'''
name = forms.CharField (
label =_("Region"),
widget= forms.TextInput({"size": "50"}))
widget= forms.TextInput())
pays = forms.ModelChoiceField (
queryset = Pays.objects.all () ,
empty_label = "-"*50 )
empty_label = "-" )
def save (self ,*args , **kwargs):
super (RegionForm , self).save (*args , **kwargs)
class Meta :
Expand All @@ -40,7 +40,7 @@ class IndicatorValueForm (forms.ModelForm):
value = forms.CharField(
label =_("Liste des valeurs de l'indicateur"),
required =False,
widget= forms.Textarea (attrs ={"rows":"10" , "cols": "50"}))
widget= forms.Textarea ())
class Meta:
model =IndicatorValue
exclude = ("indicator" , "submission")
Expand Down Expand Up @@ -74,26 +74,6 @@ def clean_name(self) :
raise ValidationError (_("Vous devez saisir une valeur pour effectuer une recherche"))
return name

class HeaderSubmissionForm (forms.Form):
date = forms.DateField (label =_('Le mois de saisie') ,
widget =SelectDateWidget , required =True)
village = forms.ModelChoiceField (
label = _("Le Village "),
#Uniquement les utilsateurs du groupe des indicateurs
queryset=IndicatorVillage.objects.all () , required =True)
# Le nom du superviseure de la fiche
#supervisor =models.CharField (max_length = 200 , blank =True , null =True)

class IndicatorStatForm (forms.Form):
'''
Create form to display statistiques data related of the indicator
'''
indicator = forms.ModelChoiceField (
label = _("Choisir un seul Indicateur"),
queryset=Indicator.objects.all ())
projects = forms.ModelMultipleChoiceField(
label = _("CHoisir les projects"),
queryset =Project.objects.all ())


class IndicatorExportForm (forms.Form):
Expand All @@ -112,28 +92,19 @@ class ProjectStatForm (forms.Form):
'''
Create form to display statistiques date related of the projet
'''
project = forms.ModelChoiceField (
label = _("Choisir un seul projet"),
queryset=Project.objects.all ())
indicators = forms.ModelMultipleChoiceField(
label = _("Choisir les indicateurs"),
queryset =Indicator.objects.all ())
project = forms.ModelChoiceField(queryset =Project.objects.all ())
indicator = forms.ModelChoiceField(queryset =Indicator.objects.all ())
village = forms.ModelChoiceField(queryset =IndicatorVillage.objects.all ())
date1 = forms.DateField (label ="Le mois de saisie (1)" ,widget =SelectDateWidget , required =False)
date2 = forms.DateField (label ="Le mois de saisie (2)" ,widget =SelectDateWidget , required =False)

class ProjectExportForm (forms.Form):
'''
Create form to display statistiques data related of the indicator
'''
projects = forms.ModelMultipleChoiceField(
label = _("Choisir le ou les projets a exporter"),queryset =Project.objects.all () ,required=False)
projects = forms.ModelMultipleChoiceField(queryset =Project.objects.all() ,required =False)


class VillageStatForm (forms.Form):
'''
The village list for export not for stat
'''
villages = forms.ModelMultipleChoiceField (
label = _("Choisir les utilisateurs a expoter"),
#Uniquement les utilsateurs du groupe des indicateurs
queryset=IndicatorVillage.objects.all ())

class VillageExportForm (forms.Form):
'''
Expand All @@ -146,6 +117,7 @@ class VillageExportForm (forms.Form):
class DataExportForm (forms.Form):
project = forms.ModelChoiceField (
label = _("Choisir un projet"),
required =False,
queryset=Project.objects.all ())
villages = forms.ModelMultipleChoiceField(
label = _("Les villages"),
Expand Down Expand Up @@ -175,17 +147,17 @@ class UserForm (forms.Form):
'''create a form to create user , update .The user is the editor od the indicator system'''
first_name = forms.CharField (
label = _("Nom de l'employer pour la saisie") ,
widget =forms.TextInput ({"size":"50"}))
widget =forms.TextInput ())
last_name = forms.CharField (
label = _("Prenom de l'employer pour la saisie") ,
widget =forms.TextInput ({"size":"50"}))
widget =forms.TextInput ())
# to pass to django.contrib.auth.views as login
username = forms.CharField (
label = _("Le login") ,
widget =forms.TextInput ({"size":"50"}))
widget =forms.TextInput ())
password = forms.CharField (
label = _("Mot de passe pour la saisie") ,
widget =forms.PasswordInput ({"size":"50"}))
widget =forms.PasswordInput ())
group = forms.ModelChoiceField(
label = _("Choisir le groupe de l'utilsateur"),
queryset=Group.objects.all ().filter (name__in= ['indicator_edit' , 'indicator_admin'] ))
Expand Down Expand Up @@ -242,8 +214,47 @@ class UserSearchForm (forms.Form):
first_name = forms.CharField (
required =False,
label = _("Nom de l'employer pour la saisie") ,
widget =forms.TextInput ({"size":"50"}))
widget =forms.TextInput ())
last_name = forms.CharField (
required=False,
label = _("Prenom de l'employer pour la saisie") ,
widget =forms.TextInput ({"size":"50"}))
widget =forms.TextInput ())

class RegionForm_(forms.ModelForm):
class Meta:
model = Region

class DepartementForm(forms.ModelForm):
class Meta:
model = Departement
class ArrondissementForm(forms.ModelForm):
class Meta:
model = Arrondissement
class CommuneArrondissementForm(forms.ModelForm):
class Meta:
model = CommuneArrondissement

class CommuneForm(forms.ModelForm):
class Meta:
model = Commune

class IndicatorVillageForm(forms.ModelForm):
class Meta:
model = IndicatorVillage

class PrefectureForm(forms.ModelForm):
class Meta:
model = Prefecture

class SuPrefectureForm(forms.ModelForm):
class Meta:
model = SubPrefecture

class SecteurForm(forms.ModelForm):
class Meta:
model = Secteur

class DistrictForm(forms.ModelForm):
class Meta:
model = District

47 changes: 32 additions & 15 deletions apps/indicator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django import forms
from datetime import date
from django.forms.extras.widgets import SelectDateWidget
import re

class Project(models.Model):
'''
Expand Down Expand Up @@ -38,7 +39,9 @@ class Project(models.Model):
# Village of the projects
villages = models.ManyToManyField ("Area" , null =True , blank =True)
created = models.DateTimeField (auto_now_add =True)


# Store the contry name of the project here
pays = models.ForeignKey ("Pays" ,null =True , blank =True , related_name ="project")
class Meta:
permissions = (
("can_admin", "Active Member"),
Expand Down Expand Up @@ -182,7 +185,7 @@ class IndicatorValue(models.Model):
max_length = 200 , null =True , blank =True,
help_text =_("Saisir ici la liste des valeurs de l'indicateur si l'indicacteur est une liste de choix"))
def __unicode__(self):
return "%s" %(self.value)
return u"%s=%s" %(unicode (self.indicator), self.value)

class Fiche (models.Model):
'''
Expand Down Expand Up @@ -214,7 +217,7 @@ class Fiche (models.Model):
indicators = models.ManyToManyField("Indicator", null =True , blank =True)
period = models.CharField (max_length = 2 , choices = FICHE_PERIOD_CHOICES)
created = models.DateTimeField (auto_now_add =True)

@classmethod
def create_fiche (cls , project , indicators):
dict = {"m" : [] , "s" :[] , 't' :[] , 'a':[]}
Expand Down Expand Up @@ -259,7 +262,7 @@ def form_save (self , indicators):
if indicator.type in (Indicator.TYPE_TEXT ,Indicator.TYPE_NUMERIC):
fields["indicator_%s"%indicator.pk] = forms.CharField (
label =_(indicator.name) ,
widget =forms.TextInput (attrs ={"size" : "50"}),
widget =forms.TextInput (),
)
elif indicator.type == Indicator.TYPE_DATE:
fields['indicator_%s'%indicator.pk] = forms.DateField(
Expand All @@ -270,7 +273,7 @@ def form_save (self , indicators):
fields["indicator_%s"%indicator.pk] = forms.MultipleChoiceField (
label = _(indicator.name),
widget = forms.CheckboxSelectMultiple() ,
choices = as_tuple(indicator.values.all ())
choices = as_tuple(indicator.values.filter(submission__isnull =True))
)
def clean (self):
return self.cleaned_data
Expand All @@ -280,14 +283,14 @@ def clean (self):

def form_edit (self ,submission ,indicator_values):
'''
Basically different to the first submission form ,only for edition
'''
Basically different to the first submission form ,only for edition
'''
fields ={}
for indicator_value in indicator_values:
if indicator_value.indicator.type in (Indicator.TYPE_TEXT ,Indicator.TYPE_NUMERIC):
fields["indicator_%s"%indicator_value.indicator.pk] = forms.CharField (
label =_(indicator_value.indicator.name),
widget =forms.TextInput (attrs ={"size" : "50"}),
widget =forms.TextInput (),
initial =str (indicator_value.value))
elif indicator_value.indicator.type in (Indicator.TYPE_DATE):
fields["indicator_%s"%indicator_value.indicator.pk] = forms.CharField (
Expand All @@ -299,10 +302,12 @@ def form_edit (self ,submission ,indicator_values):
label = _(indicator_value.indicator.name),
widget = forms.CheckboxSelectMultiple (),
initial= as_ids (IndicatorValue.objects.filter (
indicator=indicator_value.indicator ,
submission = submission).all ()),
indicator=indicator_value.indicator ,
submission = submission).all ()),
# Add submission to the filter
# I will chekh later if it is a good filter
choices= as_tuple(IndicatorValue.objects.filter (
indicator =indicator_value.indicator).all()))
indicator =indicator_value.indicator , submission =submission).all()))

def clean (self):
return self.cleaned_data
Expand All @@ -311,7 +316,7 @@ def clean (self):
{"base_fields" : fields , "clean" :clean})

def __unicode__(self):
return "%s , %s"%(self.pk, self.period)
return "<Fiche %s>"%(self.get_period_display())

def as_ids (queryset):
return ["%s" %obj.pk for obj in queryset ]
Expand All @@ -331,8 +336,12 @@ class Submission (models.Model):
village = models.ForeignKey("Area" , null =True , blank =True)
supervisor = models.CharField(max_length= 200 , blank =True , null =True)



@property
def project (self):
if hasattr (self.fiche , "project") and self.fiche.project:
return self.fiche.project
return None

class Area(models.Model):
'''
An are can be
Expand Down Expand Up @@ -433,6 +442,7 @@ class Arrondissement(Area):
pass
class CommuneArrondissement(Area):
pass
Communearrondissement = CommuneArrondissement
class CommunauteRurale (Area):
pass
class Commune(Area):
Expand All @@ -443,6 +453,7 @@ class Prefecture (Area):
pass
class SubPrefecture (Area):
pass
Subprefecture =SubPrefecture
class Secteur (Area):
pass
class Etat(Area):
Expand All @@ -453,11 +464,17 @@ class District (Area):
pass
class CommuneArrondissement(Area):
pass
Communearrondissement = CommuneArrondissement
class CommuneHurbaine (Area):
pass
class IndicatorVillage (Area):
class IndicatorVillage(Area):
'''
This not be null , but Iam not sure
'''
village = models.ForeignKey(SuiviVillage ,
null =True , blank =True)

def __unicode(self):
return self.village

Indicatorvillage = IndicatorVillage
16 changes: 4 additions & 12 deletions apps/indicator/templates/indicator/add_arrondissement.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
{% endblock %}
{% block content %}
<div class ='module'>
{% if msg %}
<p>
{% for m in msg %}
{{ m }}
{% endfor %}
</p>
{% endif %}
<h2>{% trans "Creer un arrondissement" %}</a></h2>
<div class = 'indicator-menu'>
<a href = '/indicator'>{% trans "Retour Accueil"%}</a>
</div>
<div class = 'indicator-menu'><a href = '/indicator'>{% trans "Retour Accueil"%}</a></div>
<table>
<tr>{% if msg %}<td>{% for m in msg %}{{ m }}{% endfor %}</td>{% endif %}</tr>
<tr>
<td coslpan =2>
<form action = "" method ="post">
Expand Down Expand Up @@ -57,8 +49,8 @@ <h2>{% trans "Creer un arrondissement" %}</a></h2>
<td>{{ region.longitude}}</td>
<td>{{ region.surface}}</td>
<td>{{ region.created|date:"Y-m-d" }}</td>
<td><a href = "/indicator/delete_arrondissement/{{ pay.pk }}">{% trans "Delete" %}</td>
<td><a href = "/indicator/edit_arrondissement/{{ pay.pk }}">{% trans "Edit" %}</td>
<td><a href = "/indicator/delete_arrondissement/{{ region.pk }}/arrondissement">{% trans "Delete" %}</td>
<td><a href = "/indicator/edit_arrondissement/{{ region.pk }}/arrondissement">{% trans "Edit" %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
17 changes: 4 additions & 13 deletions apps/indicator/templates/indicator/add_commune.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@
<link type="text/css" rel="stylesheet" href="/static/indicator/stylesheets/layout.css" />
<link type="text/css" rel="stylesheet" href="/static/webui/stylesheets/modules.css" />
{% endblock %}

{% block content %}
<div class ='module'>
{% if msg %}
<p>
{% for m in msg %}
{{ m }}
{% endfor %}
</p>
{% endif %}
<h2>{% trans "Creer une commune" %}</a></h2>
<div class ='indicator-menu'>
<a href = '/indicator'>{% trans "Retour Accueil"%}</a>
</div>
<div class ='indicator-menu'><a href = '/indicator'>{% trans "Retour Accueil"%}</a></div>
<table>
<tr>{% if msg %}<td>{% for m in msg %}{{ m }}{% endfor %}</td>{% endif %}</tr>
<tr>
<form action = "" method ="post">
<td coslpan =2>
Expand Down Expand Up @@ -57,8 +48,8 @@ <h2>{% trans "Creer une commune" %}</a></h2>
<td>{{ region.longitude}}</td>
<td>{{ region.surface}}</td>
<td>{{ region.created|date:"Y-m-d" }}</td>
<td><a href = "/indicator/delete_commune/{{ pay.pk }}">{% trans "Delete" %}</td>
<td><a href = "/indicator/edit_commune/{{ pay.pk }}">{% trans "Edit" %}</td>
<td><a href = "/indicator/delete_commune/{{ region.pk }}/commune">{% trans "Delete" %}</td>
<td><a href = "/indicator/edit_commune/{{ region.pk }}/commune">{% trans "Edit" %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Loading

0 comments on commit 489f34a

Please sign in to comment.