From 26d70c4ef97ae838ef09ceec0277f8d439c25057 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 17:25:44 +0100 Subject: [PATCH 01/18] page title and edit buttons --- apps/member/views.py | 4 ---- templates/member/club_info.html | 11 +++++++++++ templates/member/profile_info.html | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 7d3ed748..b518ad24 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -143,10 +143,6 @@ class UserDetailView(LoginRequiredMixin, DetailView): club_list = \ Membership.objects.all().filter(user=user).only("club") context['club_list'] = ClubTable(club_list) - context['title'] = _("Account #%(id)s: %(username)s") % { - 'id': user.pk, - 'username': user.username, - } return context diff --git a/templates/member/club_info.html b/templates/member/club_info.html index a88527fc..d720b64f 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -1,5 +1,8 @@ {% load i18n static pretty_money %}
+
+

Club {{ club.name }}

+
+
diff --git a/templates/member/profile_info.html b/templates/member/profile_info.html index 30383866..9ff20385 100644 --- a/templates/member/profile_info.html +++ b/templates/member/profile_info.html @@ -1,6 +1,9 @@ {% load i18n static pretty_money %}
+
+

{% trans "Account #" %} {{ object.pk }}

+
From a41e51e23ad66e45e2d88fc1290e9abdd54dcb55 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 25 Mar 2020 17:42:54 +0100 Subject: [PATCH 02/18] add member get side information --- apps/member/views.py | 4 ++-- templates/member/add_members.html | 12 ++++++++---- templates/member/club_info.html | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index b518ad24..14322dcf 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -391,12 +391,12 @@ class ClubAddMemberView(LoginRequiredMixin, CreateView): return super().get_queryset().filter(PermissionBackend.filter_queryset(self.request.user, Membership, "view") | PermissionBackend.filter_queryset(self.request.user, Membership, "change")) - def get_context_data(self, **kwargs): + club = Club.objects.get(pk=self.kwargs["pk"]) context = super().get_context_data(**kwargs) context['formset'] = MemberFormSet() context['helper'] = FormSetHelper() - + context['club'] = club context['no_cache'] = True return context diff --git a/templates/member/add_members.html b/templates/member/add_members.html index 8032af30..8b57e7d4 100644 --- a/templates/member/add_members.html +++ b/templates/member/add_members.html @@ -1,7 +1,11 @@ -{% extends "base.html" %} +{% extends "member/noteowner_detail.html" %} {% load crispy_forms_tags %} {% load static %} -{% block content %} + +{% block profile_info %} +{% include "member/club_info.html" %} +{% endblock %} +{% block profile_content %}
{% csrf_token %} @@ -10,9 +14,9 @@
+{% endblock %} - - +{% block extrajavascript %} +{% endblock%} From a00e43bc265cf5cd0977309cbcfda7fc8fa09815 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 26 Mar 2020 21:04:32 +0100 Subject: [PATCH 12/18] Fix alias deletion --- apps/note/tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 3d8be58e..6e998fbb 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -77,7 +77,7 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_btn = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) From 61b6aceb36c1cc7ccf88ec68d3fbd54ec0fab5f1 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:04:14 +0100 Subject: [PATCH 13/18] crappy name -> crappy behavior --- apps/note/tables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/note/tables.py b/apps/note/tables.py index 6e998fbb..4ef9b594 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -77,7 +77,7 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete_btn = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) @@ -104,7 +104,7 @@ class ButtonTable(tables.Table): text=_('edit'), accessor='pk') - delete = tables.TemplateColumn(template_code=DELETE_TEMPLATE, + delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE, extra_context={"delete_trans": _('delete')}, attrs={'td': {'class': 'col-sm-1'}}) From 49dd88dbb7d53aa8af9c6dc8bc90fdf6fbbf2895 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:04:51 +0100 Subject: [PATCH 14/18] add errMsg function --- static/js/base.js | 10 +++++++++- static/js/consos.js | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/js/base.js b/static/js/base.js index f7085850..d06c2fbe 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -28,7 +28,15 @@ function addMsg(msg, alert_type) { + msg + "
\n"; msgDiv.html(html); } - +/** + * add Muliple error message from err_obj + * @param err_obj {error_code:erro_message} + */ +function errMsg(errs_obj){ + for (const err_msg of Object.values(errs_obj)) { + addMsg(err_msg,'danger'); + } +} /** * Reload the balance of the user on the right top corner */ diff --git a/static/js/consos.js b/static/js/consos.js index 896f996c..27173365 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -200,7 +200,6 @@ function consume(source, dest, quantity, amount, reason, type, category, templat "template": template }, reset).fail(function (e) { reset(); - - addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger"); + errMsg(e.responseJSON); }); } From f7a66920e0d1bcbba112a8a8f4db71118f9d3699 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:05:08 +0100 Subject: [PATCH 15/18] move common script to alias.js --- static/js/alias.js | 37 +++++++++++++++++++++++++++++ templates/member/club_alias.html | 4 ++++ templates/member/profile_alias.html | 32 +------------------------ 3 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 static/js/alias.js diff --git a/static/js/alias.js b/static/js/alias.js new file mode 100644 index 00000000..267410da --- /dev/null +++ b/static/js/alias.js @@ -0,0 +1,37 @@ + + $("#alias_input").on('keypress',function(e) { + if(e.which == 13) { + $("#alias_submit").click(); + } + }); + + function create_alias(note_id){ + $.post("/api/note/alias/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "name": $("#alias_input").val(), + "note": note_id + } + ).done(function(){ + $("#alias_table").load(location.href+ " #alias_table"); + addMsg("Alias ajouté","success"); + }) + .fail(function(xhr, textStatus, error){ + errMsg(xhr.responseJSON); + }); +} + // on click of button "delete" , call the API + function delete_button(button_id){ + $.ajax({ + url:"/api/note/alias/"+button_id+"/", + method:"DELETE", + headers: {"X-CSRFTOKEN": CSRF_TOKEN} + }) + .done(function(){ + addMsg('Alias supprimé','success'); + $("#alias_table").load(location.href + " #alias_table"); + }) + .fail(function(xhr,textStatus, error){ + errMsg(xhr.responseJSON); + }); + } diff --git a/templates/member/club_alias.html b/templates/member/club_alias.html index 394b1c95..4b6f2882 100644 --- a/templates/member/club_alias.html +++ b/templates/member/club_alias.html @@ -4,3 +4,7 @@ {% block profile_content %} {% include "member/alias_update.html" %} {% endblock %} + +{% block extrajavascript %} + +{% endblock%} diff --git a/templates/member/profile_alias.html b/templates/member/profile_alias.html index 9d2c34a3..eb6e499a 100644 --- a/templates/member/profile_alias.html +++ b/templates/member/profile_alias.html @@ -6,35 +6,5 @@ {% endblock %} {% block extrajavascript %} - + {% endblock%} From c50e17c55519507d8bf4ffa1c70e7d0a511b84aa Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 26 Mar 2020 23:05:37 +0100 Subject: [PATCH 16/18] error handling up to client --- apps/note/api/views.py | 17 +++++++++++++++-- apps/note/models/notes.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 3a29b522..40fc4f4e 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -2,10 +2,14 @@ # SPDX-License-Identifier: GPL-3.0-or-later from django.db.models import Q +from django.core.exceptions import ValidationError from django_filters.rest_framework import DjangoFilterBackend from rest_framework.filters import OrderingFilter, SearchFilter -from api.viewsets import ReadProtectedModelViewSet, ReadOnlyProtectedModelViewSet from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework import status + +from api.viewsets import ReadProtectedModelViewSet, ReadOnlyProtectedModelViewSet from .serializers import NotePolymorphicSerializer, AliasSerializer, TemplateCategorySerializer, \ TransactionTemplateSerializer, TransactionPolymorphicSerializer @@ -59,7 +63,16 @@ class AliasViewSet(viewsets.ModelViewSet): #alias owner cannot be change once establish setattr(serializer_class.Meta, 'read_only_fields', ('note',)) return serializer_class - + + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + try: + self.perform_destroy(instance) + except ValidationError as e: + print(e) + return Response({e.code:e.message},status.HTTP_400_BAD_REQUEST) + return Response(status=status.HTTP_204_NO_CONTENT) + def get_queryset(self): """ Parse query and apply filters. diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 2fa63906..43faabfe 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -249,5 +249,5 @@ class Alias(models.Model): def delete(self, using=None, keep_parents=False): if self.name == str(self.note): raise ValidationError(_("You can't delete your main alias."), - code="cant_delete_main_alias") + code="main_alias") return super().delete(using, keep_parents) From a3a8fd601ce5a2426db6d5408da63534235b2112 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 27 Mar 2020 13:26:47 +0100 Subject: [PATCH 17/18] revert to ReadProtectedViewset --- apps/note/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 40fc4f4e..e70eb49e 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -45,7 +45,7 @@ class NotePolymorphicViewSet(ReadOnlyProtectedModelViewSet): return queryset.distinct() -class AliasViewSet(viewsets.ModelViewSet): +class AliasViewSet(ReadProtectedModelViewSet): """ REST API View set. The djangorestframework plugin will get all `Alias` objects, serialize it to JSON with the given serializer, From ee3d441a56f7650584e33360e9e360d35914c9ff Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 27 Mar 2020 14:04:30 +0100 Subject: [PATCH 18/18] add parent club link --- templates/member/club_info.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/member/club_info.html b/templates/member/club_info.html index b63c1e85..539d9867 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -13,6 +13,9 @@
{% trans 'name'|capfirst %}
{{ club.name}}
+
{% trans 'Club Parent'|capfirst %}
+
{{ club.parent_club.name}}
+
{% trans 'membership start'|capfirst %}
{{ club.membership_start }}