diff --git a/apps/member/filters.py b/apps/member/filters.py new file mode 100644 index 00000000..fb1a2128 --- /dev/null +++ b/apps/member/filters.py @@ -0,0 +1,31 @@ +# -*- mode: python; coding: utf-8 -*- +# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from django_filters import FilterSet, CharFilter,NumberFilter +from django.contrib.auth.models import User +from django.db.models import CharField +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout, Submit + +from .models import Club + +class UserFilter(FilterSet): + class Meta: + model = User + fields = ['last_name','first_name','username','profile__section'] + filter_overrides={ + CharField:{ + 'filter_class':CharFilter, + 'extra': lambda f:{ + 'lookup_expr':'icontains' + } + } + } + +class UserFilterFormHelper(FormHelper): + form_method = 'GET' + layout = Layout( + 'last_name','first_name','username','profile__section', + Submit('Submit','Apply Filter'), + ) diff --git a/apps/member/tables.py b/apps/member/tables.py index 5213a3d4..4218948c 100644 --- a/apps/member/tables.py +++ b/apps/member/tables.py @@ -2,12 +2,26 @@ import django_tables2 as tables from .models import Club +from django.conf import settings +from django.contrib.auth.models import User class ClubTable(tables.Table): class Meta: attrs = {'class':'table table-bordered table-condensed table-striped table-hover'} model = Club template_name = 'django_tables2/bootstrap.html' - fields= ('id','name','email') + fields = ('id','name','email') row_attrs = {'class':'table-row', 'data-href': lambda record: record.pk } + + + +class UserTable(tables.Table): + section = tables.Column(accessor='profile.section') + solde = tables.Column(accessor='note.balance') + + class Meta: + attrs = {'class':'table table-bordered table-condensed table-striped table-hover'} + template_name = 'django_tables2/bootstrap.html' + fields = ('last_name','first_name','username','email') + model = User diff --git a/apps/member/urls.py b/apps/member/urls.py index 39d3d896..8d3aa40a 100644 --- a/apps/member/urls.py +++ b/apps/member/urls.py @@ -15,5 +15,6 @@ urlpatterns = [ path('club//',views.ClubDetailView.as_view(),name="club_detail"), path('club//add_member/',views.ClubAddMemberView.as_view(),name="club_add_member"), path('club/create/',views.ClubCreateView.as_view(),name="club_create"), + path('user/',views.UserListView.as_view(),name="user_list"), path('user/',views.UserDetailView.as_view(),name="user_detail") ] diff --git a/apps/member/views.py b/apps/member/views.py index fed0c30b..c5c3d788 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, ListView, DetailView from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User from django.urls import reverse_lazy from django.db.models import Q @@ -16,9 +17,13 @@ from django_tables2.views import SingleTableView from .models import Profile, Club, Membership from .forms import ProfileForm, ClubForm,MembershipForm, MemberFormSet,FormSetHelper -from .tables import ClubTable +from .tables import ClubTable,UserTable +from .filters import UserFilter, UserFilterFormHelper + + from note.models.transactions import Transaction from note.tables import HistoryTable + class UserCreateView(CreateView): """ Une vue pour inscrire un utilisateur et lui créer un profile @@ -60,6 +65,28 @@ class UserDetailView(LoginRequiredMixin,DetailView): context['club_list'] = ClubTable(club_list) return context +class UserListView(LoginRequiredMixin,SingleTableView): + model = User + table_class = UserTable + template_name = 'member/user_list.html' + filter_class = UserFilter + formhelper_class = UserFilterFormHelper + + def get_queryset(self,**kwargs): + qs = super().get_queryset() + self.filter = self.filter_class(self.request.GET,queryset=qs) + self.filter.form.helper = self.formhelper_class() + return self.filter.qs + + def get_context_data(self,**kwargs): + context = super().get_context_data(**kwargs) + context["filter"] = self.filter + return context + + +################################### +############## CLUB ############### +################################### class ClubCreateView(LoginRequiredMixin,CreateView): """ diff --git a/requirements.txt b/requirements.txt index 39c20738..51b9ae4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ Django==2.2.3 django-allauth==0.39.1 django-crispy-forms==1.7.2 django-extensions==2.1.9 +django-filter==2.2.0 django-polymorphic==2.0.3 django-reversion==3.0.3 django-tables2==2.1.0 diff --git a/templates/member/user_list.html b/templates/member/user_list.html new file mode 100644 index 00000000..821ea619 --- /dev/null +++ b/templates/member/user_list.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load render_table from django_tables2 %} +{% load crispy_forms_tags%} +{% block content %} + +New User + +
+{% crispy filter.form filter.form.helper %} +
+
+
+ {% render_table table %} +
+
+ +{% endblock %} + +{% block extrajavascript %} + +{% endblock %}