Commit 33d70ddf authored by Gabriel Detraz's avatar Gabriel Detraz

Ajoute menu de recherche

parent faa28ced
......@@ -3,22 +3,14 @@ from users.models import Right
def context_user(request):
user = request.user
is_cableur = user.has_perms(('cableur',))
is_bureau = user.has_perms(('bureau',))
is_bofh = user.has_perms(('bofh',))
is_trez = user.has_perms(('trésorier',))
is_infra = user.has_perms(('infra',))
if user.is_authenticated():
list_droits = Right.objects.filter(user=user)
else:
list_droits = None
return {
'request_user': user,
'is_cableur': is_cableur,
'is_bureau': is_bureau,
'is_bofh': is_bofh,
'is_trez': is_trez,
'is_infra': is_infra,
'list_droits': list_droits,
'site_name': SITE_NAME,
}
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, MINIMUM_LEVEL, SITE_NAME
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, MINIMUM_LEVEL, EMAIL_HOST, SITE_NAME
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......@@ -42,6 +42,7 @@ INSTALLED_APPS = (
'users',
'panier',
'amap',
'search',
'reversion'
)
......@@ -119,8 +120,6 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
RIGHTS_LINK = {
'cableur' : ['bureau','infra','bofh','trésorier'],
'bofh' : ['bureau','trésorier'],
}
PAGINATION_NUMBER = 25
......
......@@ -25,5 +25,5 @@ urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include('users.urls', namespace='users')),
url(r'^panier/', include('panier.urls', namespace='panier')),
#url(r'^logs/', include('logs.urls', namespace='logs')),
url(r'^search/', include('search.urls', namespace='search')),
]
{% if management_view %}
<h2>Tableau de bord</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Solde total des comptes</th>
<th>Nombres de comptes actifs</th>
<th>Dont ENS</th>
<th>Solde moyen</th>
<th>Nombre de commandes</th>
<th>Prochaine livraison</th>
</tr>
</thead>
<tr>
<td>{{ solde_total }}</td>
<td>{{ user_total }}</td>
<td>{{ user_ens }}</td>
<td>{{ solde_moyen }}</td>
<td>{{ commandes_total }}</td>
<td>{{ next_livraison.date }}</td>
</tr>
</table>
{% endif %}
<h2>Commandes</h2>
{% if paniers_list.paginator %}
......
......@@ -47,17 +47,17 @@ def new_commande(request, userid):
article_form = SelectArticleForm(request.POST or None)
if commande_form.is_valid() and article_form.is_valid():
commande = commande_form.save(commit=False)
prix_unitaire = article_form.cleaned_data['article'].prix
quantite = commande.quantite
if timezone.now() > commande.date.date_modif and not request.user.has_perms(('bureau',)):
messages.error(request, "Vous ne pouvez plus passer commande, livraison proche")
return redirect("/users/profil/" + str(request.user.id))
if user.solde() - commande.prix() < MINIMUM_LEVEL:
messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/users/profil/" + userid)
commande.prix_unitaire = article_form.cleaned_data['article'].prix
commande.nom = article_form.cleaned_data['article'].nom
# Si non surdroits, check solde et date
if not request.user.has_perms(('bureau',)):
if timezone.now() > commande.date.date_modif:
messages.error(request, "Vous ne pouvez plus passer commande, livraison proche")
return redirect("/users/profil/" + str(request.user.id))
if user.solde() - commande.prix() < MINIMUM_LEVEL:
messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/users/profil/" + userid)
with transaction.atomic(), reversion.create_revision():
commande.prix_unitaire = article_form.cleaned_data['article'].prix
commande.nom = article_form.cleaned_data['article'].nom
commande.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
......@@ -84,14 +84,14 @@ def edit_commande(request, commandeid):
commande = BaseEditCommandeForm(request.POST or None, instance=commande_instance)
if commande.is_valid():
new_commande = commande.save(commit=False)
if commande_instance.user.solde() - new_commande.prix() < MINIMUM_LEVEL:
if commande_instance.user.solde() - new_commande.prix() < MINIMUM_LEVEL and not request.user.has_perms(('bureau',)):
messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/panier/")
with transaction.atomic(), reversion.create_revision():
commande.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in commande.changed_data))
messages.success(request, "Commande modifiee")
messages.success(request, "Commande modifiée")
return redirect("/panier/")
return form({'panierform': commande}, 'panier/panier.html', request)
......@@ -358,7 +358,7 @@ def history(request, object, id):
except Panier.DoesNotExist:
messages.error(request, "Paiement inexistant")
return redirect("/panier/")
elif object == 'livraison' and request.user.has_perms(('cableur',)):
elif object == 'livraison' and request.user.has_perms(('bureau',)):
try:
object_instance = Livraison.objects.get(pk=id)
except Livraison.DoesNotExist:
......@@ -408,7 +408,14 @@ def index(request):
# If page is out of range (e.g. 9999), deliver last page of results.
credit_list = paginator_credit.page(paginator_credit.num_pages)
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list})
management_view = request.user.has_perms(('bureau',))
solde_total = sum(us.solde() for us in User.objects.all())
user_total = len(User.objects.filter(state=0))
user_ens = len(User.objects.filter(state=0).filter(is_ens=True))
solde_moyen = solde_total/user_total
commandes_total = len(Commande.objects.all())
next_livraison = Livraison.objects.order_by('date').filter(date__gt=timezone.now())[0]
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'management_view': management_view, 'credit_list': credit_list, 'solde_total': solde_total, 'user_total': user_total, 'user_ens': user_ens, 'solde_moyen': solde_moyen, 'commandes_total': commandes_total, 'next_livraison': next_livraison})
@login_required
def index_article(request):
......
from django.db.models import Q
from simple_search import BaseSearchForm
from users.models import User, School
from users.models import User
class UserSearchForm(BaseSearchForm):
class Meta:
......
......@@ -16,12 +16,10 @@ CHOICES2 = (
CHOICES3 = (
('0', 'Utilisateurs'),
('1', 'Machines'),
('2', 'Factures'),
('3', 'Bannissements'),
('4', 'Accès à titre gracieux'),
('6', 'Switchs'),
('5', 'Ports'),
('1', 'Paniers'),
('2', 'Commandes'),
('3', 'Livraisons'),
('4', 'Crédits'),
)
......@@ -31,7 +29,6 @@ class SearchForm(Form):
class SearchFormPlus(Form):
search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
filtre = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
connexion = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES2)
affichage = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES3)
date_deb = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'])
date_fin = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
......@@ -8,31 +8,16 @@
<h2>Résultats dans les utilisateurs</h2>
{% include "users/aff_users.html" with users_list=users_list %}
{% endif%}
{% if interfaces_list %}
<h2>Résultats dans les machines : </h2>
{% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
{% if paniers_list %}
<h2>Résultats dans les paniers en vente : </h2>
{% include "panier/aff_article.html" with article_list=paniers_list %}
{% endif %}
{% if facture_list %}
<h2>Résultats dans les factures : </h2>
{% include "cotisations/aff_cotisations.html" with facture_list=facture_list %}
{% if livraison_list %}
<h2>Résultats dans les livraisons : </h2>
{% include "panier/aff_livraison.html" with livraison_list=livraison_list %}
{% endif %}
{% if white_list %}
<h2>Résultats dans les accès à titre gracieux : </h2>
{% include "users/aff_whitelists.html" with white_list=white_list %}
{% endif %}
{% if ban_list %}
<h2>Résultats dans les banissements : </h2>
{% include "users/aff_bans.html" with ban_list=ban_list %}
{% endif %}
{% if switch_list %}
<h2>Résultats dans les switchs : </h2>
{% include "topologie/aff_switch.html" with switch_list=switch_list %}
{% endif %}
{% if port_list %}
<h2>Résultats dans les ports : </h2>
{% include "topologie/aff_port.html" with port_list=port_list %}
{% endif %}
{% if not ban_list and not interfaces_list and not users_list and not facture_list and not white_list and not port_list and not switch_list%}
{% if not users_list and not paniers_list and not livraison_list %}
<h3>Aucun résultat</h3>
{% endif %}
<br />
......
......@@ -8,11 +8,10 @@ from django.template import Context, RequestContext, loader
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from users.models import User, Ban, Whitelist
from machines.models import Machine, Interface
from topologie.models import Port, Switch
from cotisations.models import Facture
from users.models import User
from search.models import SearchForm, SearchFormPlus
from panier.models import Commande, Panier, Credit, Livraison
def form(ctx, template, request):
c = ctx
......@@ -27,7 +26,6 @@ def search_result(search, type, request):
aff=[]
if(type):
aff = search.cleaned_data['affichage']
co = search.cleaned_data['connexion']
states = search.cleaned_data['filtre']
date_deb = search.cleaned_data['date_deb']
date_fin = search.cleaned_data['date_fin']
......@@ -44,31 +42,24 @@ def search_result(search, type, request):
query = query | Q(state = s)
users = None
machines = None
factures = None
bans = None
whitelists = None
switchlist = None
portlist = None
connexion = []
commande = None
panier = None
credit = None
livraison = None
for i in aff:
if i == '0':
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
if i == '1':
machines = Interface.objects.filter(machine=Machine.objects.filter(query)) | Interface.objects.filter(Q(dns__icontains = search))
panier = Panier.objects.filter(nom__icontains = search)
if i == '2':
factures = Facture.objects.filter(query & date_query)
commande = Commande.objects.filter(query & date_query)
if i == '3':
bans = Ban.objects.filter(query)
livraison = Livraison.objects.filter(date_query)
if i == '4':
whitelists = Whitelist.objects.filter(query)
if i == '5':
portlist = Port.objects.filter(details__icontains = search)
if i == '6':
switchlist = Switch.objects.filter(details__icontains = search)
return {'users_list': users, 'interfaces_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist}
credit = Credit.objects.filter(query)
return {'users_list': users, 'paniers_list' : panier, 'commandes_list' : commande, 'livraison_list' : livraison, 'credit_list' : credit}
@login_required
def search(request):
......
......@@ -31,17 +31,19 @@
<ul class="nav navbar-nav">
<li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
<li><a href="{% url "panier:index" %}">Les commandes</a></li>
{% if is_cableur %}
{% if is_bureau %}
<li><a href="{% url "users:index" %}">Gérer les utilisateurs</a></li>
{% endif %}
</ul>
<div class="col-sm-3 col-md-3 navbar-right">
<form action="{% url "search:search"%}" method="POST" class="navbar-form" role="search">
{% csrf_token %}
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="glyphicon glyphicon-plus"></i></a>
</div>
</div>
</form>
</div>
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0004_user_is_ens'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, unique=True),
),
]
......@@ -76,7 +76,7 @@ class User(AbstractBaseUser):
name = models.CharField(max_length=255)
surname = models.CharField(max_length=255)
pseudo = models.CharField(max_length=32, unique=True, help_text="Doit contenir uniquement des lettres, chiffres, ou tirets. ")
email = models.EmailField()
email = models.EmailField(unique=True)
telephone = models.CharField(max_length=15)
comment = models.CharField(help_text="Commentaire, promo", max_length=255, blank=True)
is_ens = models.BooleanField(default=True)
......
Bonjour {{ name }},
Vous trouverez ci-dessous une url permetant d'initialiser ou de reinitialiser votre
compte {{ site_name }}. Celui-ci vous permet de gérer l'ensemble de vos équipements
connectés, votre compte, vos factures, et tous les services proposés sur le réseau.
compte {{ site_name }}.
{{ url }}
......
{% extends "base.html" %}
{% block sidebar %}
{% if is_cableur %}
{% if is_bureau %}
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
<p><a href="{% url "users:index-listright" %}">Liste des droits</a></p>
{% if is_bureau %}
<p><a href="{% url "users:del-right" %}">Retirer un droit</a></p>
{% endif %}
{% endif %}
{% endblock %}
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