mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Club members autocomplete
This commit is contained in:
parent
7bafc89713
commit
ce012400e1
@ -1,7 +1,7 @@
|
||||
# -*- mode: python; coding: utf-8 -*-
|
||||
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django import forms
|
||||
@ -44,6 +44,14 @@ class MembershipForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Membership
|
||||
fields = ('user','roles','date_start')
|
||||
widgets = {
|
||||
'user': autocomplete.ModelSelect2(url='member:user_autocomplete',
|
||||
attrs={
|
||||
'data-placeholder': 'Nom ...',
|
||||
'data-minimum-input-length': 1,
|
||||
}),
|
||||
}
|
||||
|
||||
|
||||
MemberFormSet = forms.modelformset_factory(Membership,
|
||||
form=MembershipForm,
|
||||
|
@ -18,4 +18,5 @@ urlpatterns = [
|
||||
path('user/',views.UserListView.as_view(),name="user_list"),
|
||||
path('user/<int:pk>',views.UserDetailView.as_view(),name="user_detail"),
|
||||
path('user/<int:pk>/update',views.UserUpdateView.as_view(),name="user_update_profile"),
|
||||
path('user/user-autocomplete',views.UserAutocomplete.as_view(),name="user_autocomplete"),
|
||||
]
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
||||
@ -115,6 +115,18 @@ class UserListView(LoginRequiredMixin,SingleTableView):
|
||||
return context
|
||||
|
||||
|
||||
class UserAutocomplete(autocomplete.Select2QuerySetView):
|
||||
"""
|
||||
Auto complete note by aliases
|
||||
"""
|
||||
def get_queryset(self):
|
||||
qs = User.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(username__regex=self.q)
|
||||
|
||||
return qs
|
||||
|
||||
###################################
|
||||
############## CLUB ###############
|
||||
###################################
|
||||
|
@ -24,6 +24,11 @@ class TransactionForm(forms.ModelForm):
|
||||
fields = ('destination', 'reason', 'amount',)
|
||||
|
||||
widgets = {
|
||||
'source': autocomplete.ModelSelect2(url='note:note_autocomplete',
|
||||
attrs={
|
||||
'data-placeholder': 'Note ...',
|
||||
'data-minimum-input-length': 1,
|
||||
}),
|
||||
'destination': autocomplete.ModelSelect2(url='note:note_autocomplete',
|
||||
attrs={
|
||||
'data-placeholder': 'Note ...',
|
||||
|
Loading…
Reference in New Issue
Block a user