mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Ajout de la fonction de recherche
This commit is contained in:
parent
e164918b9d
commit
279b754ce4
38 changed files with 258 additions and 0 deletions
BIN
logs/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
logs/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
logs/__pycache__/admin.cpython-34.pyc
Normal file
BIN
logs/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
logs/__pycache__/models.cpython-34.pyc
Normal file
BIN
logs/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
logs/__pycache__/views.cpython-34.pyc
Normal file
BIN
logs/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
BIN
logs/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
logs/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
0
machines/__init__.py
Normal file
0
machines/__init__.py
Normal file
BIN
machines/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
machines/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
machines/__pycache__/admin.cpython-34.pyc
Normal file
BIN
machines/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
machines/__pycache__/models.cpython-34.pyc
Normal file
BIN
machines/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
12
machines/admin.py
Normal file
12
machines/admin.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Machine, MachineType
|
||||
|
||||
class MachineAdmin(admin.ModelAdmin):
|
||||
list_display = ('user','type')
|
||||
|
||||
class MachineTypeAdmin(admin.ModelAdmin):
|
||||
list_display = ('type',)
|
||||
|
||||
admin.site.register(Machine, MachineAdmin)
|
||||
admin.site.register(MachineType, MachineTypeAdmin)
|
38
machines/migrations/0001_initial.py
Normal file
38
machines/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0005_auto_20160702_0006'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Machine',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MachineType',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('type', models.CharField(max_length=255)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='machine',
|
||||
name='type',
|
||||
field=models.ForeignKey(to='machines.MachineType', on_delete=django.db.models.deletion.PROTECT),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='machine',
|
||||
name='user',
|
||||
field=models.ForeignKey(to='users.User', on_delete=django.db.models.deletion.PROTECT),
|
||||
),
|
||||
]
|
0
machines/migrations/__init__.py
Normal file
0
machines/migrations/__init__.py
Normal file
BIN
machines/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
BIN
machines/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
Binary file not shown.
BIN
machines/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
machines/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
16
machines/models.py
Normal file
16
machines/models.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.db import models
|
||||
|
||||
from users.models import User
|
||||
|
||||
class Machine(models.Model):
|
||||
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
|
||||
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
|
||||
|
||||
def __str__(self):
|
||||
return self.type
|
||||
|
||||
class MachineType(models.Model):
|
||||
type = models.CharField(max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return self.type
|
3
machines/tests.py
Normal file
3
machines/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
machines/views.py
Normal file
3
machines/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
BIN
re2o/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
re2o/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
re2o/__pycache__/login.cpython-34.pyc
Normal file
BIN
re2o/__pycache__/login.cpython-34.pyc
Normal file
Binary file not shown.
BIN
re2o/__pycache__/urls.cpython-34.pyc
Normal file
BIN
re2o/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
re2o/__pycache__/wsgi.cpython-34.pyc
Normal file
BIN
re2o/__pycache__/wsgi.cpython-34.pyc
Normal file
Binary file not shown.
0
search/__init__.py
Normal file
0
search/__init__.py
Normal file
BIN
search/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
search/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
search/__pycache__/admin.cpython-34.pyc
Normal file
BIN
search/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
search/__pycache__/models.cpython-34.pyc
Normal file
BIN
search/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
search/__pycache__/urls.cpython-34.pyc
Normal file
BIN
search/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
search/__pycache__/views.cpython-34.pyc
Normal file
BIN
search/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
3
search/admin.py
Normal file
3
search/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
16
search/forms.py
Normal file
16
search/forms.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.db.models import Q
|
||||
from simple_search import BaseSearchForm
|
||||
|
||||
from users.models import User, School
|
||||
|
||||
class UserSearchForm(BaseSearchForm):
|
||||
class Meta:
|
||||
base_qs = User.objects
|
||||
search_fields = ('^name', 'description', 'specifications', '=id')
|
||||
|
||||
# assumes a fulltext index has been defined on the fields
|
||||
# 'name,description,specifications,id'
|
||||
fulltext_indexes = (
|
||||
('name', 2), # name matches are weighted higher
|
||||
('name,description,specifications,id', 1),
|
||||
)
|
0
search/migrations/__init__.py
Normal file
0
search/migrations/__init__.py
Normal file
BIN
search/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
search/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
10
search/models.py
Normal file
10
search/models.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
from django import forms
|
||||
from django.forms import Form
|
||||
from django.forms import ModelForm
|
||||
|
||||
from users.models import User
|
||||
# Create your models here.
|
||||
|
||||
class SearchForm(Form):
|
||||
search_field = forms.CharField(label = 'Search', max_length = 100)
|
90
search/templates/search/index.html
Normal file
90
search/templates/search/index.html
Normal file
|
@ -0,0 +1,90 @@
|
|||
{% extends "users/sidebar.html" %}
|
||||
{% load bootstrap3 %}
|
||||
|
||||
{% block title %}Utilisateurs{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if users_list %}
|
||||
<h2>Résultats dans les utilisateurs</h2>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Prénom</th>
|
||||
<th>Nom</th>
|
||||
<th>Pseudo</th>
|
||||
<th>Modifier</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for user in users_list %}
|
||||
<tr>
|
||||
<td>{{ user.name }}</td>
|
||||
<td>{{ user.surname }}</td>
|
||||
<td>{{ user.pseudo }}</td>
|
||||
<td><a href="{% url 'users:edit-info' user.id %}">Editer</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif%}
|
||||
{% if machine_list %}
|
||||
<h2>Résultats dans les machines : </h2>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for machine in machine_list %}
|
||||
<tr>
|
||||
<td>{{ machine.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if facture_list %}
|
||||
<h2>Résultats dans les factures : </h2>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Utilisateur</th>
|
||||
<th>Designation</th>
|
||||
<th>Nombre</th>
|
||||
<th>Prix unitaire</th>
|
||||
<th>Moyen de paiement</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for facture in facture_list %}
|
||||
<tr>
|
||||
<td>{{ facture.user }}</td>
|
||||
<td>{{ facture.name }}</td>
|
||||
<td>{{ facture.number }}</td>
|
||||
<td>{{ facture.prix }}</td>
|
||||
<td>{{ facture.paiement }}</td>
|
||||
<td>{{ facture.date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if ban_list %}
|
||||
<h2>Résultats dans les banissements : </h2>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Utilisateur</th>
|
||||
<th>Raison</th>
|
||||
<th>Date de début</th>
|
||||
<th>Date de fin</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for ban in ban_list %}
|
||||
<tr>
|
||||
<td>{{ ban.user }}</td>
|
||||
<td>{{ ban.raison }}</td>
|
||||
<td>{{ ban.date_start }}</td>
|
||||
<td>{{ ban.date_end }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
14
search/templates/search/search.html
Normal file
14
search/templates/search/search.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "search/sidebar.html" %}
|
||||
{% load bootstrap3 %}
|
||||
|
||||
{% block title %}Création et modification d'utilisateur{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% bootstrap_form_errors searchform %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form searchform %}
|
||||
{% bootstrap_button "Search" button_type="submit" icon="search" %}
|
||||
</form>
|
||||
{% endblock %}
|
9
search/templates/search/sidebar.html
Normal file
9
search/templates/search/sidebar.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block sidebar %}
|
||||
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
|
||||
<p><a href="{% url "search:search" %}">Editer un adhérent</a></p>
|
||||
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
|
||||
<p><a href="{% url "users:add-right" %}">Ajouter un droit rezo</a></p>
|
||||
<p><a href="{% url "users:del-right" %}">Retirer un droit rezo</a></p>
|
||||
{% endblock %}
|
3
search/tests.py
Normal file
3
search/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
7
search/urls.py
Normal file
7
search/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.search, name='search'),
|
||||
]
|
34
search/views.py
Normal file
34
search/views.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# App de recherche pour re2o
|
||||
# Gabriel Détraz, Goulven Kermarec
|
||||
# Gplv2
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.core.context_processors import csrf
|
||||
from django.template import Context, RequestContext, loader
|
||||
|
||||
from django.db.models import Q
|
||||
from users.models import User, Ban
|
||||
from machines.models import Machine
|
||||
from cotisations.models import Facture
|
||||
from search.models import SearchForm
|
||||
|
||||
def form(ctx, template, request):
|
||||
c = ctx
|
||||
c.update(csrf(request))
|
||||
return render_to_response(template, c, context_instance=RequestContext(request))
|
||||
|
||||
def search(request):
|
||||
if request.method == 'POST':
|
||||
search = SearchForm(request.POST or None)
|
||||
if search.is_valid():
|
||||
search = search.cleaned_data['search_field']
|
||||
users = User.objects.filter(Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search))
|
||||
machines = None
|
||||
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
||||
factures = Facture.objects.filter(query)
|
||||
bans = Ban.objects.filter(query)
|
||||
return form({'users_list': users, 'machine_list' : machines, 'facture_list' : factures, 'ban_list' : bans}, 'search/index.html',request)
|
||||
return form({'searchform' : search}, 'search/search.html', request)
|
||||
else:
|
||||
search = SearchForm(request.POST or None)
|
||||
return form({'searchform': search}, 'search/search.html',request)
|
Loading…
Reference in a new issue