Commit fe7928a4 authored by Charlie Jacomme's avatar Charlie Jacomme

Merge branch 'cablage'

parents ff026c1a 55e580aa
from django.contrib import admin
# Register your models here.
# -*- coding: utf-8 -*-
from django import forms
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)
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)
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)
from django.db import models
# Create your models here.
.button img {
max-width: 30px;
max-height: 30px;
vertical-align: middle;
margin-left: 10px;
}
{% extends "template.html" %}
{% 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" />
{% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Modifier un objet existant</h2>
<div class="row">
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'adherent' %}">
un adhérent
<img src="/static/img/icone_compte_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'machine' %}">
une machine
<img src="/static/img/machines_icon_fixe_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'facture' %}">
une facture
<img src="/static/img/icone_factures_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'club' %}">
un club
<img src="/static/img/icone_club_white.svg">
</a>
</div>
</div>
<h2>Créer un nouvel objet</h2>
<div class="row">
<div class="three columns">
<a class="button" href="{% url 'compte:create' 'adh'%}">
Nouvel adhérent
<img src="/static/img/icone_compte_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'compte:create' 'club'%}">
Nouveau club
<img src="/static/img/icone_club_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'addmachineadherent' %}">
Machine à un adhérent
<img src="/static/img/icone_compte_white.svg">
<img src="/static/img/machines_icon_fixe_white.svg">
</a>
</div>
<div class="three columns">
<a class="button" href="{% url 'cablage:rechercher' 'addmachineclub' %}">
Machine à un club
<img src="/static/img/icone_club_white.svg">
<img src="/static/img/machines_icon_fixe_white.svg">
</a>
</div>
</div>
{% endblock %}
{% extends "template.html" %}
{% block title %}Rechercher{% endblock %}
{% block h1 %}Rechercher {% if objet == "machine" %}une machine{% elif "adherent" in objet %}un adhérent{% elif "club" in objet %}un club{% elif objet == "facture" %}une facture{% endif %}{% endblock %}
{% load staticfiles %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<table class="mobile-friendly">
<thead>
<tr>
{% if objet == "machine" %}
<th>mid</th>
<th>rid</th>
<th>Host</th>
<th>IP</th>
<th>Mac</th>
<th>Propriétaire</th>
<th>Blacklist</th>
<th>Modifier</th>
{% elif objet == "facture" %}
<th>fid</th>
<th>Article(s)</th>
<th>Mode</th>
<th>Recu le</th>
<th>Controle</th>
<th>Propriétaire</th>
<th>Voir</th>
{% elif "adherent" in objet %}
<th>aid</th>
<th>Nom</th>
<th>Prenom</th>
<th>login</th>
<th>Telephone</th>
<th>Mail</th>
<th>Chambre</th>
<th>Solde</th>
<th>Blacklist</th>
{% if "addmachine" in objet %}
<th>Ajouter une machine</th>
{% else %}
<th>Modifier cet adherent</th>
{% endif %}
{% elif "club" in objet %}
<th>cid</th>
<th>Nom</th>
<th>login</th>
<th>Telephone</th>
<th>Mail</th>
<th>Local</th>
<th>Responsable</th>
<th>Solde</th>
<th>Blacklist</th>
{% if "addmachine" in objet %}
<th>Ajouter une machine</th>
{% else %}
<th>Modifier ce club</th>
{% endif %}
{% endif %}
</tr>
</thead>
<tbody>
{% for result in results %}
<tr>
{% if objet == "machine" %}
<th mobile-header="Mid">{{ result.mid.0 }}</th>
<th mobile-header="Rid">{{ result.rid.0 }}</th>
<th mobile-header="Host">{{ result.host.0 }}</th>
<th mobile-header="IP">{{ result.ipHostNumber.0 }}</th>
<th mobile-header="Mac">{{ result.macAddress.0 }}</th>
<th mobile-header="Proprio">{{ result.proprio }}</th>
<th mobile-header="Blacklist"><span class="bad-thing">{% for bl in result.blacklist_actif%}{{bl}}{%endfor%}</th>
<td mobile-header="Modifier"><a class="button-add" href="{% url 'machines:index' %}{{ result.mid.0 }}">Modifier</a></td>
{% elif objet == "facture" %}
<th mobile-header="Fid">{{ result.fid.0 }}</th>
<th mobile-header="Article(s)">{% for art in result.article%}{{art}}{%endfor%}</th>
<th mobile-header="Mode">{{ result.modePaiement.0 }}</th>
<th mobile-header="Recu">{{ result.recuPaiement.0 }}</th>
<th mobile-header="Controle">{{ result.controle.0 }}</th>
<th mobile-header="Proprio">{{ result.proprio }}</th>
<td mobile-header="Voir"><a class="button-add" href="{% url 'factures:facture' result.fid.0 %}">Voir</a></td>
{% elif "adherent" in objet %}
<th mobile-header="Aid">{{ result.aid.0 }}</th>
<th mobile-header="Nom">{{ result.nom.0 }}</th>
<th mobile-header="Prenom">{{ result.prenom.0 }}</th>
<th mobile-header="Login">{{ result.uid.0 }}</th>
<th mobile-header="Telephone">{{ result.tel.0 }}</th>
<th mobile-header="Mail">{{ result.mail.0 }}</th>
<th mobile-header="Chambre">{{ result.chbre.0 }}</th>
<th mobile-header="Solde">{{ result.solde.0 }}</th>
<th mobile-header="Blacklist"><span class="bad-thing">{% for bl in result.blacklist_actif%}{{bl}}{%endfor%}</th>
{% if "addmachine" in objet %}
<td mobile-header="Ajouter"><a class="button-add" href="{% url 'machines:add' 'fil' 'adh' result.aid.0 %}">Filaire</a> <a class="button-add" href="{% url 'machines:add' 'wifi' 'adh' result.aid.0 %}">Wifi</a></td>
{% else %}
<td mobile-header="Modifier"><a class="button-add" href="{% url 'compte:afficher' result.aid.0 %}">Modifier</a>
{% endif %}
{% elif "club" in objet %}
<th mobile-header="Cid">{{ result.cid.0 }}</th>
<th mobile-header="Nom">{{ result.nom.0 }}</th>
<th mobile-header="Login">{{ result.uid.0 }}</th>
<th mobile-header="Telephone">{{ result.tel.0 }}</th>
<th mobile-header="Mail">{{ result.mail.0 }}</th>
<th mobile-header="Local">{{ result.chbre.0 }}</th>
<th mobile-header="Responsable">{{ result.responsable.0 }}</th>
<th mobile-header="Solde">{{ result.solde.0 }}</th>
<th mobile-header="Blacklist"> <span class="bad-thing">{% for bl in result.blacklist_actif%}{{bl}}{%endfor%}</th>
{% if "addmachine" in objet %}
<td mobile-header="Ajouter"><a class="button-add" href="{% url 'machines:add' 'fil' 'club' result.cid.0 %}">Filaire</a> <a class="button-add" href="{% url 'machines:add' 'wifi' 'club' result.cid.0 %}">Wifi</a></td>
{% else %}
<td mobile-header="Modifier"><a class="button-add" href="{% url 'compte:afficher_club' result.cid.0 %}">Modifier</a>
{% endif %}
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% if "adherent" in objet or "machine" == objet or "facture" == objet %}
<h2>Filtre adhérent</h2>
<div class="row">
<div class="three columns">
{{ adherentform.nom.label_tag }}
{{ adherentform.nom }}
{{ adherentform.nom.errors }}
{{ adherentform.nom.help_text }}
</div>
<div class="three columns">
{{ adherentform.prenom.label_tag }}
{{ adherentform.prenom }}
{{ adherentform.prenom.errors }}
{{ adherentform.prenom.help_text }}
</div>
<div class="three columns">
{{ adherentform.tel.label_tag }}
{{ adherentform.tel }}
{{ adherentform.tel.errors }}
{{ adherentform.tel.help_text }}
</div>
<div class="three columns">
{{ adherentform.mail.label_tag }}
{{ adherentform.mail }}
{{ adherentform.mail.errors }}
{{ adherentform.mail.help_text }}
</div>
</div>
<div class="row">
<div class="three columns">
{{ adherentform.chbre.label_tag }}
{{ adherentform.chbre }}
{{ adherentform.chbre.errors }}
{{ adherentform.chbre.help_text }}
</div>
<div class="three columns">
{{ adherentform.aid.label_tag }}
{{ adherentform.aid }}
{{ adherentform.aid.errors }}
{{ adherentform.aid.help_text }}
</div>
<div class="three columns">
{{ adherentform.uid.label_tag }}
{{ adherentform.uid }}
{{ adherentform.uid.errors }}
{{ adherentform.uid.help_text }}
</div>
</div>
{% endif %}
{% if "club" in objet or "machine" == objet or "facture" == objet %}
<h2>Filtre club</h2>
<div class="row">
<div class="three columns">
{{ clubform.nom.label_tag }}
{{ clubform.nom }}
{{ clubform.nom.errors }}
{{ clubform.nom.help_text }}
</div>
<div class="three columns">
{{ clubform.chbre.label_tag }}
{{ clubform.chbre }}
{{ clubform.chbre.errors }}
{{ clubform.chbre.help_text }}
</div>
<div class="three columns">
{{ clubform.cid.label_tag }}
{{ clubform.cid }}
{{ clubform.cid.errors }}
{{ clubform.cid.help_text }}
</div>
<div class="three columns">
{{ clubform.uid.label_tag }}
{{ clubform.uid }}
{{ clubform.uid.errors }}
{{ clubform.uid.help_text }}
</div>
</div>
{% endif %}
{% if objet != "facture" %}
<h2>Filtre machine</h2>
<div class="row">
<div class="three columns">
{{ machineform.host.label_tag }}
{{ machineform.host }}
{{ machineform.host.errors }}
{{ machineform.host.help_text }}
</div>
<div class="three columns">
{{ machineform.macAddress.label_tag }}
{{ machineform.macAddress }}
{{ machineform.macAddress.errors }}
{{ machineform.macAddress.help_text }}
</div>
<div class="three columns">
{{ machineform.ipHostNumber.label_tag }}
{{ machineform.ipHostNumber }}
{{ machineform.ipHostNumber.errors }}
{{ machineform.ipHostNumber.help_text }}
</div>
<div class="three columns">
{{ machineform.mid.label_tag }}
{{ machineform.mid }}
{{ machineform.mid.errors }}
{{ machineform.mid.help_text }}
</div>
</div>
{% endif %}
{% if objet != "machine" %}
<h2>Filtre facture</h2>
<div class="row">
<div class="three columns">
{{ factureform.fid.label_tag }}
{{ factureform.fid }}
{{ factureform.fid.errors }}
{{ factureform.fid.help_text }}
</div>
</div>
{% endif %}
<footer>
<div class="row">
<div class="six columns">
<input class="button-add" type="submit" value="Rechercher">
<a href="{% url 'cablage:afficher' %}" class="button-cancel">Retour</a>
</div>
</div>
</footer>
{% endblock %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import patterns as patterns
from django.conf.urls import url
import views
urlpatterns = [
url('^$', views.afficher, name='afficher'),
url('rechercher/(?P<objet>[^/]*)?/?$', views.rechercher, name="rechercher"),
]
# -*- coding: utf-8 -*-
# Application de cablage sur l'intranet
# Gabriel Détraz detraz@crans.org
from django.shortcuts import render
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from intranet import conn_pool
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from intranet.settings import BASE_LDAP_TEST
import lc_ldap.shortcuts
from forms import MachineForm, AdherentForm, ClubForm, FactureForm
if BASE_LDAP_TEST:
use_ldap_admin = lc_ldap.shortcuts.with_ldap_conn(retries=2, delay=5,
constructor=lc_ldap.shortcuts.lc_ldap_test)
else:
use_ldap_admin = lc_ldap.shortcuts.with_ldap_conn(retries=2, delay=5,
constructor=lc_ldap.shortcuts.lc_ldap_admin)
@login_required
def afficher(request):
""" Accueil de l'interface de cablage """
if not request.user.has_perm('auth.crans_cableur'):
messages.error(request, u""" Accès interdit, droits insuffisants """ )
return HttpResponseRedirect("/")
return render(request, "cablage/affichage.html")
@use_ldap_admin
@login_required
def rechercher(request, ldap, objet):
""" Interface de recherche d'un objet ldap """
if not request.user.has_perm('auth.crans_cableur'):
messages.error(request, u""" Accès interdit, droits insuffisants """ )
return HttpResponseRedirect("/")
if request.method == "POST":
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 formchanged:
valeur = formcleaned[champ]
if valeur != "*":
filtre += u"(%s=%s)" % (champ,valeur)
if filtre != u"":
donnees = ldap.search(u'(&%s)' % filtre)
# Tri des objets suivant ce qu'on veut à l'arrivée
results = []
for item in donnees:
if objet in item.ldap_name or item.ldap_name in objet:
results.append(item)
else:
# Si on cherche un adh à partir de ses machines ou factures
# Note : objet peut etre addmachineadh , donc on ratisse large
if 'adherent' in objet or 'club' in objet:
if "machine" in item.ldap_name or item.ldap_name == "facture":
if item.proprio().ldap_name == objet:
results.append(item.proprio())
elif objet == 'facture':
if item.ldap_name == "adherent" or item.ldap_name == "club":
results += item.factures()
elif objet == 'machine':
if item.ldap_name == "adherent" or item.ldap_name == "club":
results += item.machines()
return render(request, "cablage/recherche.html", {
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
'results': results,
})
return render(request, "cablage/recherche.html", {
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
})
else:
return render(request, "cablage/recherche.html", {
'adherentform': adherentform,
'machineform': machineform,
'factureform': factureform,
'clubform': clubform,
'objet': objet,
})
else:
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)
# -*- coding: utf-8 -*-
# Application de cablage par l'intranet
# Gabriel Détraz detraz@crans.org
from django.shortcuts import render
from django.template import RequestContext
def is_cableur(request):
"""Renvoie True si l'utilisateur connecté a les droits"""
luser = conn_pool.get_user(request.user)
li = False
if "Cableur" in luser['droits'] or "Nounou" in luser['droits']:
li = True
return li
def afficher(request):
if not is_cableur(request):
messages.error(request, u""" Accès interdit, droits insuffisants """ )
return HttpResponseRedirect("/")
......@@ -32,3 +32,19 @@ class ImprimeurAddForm(forms.Form):
login = new_imprimeur.lower().strip(' ')
return login
class ResponsableEditForm(forms.Form):
new_responsable = forms.CharField(
required=True,
label='Modifier le responsable',
help_text=('Entrer le login crans de la personne.\n'
'Usuellement le nom (sans accents) '
'ou la première lettre du prénom suivi du nom'
)
)
def clean_new_responsable(self):
"""Passe le login du responsable en minuscule et retire les espaces"""
# Apparement cette méthode est appelé par Django au moment du clean
new_responsable = self.cleaned_data['new_responsable']
login = new_responsable.lower().strip(' ')
return login
......@@ -11,7 +11,8 @@
<footer>
<div class="row">
<div class="six columns">
<a href="{% url 'club:index' %}" class="button-cancel">Retour à la liste des clubs</a>
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour</a>
<input class="button-add" type="submit" value="Ajouter cet imprimeur">
</div>
</div>
......
......@@ -11,7 +11,8 @@
<footer>
<div class="row">
<div class="six columns">
<a href="{% url 'club:index' %}" class="button-cancel">Retour à la liste des clubs</a>
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour</a>
<input class="button-del" type="submit" value="Retirer ces imprimeurs">
</div>
</div>
......
......@@ -3,7 +3,9 @@
{% block h1 %} Gestion des comptes {% endblock %}
{% block content %}
<div class="row">
{% for club in clubs %}
<div class="six columns">
<h2>{{ club.club_name }}</h2>
Liste des imprimeurs:
<ul>
......@@ -13,12 +15,38 @@
<span class="bad-thing">Vous n'avez actuellement aucun imprimeurs pour ce club !</span>
{% endfor %}
</ul>
<a href="{% url 'club:imprimeur_add' cid=club.cid %}"><button class="button-add">Ajouter un imprimeur</button></a>
Responsable : {{club.responsable}}
<footer>