Commit 279b754c authored by Dalahro's avatar Dalahro

Ajout de la fonction de recherche

parent e164918b
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)
# -*- 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),
),
]
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
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
# Register your models here.
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),
)
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)
{% 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 %}
{% 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 %}
{% 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 %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.search, name='search'),
]
# 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)
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