Commit 5b2ac094 authored by Gabriel Detraz's avatar Gabriel Detraz

Utilise l'héritage des forms, corrige le bug des champs mutiples

parent 537baf08
# -*- coding: utf-8 -*-
from django import forms
class SearchForm(forms.Form):
class BaseForm(forms.Form):
""" Formulaire de recherche pour le cableur """
uid = forms.CharField(label=u'Login', max_length=40, required=False)
chbre = forms.CharField(label=u'Chambre', max_length=5, required=False)
aid = forms.IntegerField(label=u'Aid', required=False)
nom = forms.CharField(label=u'Nom', max_length=40, required=False)
class AdherentForm(BaseForm):
tel = forms.CharField(label=u'Telephone', max_length=10, required=False)
aid = forms.IntegerField(label=u'Aid', required=False)
prenom = forms.CharField(label=u'Prenom', max_length=40, required=False)
mail = forms.EmailField(label=u'Mail', required=False)
tel = forms.CharField(label=u'Telephone', max_length=10, required=False)
class FactureForm(forms.Form):
fid = forms.IntegerField(label=u'Fid', required=False)
class ClubForm(BaseForm):
cid = forms.IntegerField(label=u'Cid', required=False)
class MachineForm(forms.Form):
host = forms.CharField(label=u'Nom de machine', max_length=40, required=False)
macAddress = forms.CharField(label=u'Mac', max_length=17, required=False)
ipHostNumber = forms.CharField(label=u'IP', max_length=16, required=False)
mid = forms.IntegerField(label=u'Mid', required=False)
{% extends "template.html" %}
{% block title %}Application de Cablage{% endblock %}
{% block h1 %}Cablage sur l'intranet{% endblock %}
{% block title %}Application de Câblage{% endblock %}
{% block h1 %}Câblage{% endblock %}
{% block head %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="/static/css/cablage.css" />
......
......@@ -120,49 +120,49 @@
<h2>Filtre adhérent</h2>
<div class="row">
<div class="three columns">
{{ form.nom.label_tag }}
{{ form.nom }}
{{ form.nom.errors }}
{{ form.nom.help_text }}
{{ adherentform.nom.label_tag }}
{{ adherentform.nom }}
{{ adherentform.nom.errors }}
{{ adherentform.nom.help_text }}
</div>
<div class="three columns">
{{ form.prenom.label_tag }}
{{ form.prenom }}
{{ form.prenom.errors }}
{{ form.prenom.help_text }}
{{ adherentform.prenom.label_tag }}
{{ adherentform.prenom }}
{{ adherentform.prenom.errors }}
{{ adherentform.prenom.help_text }}
</div>
<div class="three columns">
{{ form.tel.label_tag }}
{{ form.tel }}
{{ form.tel.errors }}
{{ form.tel.help_text }}
{{ adherentform.tel.label_tag }}
{{ adherentform.tel }}
{{ adherentform.tel.errors }}
{{ adherentform.tel.help_text }}
</div>
<div class="three columns">
{{ form.mail.label_tag }}
{{ form.mail }}
{{ form.mail.errors }}
{{ form.mail.help_text }}
{{ adherentform.mail.label_tag }}
{{ adherentform.mail }}
{{ adherentform.mail.errors }}
{{ adherentform.mail.help_text }}
</div>
</div>
<div class="row">
<div class="three columns">
{{ form.chbre.label_tag }}
{{ form.chbre }}
{{ form.chbre.errors }}
{{ form.chbre.help_text }}
{{ adherentform.chbre.label_tag }}
{{ adherentform.chbre }}
{{ adherentform.chbre.errors }}
{{ adherentform.chbre.help_text }}
</div>
<div class="three columns">
{{ form.aid.label_tag }}
{{ form.aid }}
{{ form.aid.errors }}
{{ form.aid.help_text }}
{{ adherentform.aid.label_tag }}
{{ adherentform.aid }}
{{ adherentform.aid.errors }}
{{ adherentform.aid.help_text }}
</div>
<div class="three columns">
{{ form.uid.label_tag }}
{{ form.uid }}
{{ form.uid.errors }}
{{ form.uid.help_text }}
{{ adherentform.uid.label_tag }}
{{ adherentform.uid }}
{{ adherentform.uid.errors }}
{{ adherentform.uid.help_text }}
</div>
</div>
{% endif %}
......@@ -171,28 +171,28 @@
<h2>Filtre club</h2>
<div class="row">
<div class="three columns">
{{ form.nom.label_tag }}
{{ form.nom }}
{{ form.nom.errors }}
{{ form.nom.help_text }}
{{ clubform.nom.label_tag }}
{{ clubform.nom }}
{{ clubform.nom.errors }}
{{ clubform.nom.help_text }}
</div>
<div class="three columns">
{{ form.chbre.label_tag }}
{{ form.chbre }}
{{ form.chbre.errors }}
{{ form.chbre.help_text }}
{{ clubform.chbre.label_tag }}
{{ clubform.chbre }}
{{ clubform.chbre.errors }}
{{ clubform.chbre.help_text }}
</div>
<div class="three columns">
{{ form.cid.label_tag }}
{{ form.cid }}
{{ form.cid.errors }}
{{ form.cid.help_text }}
{{ clubform.cid.label_tag }}
{{ clubform.cid }}
{{ clubform.cid.errors }}
{{ clubform.cid.help_text }}
</div>
<div class="three columns">
{{ form.uid.label_tag }}
{{ form.uid }}
{{ form.uid.errors }}
{{ form.uid.help_text }}
{{ clubform.uid.label_tag }}
{{ clubform.uid }}
{{ clubform.uid.errors }}
{{ clubform.uid.help_text }}
</div>
</div>
{% endif %}
......@@ -201,28 +201,28 @@
<h2>Filtre machine</h2>
<div class="row">
<div class="three columns">
{{ form.host.label_tag }}
{{ form.host }}
{{ form.host.errors }}
{{ form.host.help_text }}
{{ machineform.host.label_tag }}
{{ machineform.host }}
{{ machineform.host.errors }}
{{ machineform.host.help_text }}
</div>
<div class="three columns">
{{ form.macAddress.label_tag }}
{{ form.macAddress }}
{{ form.macAddress.errors }}
{{ form.macAddress.help_text }}
{{ machineform.macAddress.label_tag }}
{{ machineform.macAddress }}
{{ machineform.macAddress.errors }}
{{ machineform.macAddress.help_text }}
</div>
<div class="three columns">
{{ form.ipHostNumber.label_tag }}
{{ form.ipHostNumber }}
{{ form.ipHostNumber.errors }}
{{ form.ipHostNumber.help_text }}
{{ machineform.ipHostNumber.label_tag }}
{{ machineform.ipHostNumber }}
{{ machineform.ipHostNumber.errors }}
{{ machineform.ipHostNumber.help_text }}
</div>
<div class="three columns">
{{ form.mid.label_tag }}
{{ form.mid }}
{{ form.mid.errors }}
{{ form.mid.help_text }}
{{ machineform.mid.label_tag }}
{{ machineform.mid }}
{{ machineform.mid.errors }}
{{ machineform.mid.help_text }}
</div>
</div>
{% endif %}
......@@ -231,10 +231,10 @@
<h2>Filtre facture</h2>
<div class="row">
<div class="three columns">
{{ form.fid.label_tag }}
{{ form.fid }}
{{ form.fid.errors }}
{{ form.fid.help_text }}
{{ factureform.fid.label_tag }}
{{ factureform.fid }}
{{ factureform.fid.errors }}
{{ factureform.fid.help_text }}
</div>
</div>
{% endif %}
......
......@@ -3,7 +3,7 @@ from django.conf.urls import url
import views
urlpatterns = patterns('',
urlpatterns = [
url('^$', views.afficher, name='afficher'),
url('rechercher/(?P<objet>[^/]*)?/?$', views.rechercher, name="rechercher"),
)
]
......@@ -14,7 +14,7 @@ from intranet.settings import BASE_LDAP_TEST
import lc_ldap.shortcuts
from forms import SearchForm
from forms import MachineForm, AdherentForm, ClubForm, FactureForm
if BASE_LDAP_TEST:
......@@ -40,12 +40,29 @@ def rechercher(request, ldap, objet):
messages.error(request, u""" Accès interdit, droits insuffisants """ )
return HttpResponseRedirect("/")
if request.method == "POST":
form = SearchForm(request.POST)
if form.is_valid():
machineform = MachineForm(request.POST)
adherentform = AdherentForm(request.POST)
clubform = ClubForm(request.POST)
factureform = FactureForm(request.POST)
formchanged = []
formcleaned = dict()
if machineform.is_valid():
formchanged += machineform.changed_data
formcleaned.update(machineform.cleaned_data)
if clubform.is_valid():
formchanged += clubform.changed_data
formcleaned.update(clubform.cleaned_data)
if adherentform.is_valid():
formchanged += adherentform.changed_data
formcleaned.update(adherentform.cleaned_data)
if factureform.is_valid():
formchanged += factureform.changed_data
formcleaned.update(factureform.cleaned_data)
if machineform.is_valid() or clubform.is_valid() or adherentform.is_valid() or factureform.is_valid():
filtre = u""
result = None
for champ in form.changed_data:
valeur = form.cleaned_data[champ]
for champ in formchanged:
valeur = formcleaned[champ]
if valeur != "*":
filtre += u"(%s=%s)" % (champ,valeur)
if filtre != u"":
......@@ -69,20 +86,32 @@ def rechercher(request, ldap, objet):
if item.ldap_name == "adherent" or item.ldap_name == "club":
results += item.machines()
return render(request, "cablage/recherche.html", {
'form': form,
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
'results': results,
})
return render(request, "cablage/recherche.html", {
'form': form,
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
})
else:
return render(request, "cablage/recherche.html", {
'form': form,
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
})
else:
form = SearchForm()
context = {'form': form, 'objet': objet}
machineform = MachineForm()
adherentform = AdherentForm()
clubform = ClubForm()
factureform = FactureForm()
context = {'machineform': machineform, 'adherentform': adherentform, 'clubform': clubform, 'factureform': factureform, 'objet': objet}
return render(request, "cablage/recherche.html", context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment