mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
pep8 et pylint
This commit is contained in:
parent
439b0fb30c
commit
9a292d38d8
4 changed files with 42 additions and 44 deletions
|
@ -21,8 +21,8 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
"""The field used in the admin view for the search app"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
"""The forms used by the search app"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -44,14 +46,18 @@ CHOICES_AFF = (
|
||||||
|
|
||||||
|
|
||||||
def initial_choices(c):
|
def initial_choices(c):
|
||||||
|
"""Return the choices that should be activated by default for a
|
||||||
|
given set of choices"""
|
||||||
return [i[0] for i in c]
|
return [i[0] for i in c]
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(Form):
|
class SearchForm(Form):
|
||||||
|
"""The form for a simple search"""
|
||||||
q = forms.CharField(label='Search', max_length=100)
|
q = forms.CharField(label='Search', max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class SearchFormPlus(Form):
|
class SearchFormPlus(Form):
|
||||||
|
"""The form for an advanced search (with filters)"""
|
||||||
q = forms.CharField(
|
q = forms.CharField(
|
||||||
label='Search',
|
label='Search',
|
||||||
max_length=100,
|
max_length=100,
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
"""The urls used by the search app"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
|
@ -20,21 +20,19 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
# App de recherche pour re2o
|
"""The views for the search app, responsible for finding the matches
|
||||||
# Augustin lemesle, Gabriel Détraz, Goulven Kermarec
|
Augustin lemesle, Gabriel Détraz, Goulven Kermarec, Maël Kervella
|
||||||
# Gplv2
|
Gplv2"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.template.context_processors import csrf
|
|
||||||
from django.template import Context, RequestContext, loader
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from users.models import User, Ban, Whitelist
|
from users.models import User, Ban, Whitelist
|
||||||
from machines.models import Machine, Interface
|
from machines.models import Machine
|
||||||
from topologie.models import Port, Switch, Room
|
from topologie.models import Port, Switch, Room
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from preferences.models import GeneralOption
|
from preferences.models import GeneralOption
|
||||||
|
@ -72,36 +70,24 @@ def get_results(query, request, filters={}):
|
||||||
user_state = filters.get('u', initial_choices(CHOICES_USER))
|
user_state = filters.get('u', initial_choices(CHOICES_USER))
|
||||||
aff = filters.get('a', initial_choices(CHOICES_AFF))
|
aff = filters.get('a', initial_choices(CHOICES_AFF))
|
||||||
|
|
||||||
options, created = GeneralOption.objects.get_or_create()
|
options, _ = GeneralOption.objects.get_or_create()
|
||||||
max_result = options.search_display_page
|
max_result = options.search_display_page
|
||||||
|
|
||||||
user_state_filter = Q()
|
user_state_filter = Q()
|
||||||
for s in user_state:
|
for state in user_state:
|
||||||
user_state_filter |= Q(state = s)
|
user_state_filter |= Q(state=state)
|
||||||
|
|
||||||
connexion = []
|
|
||||||
|
|
||||||
results = {
|
results = {
|
||||||
'users_list': User.objects.none(),
|
'users_list': User.objects.none(),
|
||||||
'machines_list' : Machine.objects.none(),
|
'machines_list': Machine.objects.none(),
|
||||||
'factures_list' : Facture.objects.none(),
|
'factures_list': Facture.objects.none(),
|
||||||
'bans_list' : Ban.objects.none(),
|
'bans_list': Ban.objects.none(),
|
||||||
'whitelists_list': Whitelist.objects.none(),
|
'whitelists_list': Whitelist.objects.none(),
|
||||||
'rooms_list': Room.objects.none(),
|
'rooms_list': Room.objects.none(),
|
||||||
'switch_ports_list': Port.objects.none(),
|
'switch_ports_list': Port.objects.none(),
|
||||||
'switches_list': Switch.objects.none()
|
'switches_list': Switch.objects.none()
|
||||||
}
|
}
|
||||||
|
|
||||||
users_filter = Q(
|
|
||||||
user__pseudo__icontains=query
|
|
||||||
) | Q(
|
|
||||||
user__adherent__name__icontains=query
|
|
||||||
) | Q(
|
|
||||||
user__surname__icontains=query
|
|
||||||
)
|
|
||||||
if not request.user.has_perms(('cableur',)):
|
|
||||||
users_filter &= Q(user=request.user)
|
|
||||||
|
|
||||||
# Users
|
# Users
|
||||||
if '0' in aff:
|
if '0' in aff:
|
||||||
filter_user_list = Q(
|
filter_user_list = Q(
|
||||||
|
@ -155,9 +141,9 @@ def get_results(query, request, filters={}):
|
||||||
filter_facture_list = Q(
|
filter_facture_list = Q(
|
||||||
user__pseudo__icontains=query
|
user__pseudo__icontains=query
|
||||||
)
|
)
|
||||||
if start != None:
|
if start is not None:
|
||||||
filter_facture_list &= Q(date__gte=start)
|
filter_facture_list &= Q(date__gte=start)
|
||||||
if end != None:
|
if end is not None:
|
||||||
filter_facture_list &= Q(date__lte=end)
|
filter_facture_list &= Q(date__lte=end)
|
||||||
results['factures_list'] = Facture.objects.filter(filter_facture_list)
|
results['factures_list'] = Facture.objects.filter(filter_facture_list)
|
||||||
results['factures_list'] = SortTable.sort(
|
results['factures_list'] = SortTable.sort(
|
||||||
|
@ -174,7 +160,7 @@ def get_results(query, request, filters={}):
|
||||||
) | Q(
|
) | Q(
|
||||||
raison__icontains=query
|
raison__icontains=query
|
||||||
)
|
)
|
||||||
if start != None:
|
if start is not None:
|
||||||
date_filter &= (
|
date_filter &= (
|
||||||
Q(date_start__gte=start) & Q(date_end__gte=start)
|
Q(date_start__gte=start) & Q(date_end__gte=start)
|
||||||
) | (
|
) | (
|
||||||
|
@ -182,7 +168,7 @@ def get_results(query, request, filters={}):
|
||||||
) | (
|
) | (
|
||||||
Q(date_start__gte=start) & Q(date_end__lte=start)
|
Q(date_start__gte=start) & Q(date_end__lte=start)
|
||||||
)
|
)
|
||||||
if end != None:
|
if end is not None:
|
||||||
date_filter &= (
|
date_filter &= (
|
||||||
Q(date_start__lte=end) & Q(date_end__lte=end)
|
Q(date_start__lte=end) & Q(date_end__lte=end)
|
||||||
) | (
|
) | (
|
||||||
|
@ -205,7 +191,7 @@ def get_results(query, request, filters={}):
|
||||||
) | Q(
|
) | Q(
|
||||||
raison__icontains=query
|
raison__icontains=query
|
||||||
)
|
)
|
||||||
if start != None:
|
if start is not None:
|
||||||
date_filter &= (
|
date_filter &= (
|
||||||
Q(date_start__gte=start) & Q(date_end__gte=start)
|
Q(date_start__gte=start) & Q(date_end__gte=start)
|
||||||
) | (
|
) | (
|
||||||
|
@ -213,7 +199,7 @@ def get_results(query, request, filters={}):
|
||||||
) | (
|
) | (
|
||||||
Q(date_start__gte=start) & Q(date_end__lte=start)
|
Q(date_start__gte=start) & Q(date_end__lte=start)
|
||||||
)
|
)
|
||||||
if end != None:
|
if end is not None:
|
||||||
date_filter &= (
|
date_filter &= (
|
||||||
Q(date_start__lte=end) & Q(date_end__lte=end)
|
Q(date_start__lte=end) & Q(date_end__lte=end)
|
||||||
) | (
|
) | (
|
||||||
|
@ -248,7 +234,7 @@ def get_results(query, request, filters={}):
|
||||||
|
|
||||||
# Switch ports
|
# Switch ports
|
||||||
if '6' in aff and request.user.has_perms(('cableur',)):
|
if '6' in aff and request.user.has_perms(('cableur',)):
|
||||||
filter_switch_ports_list = Q(
|
filter_ports_list = Q(
|
||||||
room__name__icontains=query
|
room__name__icontains=query
|
||||||
) | Q(
|
) | Q(
|
||||||
machine_interface__domain__name__icontains=query
|
machine_interface__domain__name__icontains=query
|
||||||
|
@ -262,10 +248,10 @@ def get_results(query, request, filters={}):
|
||||||
details__icontains=query
|
details__icontains=query
|
||||||
)
|
)
|
||||||
if is_int(query):
|
if is_int(query):
|
||||||
filter_switch_ports_list |= Q(
|
filter_ports_list |= Q(
|
||||||
port=query
|
port=query
|
||||||
)
|
)
|
||||||
results['switch_ports_list'] = Port.objects.filter(filter_switch_ports_list)
|
results['switch_ports_list'] = Port.objects.filter(filter_ports_list)
|
||||||
results['switch_ports_list'] = SortTable.sort(
|
results['switch_ports_list'] = SortTable.sort(
|
||||||
results['switch_ports_list'],
|
results['switch_ports_list'],
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -275,7 +261,7 @@ def get_results(query, request, filters={}):
|
||||||
|
|
||||||
# Switches
|
# Switches
|
||||||
if '7' in aff and request.user.has_perms(('cableur',)):
|
if '7' in aff and request.user.has_perms(('cableur',)):
|
||||||
filter_switches = Q(
|
filter_switches_list = Q(
|
||||||
switch_interface__domain__name__icontains=query
|
switch_interface__domain__name__icontains=query
|
||||||
) | Q(
|
) | Q(
|
||||||
switch_interface__ipv4__ipv4__icontains=query
|
switch_interface__ipv4__ipv4__icontains=query
|
||||||
|
@ -291,12 +277,12 @@ def get_results(query, request, filters={}):
|
||||||
details__icontains=query
|
details__icontains=query
|
||||||
)
|
)
|
||||||
if is_int(query):
|
if is_int(query):
|
||||||
filter_switch_ports_list |= Q(
|
filter_switches_list |= Q(
|
||||||
number=query
|
number=query
|
||||||
) | Q(
|
) | Q(
|
||||||
stack_member_id=query
|
stack_member_id=query
|
||||||
)
|
)
|
||||||
results['switches_list'] = Switch.objects.filter(filter_switches)
|
results['switches_list'] = Switch.objects.filter(filter_switches_list)
|
||||||
results['switches_list'] = SortTable.sort(
|
results['switches_list'] = SortTable.sort(
|
||||||
results['switches_list'],
|
results['switches_list'],
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -304,16 +290,18 @@ def get_results(query, request, filters={}):
|
||||||
SortTable.TOPOLOGIE_INDEX
|
SortTable.TOPOLOGIE_INDEX
|
||||||
)
|
)
|
||||||
|
|
||||||
for r in results.keys():
|
for name, val in results.items():
|
||||||
results[r] = results[r].distinct()[:max_result]
|
results[name] = val.distinct()[:max_result]
|
||||||
|
|
||||||
results.update({'max_result': max_result})
|
results.update({'max_result': max_result})
|
||||||
results.update({'search_term': query})
|
results.update({'search_term': query})
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search(request):
|
def search(request):
|
||||||
|
""" La page de recherche standard """
|
||||||
search_form = SearchForm(request.GET or None)
|
search_form = SearchForm(request.GET or None)
|
||||||
if search_form.is_valid():
|
if search_form.is_valid():
|
||||||
return render(
|
return render(
|
||||||
|
@ -325,10 +313,12 @@ def search(request):
|
||||||
search_form.cleaned_data
|
search_form.cleaned_data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return render(request, 'search/search.html', {'search_form' : search_form})
|
return render(request, 'search/search.html', {'search_form': search_form})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def searchp(request):
|
def searchp(request):
|
||||||
|
""" La page de recherche avancée """
|
||||||
search_form = SearchFormPlus(request.GET or None)
|
search_form = SearchFormPlus(request.GET or None)
|
||||||
if search_form.is_valid():
|
if search_form.is_valid():
|
||||||
return render(
|
return render(
|
||||||
|
@ -340,4 +330,4 @@ def searchp(request):
|
||||||
search_form.cleaned_data
|
search_form.cleaned_data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return render(request, 'search/search.html', {'search_form' : search_form})
|
return render(request, 'search/search.html', {'search_form': search_form})
|
||||||
|
|
Loading…
Reference in a new issue