mirror of https://gitlab.crans.org/bde/nk20
List pending users
This commit is contained in:
parent
49807d33d9
commit
f10497bac3
|
@ -26,7 +26,7 @@ class ProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
exclude = ('user', 'email_confirmed', )
|
exclude = ('user', 'email_confirmed', 'registration_valid', )
|
||||||
|
|
||||||
|
|
||||||
class ClubForm(forms.ModelForm):
|
class ClubForm(forms.ModelForm):
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from member.tokens import account_activation_token
|
from registration.tokens import account_activation_token
|
||||||
from note.models import MembershipTransaction
|
from note.models import MembershipTransaction
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +53,11 @@ class Profile(models.Model):
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
registration_valid = models.BooleanField(
|
||||||
|
verbose_name=_("registration valid"),
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
email_confirmed = models.BooleanField(
|
email_confirmed = models.BooleanField(
|
||||||
verbose_name=_("email confirmed"),
|
verbose_name=_("email confirmed"),
|
||||||
default=False,
|
default=False,
|
||||||
|
|
|
@ -139,7 +139,7 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
template_name = 'member/user_list.html'
|
template_name = 'member/user_list.html'
|
||||||
|
|
||||||
def get_queryset(self, **kwargs):
|
def get_queryset(self, **kwargs):
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset().filter(profile__registration_valid=True)
|
||||||
if "search" in self.request.GET:
|
if "search" in self.request.GET:
|
||||||
pattern = self.request.GET["search"]
|
pattern = self.request.GET["search"]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
def save_user_note(instance, created, raw, **_kwargs):
|
def save_user_note(instance, raw, **_kwargs):
|
||||||
"""
|
"""
|
||||||
Hook to create and save a note when an user is updated
|
Hook to create and save a note when an user is updated
|
||||||
"""
|
"""
|
||||||
|
@ -10,10 +10,11 @@ def save_user_note(instance, created, raw, **_kwargs):
|
||||||
# When provisionning data, do not try to autocreate
|
# When provisionning data, do not try to autocreate
|
||||||
return
|
return
|
||||||
|
|
||||||
if created:
|
if instance.profile.registration_valid and instance.is_active:
|
||||||
from .models import NoteUser
|
# Create note only when the registration is validated
|
||||||
NoteUser.objects.create(user=instance)
|
from note.models import NoteUser
|
||||||
instance.note.save()
|
NoteUser.objects.get_or_create(user=instance)
|
||||||
|
instance.note.save()
|
||||||
|
|
||||||
|
|
||||||
def save_club_note(instance, created, raw, **_kwargs):
|
def save_club_note(instance, created, raw, **_kwargs):
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import django_tables2 as tables
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class FutureUserTable(tables.Table):
|
||||||
|
phone_number = tables.Column(accessor='profile.phone_number')
|
||||||
|
|
||||||
|
section = tables.Column(accessor='profile.section')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
|
}
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
fields = ('last_name', 'first_name', 'username', 'email', )
|
||||||
|
model = User
|
||||||
|
row_attrs = {
|
||||||
|
'class': 'table-row',
|
||||||
|
'data-href': lambda record: record.pk
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ from . import views
|
||||||
app_name = 'registration'
|
app_name = 'registration'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('signup/', views.UserCreateView.as_view(), name="signup"),
|
path('signup/', views.UserCreateView.as_view(), name="signup"),
|
||||||
path('accounts/activate/sent', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
|
path('validate_email/sent', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
|
||||||
path('accounts/activate/<uidb64>/<token>', views.UserActivateView.as_view(), name='account_activation'),
|
path('validate_email/<uidb64>/<token>', views.UserActivateView.as_view(), name='account_activation'),
|
||||||
|
path('validate_user/', views.FutureUserListView.as_view(), name="future_user_list"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.shortcuts import resolve_url
|
from django.shortcuts import resolve_url
|
||||||
|
@ -11,10 +12,13 @@ from django.utils.http import urlsafe_base64_decode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.decorators.csrf import csrf_protect
|
from django.views.decorators.csrf import csrf_protect
|
||||||
from django.views.generic import CreateView, TemplateView
|
from django.views.generic import CreateView, TemplateView
|
||||||
|
from django_tables2 import SingleTableView
|
||||||
from member.forms import ProfileForm
|
from member.forms import ProfileForm
|
||||||
from member.tokens import account_activation_token
|
from permission.views import ProtectQuerysetMixin
|
||||||
|
|
||||||
from .forms import SignUpForm
|
from .forms import SignUpForm
|
||||||
|
from .tables import FutureUserTable
|
||||||
|
from .tokens import account_activation_token
|
||||||
|
|
||||||
|
|
||||||
class UserCreateView(CreateView):
|
class UserCreateView(CreateView):
|
||||||
|
@ -23,8 +27,8 @@ class UserCreateView(CreateView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
form_class = SignUpForm
|
form_class = SignUpForm
|
||||||
success_url = reverse_lazy('member:login')
|
success_url = reverse_lazy('registration:account_activation_sent')
|
||||||
template_name = 'member/signup.html'
|
template_name = 'registration/signup.html'
|
||||||
second_form = ProfileForm
|
second_form = ProfileForm
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -108,3 +112,22 @@ class UserActivationEmailSentView(TemplateView):
|
||||||
template_name = 'registration/account_activation_email_sent.html'
|
template_name = 'registration/account_activation_email_sent.html'
|
||||||
title = _('Account activation email sent')
|
title = _('Account activation email sent')
|
||||||
|
|
||||||
|
|
||||||
|
class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
|
"""
|
||||||
|
Affiche la liste des utilisateurs, avec une fonction de recherche statique
|
||||||
|
"""
|
||||||
|
model = User
|
||||||
|
table_class = FutureUserTable
|
||||||
|
template_name = 'registration/future_user_list.html'
|
||||||
|
|
||||||
|
def get_queryset(self, **kwargs):
|
||||||
|
return super().get_queryset().filter(profile__registration_valid=False)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context["title"] = _("Unregistered users")
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
|
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if "member.change_profile_registration_valid"|has_perm:user %}
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="{% url 'registration:future_user_list' %}">
|
||||||
|
<i class="fa fa-user-plus"></i> {% trans "Registrations" %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% if "activity.activity"|not_empty_model_list %}
|
{% if "activity.activity"|not_empty_model_list %}
|
||||||
<li class="nav-item active">
|
<li class="nav-item active">
|
||||||
<a class="nav-link" href="{% url 'activity:activity_list' %}"><i class="fa fa-calendar"></i> {% trans 'Activities' %}</a>
|
<a class="nav-link" href="{% url 'activity:activity_list' %}"><i class="fa fa-calendar"></i> {% trans 'Activities' %}</a>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load render_table from django_tables2 %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div id="user_table">
|
||||||
|
{% render_table table %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<a href="{% url 'registration:signup' %}"><button class="btn btn-primary btn-block">{% trans "New user" %}</button></a>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extrajavascript %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".table-row").click(function() {
|
||||||
|
window.document.location = $(this).data("href");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue