Move delete buttons to edit page

This commit is contained in:
Yingtong Li 2019-06-19 18:26:34 +10:00
parent 2d9ea3b311
commit 2a5bf7ad93
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
10 changed files with 38 additions and 23 deletions

View File

@ -95,6 +95,9 @@
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}"> <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<input class="ui primary button" type="submit" name='submit' value="Save"> <input class="ui primary button" type="submit" name='submit' value="Save">
<input class="ui button" type="submit" name='submit' value="Save and continue editing"> <input class="ui button" type="submit" name='submit' value="Save and continue editing">
{% if request.resolver_match.url_name == 'bulletin_edit' %}
<input class="ui right floated red button" type="submit" name='submit' value="Delete" onclick="return confirm('Are you sure you want to delete this bulletin item? This action is IRREVERSIBLE.');">
{% endif %}
</form> </form>
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
{# {#
Society Self-Service 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 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 it under the terms of the GNU Affero General Public License as published by
@ -24,9 +24,9 @@
<table class="ui selectable celled table"> <table class="ui selectable celled table">
<thead> <thead>
<tr> <tr>
<th class="four wide">Title</th> <th class="five wide">Title</th>
<th class="ten wide">Content</th> <th class="ten wide">Content</th>
<th class="two wide">Actions</th> <th class="one wide">Edit</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -34,9 +34,8 @@
<tr> <tr>
<td class="selectable"><a href="{{ url('bulletin_edit', kwargs={'id': item.id}) }}">{{ item.title }}</a></td> <td class="selectable"><a href="{{ url('bulletin_edit', kwargs={'id': item.id}) }}">{{ item.title }}</a></td>
<td>{{ item.content|markdown }}</td> <td>{{ item.content|markdown }}</td>
<td class="selectable"> <td>
<a href="{{ url('bulletin_edit', kwargs={'id': item.id}) }}" class="ui tiny primary icon button" style="margin: 0.8em 0 0.8em 0.8em;"><i class="edit icon"></i></a> <a href="{{ url('bulletin_edit', kwargs={'id': item.id}) }}" class="ui tiny primary icon button"><i class="edit icon"></i></a>
<a href="{{ url('bulletin_delete', kwargs={'id': item.id}) }}" onclick="return confirm('Are you sure you want to delete this bulletin item?');" class="ui tiny red icon button" style="margin: 0.8em 0 0.8em 0.8em;"><i class="trash icon"></i></a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -22,7 +22,6 @@ urlpatterns = [
path('bulletin/', views.bulletin_list, name='bulletin_list'), path('bulletin/', views.bulletin_list, name='bulletin_list'),
path('bulletin/new/', views.bulletin_new, name='bulletin_new'), path('bulletin/new/', views.bulletin_new, name='bulletin_new'),
path('bulletin/edit/<int:id>', views.bulletin_edit, name='bulletin_edit'), path('bulletin/edit/<int:id>', views.bulletin_edit, name='bulletin_edit'),
path('bulletin/delete/<int:id>', views.bulletin_delete, name='bulletin_delete'),
path('bulletin/preview/', views.bulletin_preview, name='bulletin_preview'), path('bulletin/preview/', views.bulletin_preview, name='bulletin_preview'),
path('', views.index, name='promotions'), path('', views.index, name='promotions'),
] ]

View File

@ -112,9 +112,20 @@ def bulletin_new(request):
def bulletin_edit(request, id): def bulletin_edit(request, id):
if request.method == 'POST': if request.method == 'POST':
item = models.BulletinItem.objects.get(id=id) 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'])) item.group = models.Group.objects.get(id=int(request.POST['group']))
if not item.can_user_access(request.user): if not item.can_user_access(request.user):
return HttpResponse('Unauthorized', status=401) return HttpResponse('Unauthorized', status=401)
item.title = request.POST['title'] item.title = request.POST['title']
item.date = request.POST['date'] item.date = request.POST['date']
item.content = request.POST['content'] item.content = request.POST['content']
@ -132,16 +143,8 @@ def bulletin_edit(request, id):
item = models.BulletinItem.objects.get(id=id) item = models.BulletinItem.objects.get(id=id)
if not item.can_user_access(request.user): if not item.can_user_access(request.user):
return HttpResponse('Unauthorized', status=401) return HttpResponse('Unauthorized', status=401)
return render(request, 'sspromotions/bulletin_edit.html', { return render(request, 'sspromotions/bulletin_edit.html', {
'item': item, 'item': item,
'groups': models.Group.objects.filter(hidden=False).all() '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'))

View File

@ -2,7 +2,7 @@
{# {#
Society Self-Service 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 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 it under the terms of the GNU Affero General Public License as published by
@ -95,6 +95,9 @@
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}"> <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<input class="ui primary button" type="submit" name='submit' value="Save"> <input class="ui primary button" type="submit" name='submit' value="Save">
<input class="ui button" type="submit" name='submit' value="Save and continue editing"> <input class="ui button" type="submit" name='submit' value="Save and continue editing">
{% if request.resolver_match.url_name == 'budget_edit' %}
<input class="ui right floated red button" type="submit" name='submit' value="Delete" onclick="return confirm('Are you sure you want to delete this budget? This action is IRREVERSIBLE.');">
{% endif %}
</form> </form>
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
{# {#
Society Self-Service 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 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 it under the terms of the GNU Affero General Public License as published by
@ -26,6 +26,7 @@
<tr> <tr>
<th class="twelve wide">Name</th> <th class="twelve wide">Name</th>
<th class="four wide">Status</th> <th class="four wide">Status</th>
<th class="one wide">View</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -33,6 +34,9 @@
<tr> <tr>
<td class="selectable"><a href="{{ url('budget_view', kwargs={'id': revision.budget.id}) }}">{{ revision.name }}</a></td> <td class="selectable"><a href="{{ url('budget_view', kwargs={'id': revision.budget.id}) }}">{{ revision.name }}</a></td>
<td class="selectable"><a href="{{ url('budget_view', kwargs={'id': revision.budget.id}) }}">{{ import('sstreasury.models').BudgetState(revision.state).description }}</a></td> <td class="selectable"><a href="{{ url('budget_view', kwargs={'id': revision.budget.id}) }}">{{ import('sstreasury.models').BudgetState(revision.state).description }}</a></td>
<td>
<a href="{{ url('budget_view', kwargs={'id': revision.budget.id}) }}" class="ui tiny primary icon button"><i class="eye icon"></i></a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -71,4 +75,4 @@
{% block head %} {% block head %}
{{ super() }} {{ super() }}
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
{# {#
Society Self-Service 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 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 it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
# Society Self-Service # 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 # 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 # it under the terms of the GNU Affero General Public License as published by

View File

@ -1,6 +1,6 @@
/* /*
Society Self-Service 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 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 it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
# Society Self-Service # 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 # 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 # 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(): if request.user not in revision.contributors.all():
raise PermissionDenied raise PermissionDenied
if request.POST['submit'] == 'Delete':
budget.delete()
return redirect(reverse('budget_list'))
with transaction.atomic(): with transaction.atomic():
revision = models.BudgetRevision() revision = models.BudgetRevision()
revision.author = request.user revision.author = request.user