Merge branch 'Aufinal/delete_bds_user' into 'master'

Possibilité de supprimer un utilisateur sur gestioBDS

Closes #271

See merge request klub-dev-ens/gestioCOF!442
This commit is contained in:
Martin Pepin 2020-08-25 20:17:51 +02:00
commit 1d707aad41
8 changed files with 122 additions and 46 deletions

View file

@ -16,20 +16,20 @@ Liste des changements notables dans GestioCOF depuis la version 0.1 (septembre
- Vue d'inscription à un événement **ou** intégration propre dans la vue - Vue d'inscription à un événement **ou** intégration propre dans la vue
"inscription d'un nouveau membre" "inscription d'un nouveau membre"
### Nouveau module BDS
Uniquement un modèle BDSProfile pour le moment…
### Nouveau module de gestion des clubs ### Nouveau module de gestion des clubs
Uniquement un modèle simple de clubs avec des respos. Aucune gestion des Uniquement un modèle simple de clubs avec des respos. Aucune gestion des
adhérents ni des cotisations. adhérents ni des cotisations.
## Upcoming
### GestioBDS
- Ajout d'un bouton pour supprimer un compte
### Site du COF ### Site du COF
Captcha fonctionnel pour les mailing-listes - Captcha fonctionnel pour les mailing-listes
## Upcoming
## Version 0.6 - 27/0702020 ## Version 0.6 - 27/0702020

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -123,6 +123,16 @@ input[type="submit"] {
} }
} }
.button.is-primary {
background-color: $button_color;
color: findColorInvert($button_color);
&:hover {
background-color: $primary_color;
color: findColorInvert($primary_color);
}
}
/* --- Message styling --- */ /* --- Message styling --- */
.notification { .notification {
@ -131,3 +141,12 @@ input[type="submit"] {
text-align: center; text-align: center;
} }
/* --- Modals --- */
.modal-card-head {
background-color: $primary_color;
.modal-card-title {
color: findColorInvert($primary_color);
}
}

View file

@ -1,28 +0,0 @@
{% extends "bds/base.html" %}
{% load bulma_utils %}
{% block body %}
{% include "bds/nav.html" %}
<section class="section">
<div class="columns">
<div class="column is-two-thirds is-offset-2">
{% if messages %}
{% for message in messages %}
<div class="notification is-{{ message.level_tag|bulma_message_tag }}">
{% if 'safe' in message.tags %}
{{ message|safe }}
{% else %}
{{ message }}
{% endif %}
</div>
{% endfor %}
{% endif %}
{% block content %}
{% endblock content %}
</div>
</div>
</section>
{% endblock body %}

View file

@ -15,19 +15,90 @@
<h1 class="title">{% trans "Modification du profil " %}{{ view.user.username }}</h1> <h1 class="title">{% trans "Modification du profil " %}{{ view.user.username }}</h1>
<div class="container"> <div class="container">
<form action="" method="post"> <form method="post" action="" id="user-update-form">
{% csrf_token %} {% csrf_token %}
{% for form in forms.values %} {% for form in forms.values %}
{% include "bds/forms/form.html" with form=form errors=False %} {% include "bds/forms/form.html" with form=form errors=False %}
{% endfor %} {% endfor %}
<div class="field">
<p class="control">
<input class="button is-fullwidth" type="submit" value="Enregistrer">
</p>
</div>
</form> </form>
<form method="post" action="{% url 'bds:user.delete' view.user.pk %}" id="user-delete-form">
{% csrf_token %}
</form>
<div class="columns is-gapless mt-5">
<div class="column is-5">
<button id="user-update-button" class="button is-fullwidth is-primary">Enregistrer</button>
</div>
<div class="column is-2">
</div>
<div class="column is-5">
<button id="user-delete-button" class="button is-fullwidth is-danger">Supprimer</button>
</div>
</div>
</div> </div>
<!-- Hidden by default -->
<div id="confirm-delete-modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Confirmer la suppression</p>
<button id= "modal-close" class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
Voulez-vous réellement supprimer ce compte ? Attention, cette opération est irréversible !
</section>
<footer class="modal-card-foot">
<button id="confirm-delete-button" class="button is-primary">Supprimer</button>
<button id="cancel-delete-button" class="button">Annuler</button>
</footer>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
"use strict";
// Adapted from https://bulma.io/lib/main.js
function openModal(target) {
$(document).addClass('is-clipped');
$(`#${target}`).addClass('is-active');
}
function closeModals() {
$(document).removeClass('is-clipped');
$(".modal").removeClass('is-active');
}
// Si on clique sur enregistrer, ça marche
$("#user-update-button").on("click", function() {
$("#user-update-form").submit();
})
// Si on clique sur supprimer, confirmation demandée
$("#user-delete-button").on("click", function () {
openModal("confirm-delete-modal");
});
$(".modal-background, #modal-close, #cancel-delete-button").on("click", closeModals);
$("#confirm-delete-button").on("click", function() {
$("#user-delete-form").submit();
});
$(document).on("keydown", function (e) {
if (e.key == "Escape") {
closeModals();
}
if (e.key == "Enter") {
$("#user-update-form").submit();
}
});
});
</script>
{% endblock %} {% endblock %}

View file

@ -13,4 +13,5 @@ urlpatterns = [
views.UserCreateView.as_view(), views.UserCreateView.as_view(),
name="user.create.fromclipper", name="user.create.fromclipper",
), ),
path("user/delete/<int:pk>", views.UserDeleteView.as_view(), name="user.delete"),
] ]

View file

@ -1,9 +1,9 @@
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView from django.views.generic import DeleteView, TemplateView
from bds.autocomplete import bds_search from bds.autocomplete import bds_search
from bds.forms import ProfileForm, UserForm, UserFromClipperForm, UserFromScratchForm from bds.forms import ProfileForm, UserForm, UserFromClipperForm, UserFromScratchForm
@ -109,3 +109,16 @@ class UserCreateView(StaffRequiredMixin, MultipleFormView):
def form_invalid(self, forms): def form_invalid(self, forms):
messages.error(self.request, _("Veuillez corriger les erreurs ci-dessous")) messages.error(self.request, _("Veuillez corriger les erreurs ci-dessous"))
return super().form_invalid(forms) return super().form_invalid(forms)
class UserDeleteView(StaffRequiredMixin, DeleteView):
model = User
success_url = reverse_lazy("bds:home")
success_message = "Profil supprimé avec succès !"
def delete(self, request, *args, **kwargs):
# SuccessMessageMixin does not work with DeleteView, see :
# https://code.djangoproject.com/ticket/21926
messages.success(request, self.success_message)
return super().delete(request, *args, **kwargs)