From 2a5bf7ad9303aad93b2c414c6ac766c6fc80eb43 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Wed, 19 Jun 2019 18:26:34 +1000 Subject: [PATCH] Move delete buttons to edit page --- .../jinja2/sspromotions/bulletin_edit.html | 3 +++ .../jinja2/sspromotions/bulletin_list.html | 11 +++++----- sspromotions/urls.py | 1 - sspromotions/views.py | 21 +++++++++++-------- sstreasury/jinja2/sstreasury/budget_edit.html | 5 ++++- sstreasury/jinja2/sstreasury/budget_list.html | 8 +++++-- sstreasury/jinja2/sstreasury/budget_view.html | 2 +- sstreasury/models.py | 2 +- sstreasury/static/sstreasury/budget.js | 2 +- sstreasury/views.py | 6 +++++- 10 files changed, 38 insertions(+), 23 deletions(-) diff --git a/sspromotions/jinja2/sspromotions/bulletin_edit.html b/sspromotions/jinja2/sspromotions/bulletin_edit.html index f1e040f..97142a2 100644 --- a/sspromotions/jinja2/sspromotions/bulletin_edit.html +++ b/sspromotions/jinja2/sspromotions/bulletin_edit.html @@ -95,6 +95,9 @@ + {% if request.resolver_match.url_name == 'bulletin_edit' %} + + {% endif %} {% endblock %} diff --git a/sspromotions/jinja2/sspromotions/bulletin_list.html b/sspromotions/jinja2/sspromotions/bulletin_list.html index 76750a7..7fae41a 100644 --- a/sspromotions/jinja2/sspromotions/bulletin_list.html +++ b/sspromotions/jinja2/sspromotions/bulletin_list.html @@ -2,7 +2,7 @@ {# Society Self-Service - Copyright © 2018 Yingtong Li (RunasSudo) + Copyright © 2018-2019 Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -24,9 +24,9 @@ - + - + @@ -34,9 +34,8 @@ - {% endfor %} diff --git a/sspromotions/urls.py b/sspromotions/urls.py index 48aec24..db5a14a 100644 --- a/sspromotions/urls.py +++ b/sspromotions/urls.py @@ -22,7 +22,6 @@ urlpatterns = [ path('bulletin/', views.bulletin_list, name='bulletin_list'), path('bulletin/new/', views.bulletin_new, name='bulletin_new'), path('bulletin/edit/', views.bulletin_edit, name='bulletin_edit'), - path('bulletin/delete/', views.bulletin_delete, name='bulletin_delete'), path('bulletin/preview/', views.bulletin_preview, name='bulletin_preview'), path('', views.index, name='promotions'), ] diff --git a/sspromotions/views.py b/sspromotions/views.py index ccde5f6..2e9ef21 100644 --- a/sspromotions/views.py +++ b/sspromotions/views.py @@ -112,9 +112,20 @@ def bulletin_new(request): def bulletin_edit(request, id): if request.method == 'POST': item = models.BulletinItem.objects.get(id=id) + + # Check access with old group + if not item.can_user_access(request.user): + return HttpResponse('Unauthorized', status=401) + + if request.POST['submit'] == 'Delete': + item.delete() + return redirect(reverse('bulletin_list')) + + # Check access with new group item.group = models.Group.objects.get(id=int(request.POST['group'])) if not item.can_user_access(request.user): return HttpResponse('Unauthorized', status=401) + item.title = request.POST['title'] item.date = request.POST['date'] item.content = request.POST['content'] @@ -132,16 +143,8 @@ def bulletin_edit(request, id): item = models.BulletinItem.objects.get(id=id) if not item.can_user_access(request.user): return HttpResponse('Unauthorized', status=401) + return render(request, 'sspromotions/bulletin_edit.html', { 'item': item, 'groups': models.Group.objects.filter(hidden=False).all() }) - -@login_required -def bulletin_delete(request, id): - item = models.BulletinItem.objects.get(id=id) - if not item.can_user_access(request.user): - return HttpResponse('Unauthorized', status=401) - item.delete() - - return redirect(reverse('bulletin_list')) diff --git a/sstreasury/jinja2/sstreasury/budget_edit.html b/sstreasury/jinja2/sstreasury/budget_edit.html index e694ec5..830ca00 100644 --- a/sstreasury/jinja2/sstreasury/budget_edit.html +++ b/sstreasury/jinja2/sstreasury/budget_edit.html @@ -2,7 +2,7 @@ {# Society Self-Service - Copyright © 2018 Yingtong Li (RunasSudo) + Copyright © 2018-2019 Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -95,6 +95,9 @@ + {% if request.resolver_match.url_name == 'budget_edit' %} + + {% endif %} {% endblock %} diff --git a/sstreasury/jinja2/sstreasury/budget_list.html b/sstreasury/jinja2/sstreasury/budget_list.html index bd344cf..15c8b76 100644 --- a/sstreasury/jinja2/sstreasury/budget_list.html +++ b/sstreasury/jinja2/sstreasury/budget_list.html @@ -2,7 +2,7 @@ {# Society Self-Service - Copyright © 2018 Yingtong Li (RunasSudo) + Copyright © 2018-2019 Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -26,6 +26,7 @@ + @@ -33,6 +34,9 @@ + {% endfor %} @@ -71,4 +75,4 @@ {% block head %} {{ super() }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/sstreasury/jinja2/sstreasury/budget_view.html b/sstreasury/jinja2/sstreasury/budget_view.html index dfde150..396b13b 100644 --- a/sstreasury/jinja2/sstreasury/budget_view.html +++ b/sstreasury/jinja2/sstreasury/budget_view.html @@ -2,7 +2,7 @@ {# Society Self-Service - Copyright © 2018 Yingtong Li (RunasSudo) + Copyright © 2018-2019 Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by diff --git a/sstreasury/models.py b/sstreasury/models.py index 61d803e..007a3e1 100644 --- a/sstreasury/models.py +++ b/sstreasury/models.py @@ -1,5 +1,5 @@ # Society Self-Service -# Copyright © 2018 Yingtong Li (RunasSudo) +# Copyright © 2018-2019 Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by diff --git a/sstreasury/static/sstreasury/budget.js b/sstreasury/static/sstreasury/budget.js index d7baef0..2807eca 100644 --- a/sstreasury/static/sstreasury/budget.js +++ b/sstreasury/static/sstreasury/budget.js @@ -1,6 +1,6 @@ /* Society Self-Service - Copyright © 2018 Yingtong Li (RunasSudo) + Copyright © 2018-2019 Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by diff --git a/sstreasury/views.py b/sstreasury/views.py index 29dd30f..adee9ac 100644 --- a/sstreasury/views.py +++ b/sstreasury/views.py @@ -1,5 +1,5 @@ # Society Self-Service -# Copyright © 2018 Yingtong Li (RunasSudo) +# Copyright © 2018-2019 Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -138,6 +138,10 @@ def budget_edit(request, id): if request.user not in revision.contributors.all(): raise PermissionDenied + if request.POST['submit'] == 'Delete': + budget.delete() + return redirect(reverse('budget_list')) + with transaction.atomic(): revision = models.BudgetRevision() revision.author = request.user
TitleTitle ContentActionsEdit
{{ item.title }} {{ item.content|markdown }} - - + +
Name StatusView
{{ revision.name }} {{ import('sstreasury.models').BudgetState(revision.state).description }} + +