From db9594457486421db63144eb011d795eb6ab0171 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 28 Feb 2020 15:25:45 +0100 Subject: [PATCH] add delete boutons, work with only one alias --- apps/member/views.py | 11 +++++++---- apps/note/tables.py | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 4518c955..14ba0556 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -187,10 +187,13 @@ class AliasView(LoginRequiredMixin,FormMixin,DetailView): print(alias,alias.pk) return super().form_valid(form) -class DeleteAliasView(DeleteView): - model = Alias - success_url = reverse_lazy('member:user_alias') - +class DeleteAliasView(LoginRequiredMixin, DeleteView): + model = Alias + def get_success_url(self): + return reverse_lazy('member:user_alias',kwargs={'pk':self.object.note.user.pk}) + def get(self, request, *args, **kwargs): + return self.post(request, *args, **kwargs) + class ManageAuthTokens(LoginRequiredMixin, TemplateView): """ Affiche le jeton d'authentification, et permet de le regénérer diff --git a/apps/note/tables.py b/apps/note/tables.py index 461b6aa2..c8dbf74a 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -3,7 +3,7 @@ import django_tables2 as tables from django.db.models import F - +from django_tables2.utils import A from .models.transactions import Transaction from .models.notes import Alias @@ -32,8 +32,8 @@ class AliasTable(tables.Table): 'table table condensed table-striped table-hover' } model = Alias - fields = ('name',) + fields = ('name','pk') template_name = 'django_tables2/bootstrap4.html' - # delete = tables.LinkColumn('member:user_alias_delete', args=[A('id')], attrs={ - # 'a': {'class': 'btn'} }) + delete = tables.LinkColumn('member:user_alias_delete', args=[A('pk')], attrs={ + 'a': {'class': 'btn btn-danger'} },text='delete')