From 639aa86684e81d729aee9255da5d10dcafa21cd2 Mon Sep 17 00:00:00 2001 From: chirac Date: Mon, 28 Dec 2020 12:15:37 +0100 Subject: [PATCH] Add views and urls for autocomplete on user app --- users/urls.py | 7 ++++ users/views_autocomplete.py | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 users/views_autocomplete.py diff --git a/users/urls.py b/users/urls.py index 74cdd284..b7d52ddc 100644 --- a/users/urls.py +++ b/users/urls.py @@ -31,6 +31,7 @@ from __future__ import unicode_literals from django.conf.urls import url from . import views +from . import views_autocomplete urlpatterns = [ url(r"^new_user/$", views.new_user, name="new-user"), @@ -128,4 +129,10 @@ urlpatterns = [ url(r"^index_clubs/$", views.index_clubs, name="index-clubs"), url(r"^initial_register/$", views.initial_register, name="initial-register"), url(r"^edit_theme/(?P[0-9]+)$", views.edit_theme, name="edit-theme"), + ### Autocomplete Views + url(r'^user-autocomplete/$', views_autocomplete.UserAutocomplete.as_view(), name='user-autocomplete',), + url(r'^adherent-autocomplete/$', views_autocomplete.AdherentAutocomplete.as_view(), name='adherent-autocomplete',), + url(r'^club-autocomplete/$', views_autocomplete.ClubAutocomplete.as_view(), name='club-autocomplete',), + url(r'^school-autocomplete/$', views_autocomplete.SchoolAutocomplete.as_view(), name='school-autocomplete',), + url(r'^shell-autocomplete/$', views_autocomplete.ShellAutocomplete.as_view(), name='shell-autocomplete',), ] diff --git a/users/views_autocomplete.py b/users/views_autocomplete.py new file mode 100644 index 00000000..a2ea0c06 --- /dev/null +++ b/users/views_autocomplete.py @@ -0,0 +1,72 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017-2020 Gabriel Détraz +# Copyright © 2017-2020 Jean-Romain Garnier +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# App de gestion des users pour re2o +# Lara Kermarec, Gabriel Détraz, Lemesle Augustin +# Gplv2 +""" +Django views autocomplete view + +Here are defined the autocomplete class based view. + +""" +from __future__ import unicode_literals + +from .models import ( + User, + Ban, + Whitelist, + School, + ListRight, + Request, + ServiceUser, + Adherent, + Club, + ListShell, + EMailAddress, +) + +from re2o.mixins import AutocompleteViewMixin + +from re2o.acl import ( + can_view_all, +) + +#@can_view_all(School) +class SchoolAutocomplete(AutocompleteViewMixin): + obj_type = School + +#@can_view_all(User) +class UserAutocomplete(AutocompleteViewMixin): + obj_type = User + +#@can_view_all(Adherent) +class AdherentAutocomplete(AutocompleteViewMixin): + obj_type = Adherent + +#@can_view_all(Club) +class ClubAutocomplete(AutocompleteViewMixin): + obj_type = Club + +class ShellAutocomplete(AutocompleteViewMixin): + obj_type = ListShell + query_filter = "shell__icontains"