Add option to delete info item.

This commit is contained in:
Víðir Valberg Guðmundsson 2018-05-06 21:55:50 +02:00
parent 9d5a9daab4
commit 642c452984
4 changed files with 63 additions and 9 deletions

View file

@ -0,0 +1,30 @@
{% extends 'base.html' %}
{% load commonmark %}
{% load bootstrap3 %}
{% block title %}
{% if form.instance.id %}
Edit Info Item: {{ form.instance.headline }}
{% else %}
Create Info item
{% endif %}
in {{ form.instance.category.headline }}
{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>
Delete info item {{ object.name }}
in {{ form.instance.category.headline }}
</h4>
</div>
<div class="panel-body">
<form method="POST">
{% csrf_token %}
<p>Are you sure you want to delete "{{ object.headline }}" in the "{{ object.category.headline }}" category.</p>
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</div>
</div>
{% endblock %}

View file

@ -3,31 +3,37 @@
{% load bootstrap3 %}
{% block title %}
{% if form.instance.id %}
Edit Info Item: {{ form.instance.headline }}
{% if object %}
Editing "{{ object.headline }}"
{% else %}
Create Info item
{% endif %}
in {{ form.instance.category.headline }}
in "{{ form.instance.category.headline }}"
{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>
{% if form.instance.id %}
Edit Info Item: {{ form.instance.name }}
{% if object %}
Editing "{{ object.headline }}"
{% else %}
Create Info Item
{% endif %}
in {{ form.instance.category.headline }}
in "{{ object.category.headline }}"
</h4>
</div>
<div class="panel-body">
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<button type="submit" class="btn btn-primary">{% if form.instance.id %}Save{% else %}Create{% endif %}</button>
<button type="submit" class="btn btn-primary">{% if object.id %}Save{% else %}Create{% endif %}</button>
{% if object %}
<a href="{% url 'teams:info_item_delete' camp_slug=camp.slug team_slug=object.category.team.slug category_anchor=object.category.anchor item_anchor=object.anchor %}"
class="btn btn-danger">
<i class="fa fa-remove"></i> Delete
</a>
{% endif %}
</form>
</div>
<div class="panel-footer"><i>This info item belongs to the <a href="{% url 'teams:detail' team_slug=team.slug camp_slug=team.camp.slug %}">{{ team.name }} Team</a></i></div>

View file

@ -10,7 +10,7 @@ from teams.views.base import (
TeamManageView,
FixIrcAclView,
)
from teams.views.info import InfoItemUpdateView, InfoItemCreateView
from teams.views.info import InfoItemUpdateView, InfoItemCreateView, InfoItemDeleteView
from teams.views.tasks import (
TaskCreateView,
@ -105,6 +105,11 @@ urlpatterns = [
InfoItemUpdateView.as_view(),
name='info_item_update',
),
url(
r'^delete/$',
InfoItemDeleteView.as_view(),
name='info_item_delete',
),
]),
),
])

View file

@ -1,6 +1,6 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
from django.views.generic import CreateView, UpdateView
from django.views.generic import CreateView, UpdateView, DeleteView
from reversion.views import RevisionMixin
from camps.mixins import CampViewMixin
@ -47,3 +47,16 @@ class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibl
if next:
return next
return self.team.get_absolute_url()
class InfoItemDeleteView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, DeleteView):
model = InfoItem
template_name = "info_item_delete_confirm.html"
slug_field = 'anchor'
slug_url_kwarg = 'item_anchor'
def get_success_url(self):
next = self.request.GET.get('next')
if next:
return next
return self.team.get_absolute_url()