staff can delete a participant that does not have any talk, fix #102

This commit is contained in:
Guilhem Saurel 2017-11-28 01:10:28 +01:00
parent ca38b114ec
commit 603cec8303
4 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% load crispy_forms_tags i18n %}
{% block content %}
<div class="row">
<div class="col-md-12">
<form method="POST" class="form-horizontal col-md-8 col-md-offset-2">
{% csrf_token %}
<div class="form-group">
{% blocktrans %}Are you really sure that you want to delete a speaker ?{% endblocktrans %}
</div>
{{ form|crispy }}
<div class="col-md-12 text-center">
<button type="submit" class="btn btn-warning text-center">{% trans "Yes, Delete" %}</button>
<a href="javascript:history.back()" class="btn btn-default text-center">{% trans "Nope, Abort" %}</a>
</div>
</form>
</div>
</div>
{% endblock %}

View File

@ -10,7 +10,12 @@
{% if participant.vip %}<span class="badge">{% trans "VIP" %}</span>{% endif %} {% if participant.vip %}<span class="badge">{% trans "VIP" %}</span>{% endif %}
</h1> </h1>
<p><a class="btn btn-success" href="{% url 'participant-edit' participant.pk %}">{% trans "Edit" %}</a></p> <p>
<a class="btn btn-success" href="{% url 'participant-edit' participant.pk %}">{% trans "Edit" %}</a>
{% if not participant.talk_set.exists %} -
<a class="btn btn-danger" href="{% url 'participant-remove' participant.pk %}" >{% trans "Remove" %}</a>
{% endif %}
</p>
<h2>{% trans "Biography" %}</h2> <h2>{% trans "Biography" %}</h2>
<p>{{ participant.biography|linebreaksbr }}</p> <p>{{ participant.biography|linebreaksbr }}</p>

View File

@ -42,6 +42,7 @@ urlpatterns = [
url(r'^staff/speakers/(?P<participant_id>[0-9]+)/$', views.participant_details, name='participant-details'), url(r'^staff/speakers/(?P<participant_id>[0-9]+)/$', views.participant_details, name='participant-details'),
url(r'^staff/speakers/(?P<participant_id>[0-9]+)/add-talk/$', views.participant_add_talk, name='participant-add-talk'), url(r'^staff/speakers/(?P<participant_id>[0-9]+)/add-talk/$', views.participant_add_talk, name='participant-add-talk'),
url(r'^staff/speakers/(?P<participant_id>[0-9]+)/edit/$', views.ParticipantUpdate.as_view(), name='participant-edit'), url(r'^staff/speakers/(?P<participant_id>[0-9]+)/edit/$', views.ParticipantUpdate.as_view(), name='participant-edit'),
url(r'^staff/speakers/(?P<participant_id>[0-9]+)/remove/$', views.ParticipantRemove.as_view(), name='participant-remove'),
url(r'^staff/tracks/$', views.TrackList.as_view(), name='track-list'), url(r'^staff/tracks/$', views.TrackList.as_view(), name='track-list'),
url(r'^staff/tracks/add/$', views.TrackCreate.as_view(), name='track-add'), url(r'^staff/tracks/add/$', views.TrackCreate.as_view(), name='track-add'),
url(r'^staff/tracks/(?P<slug>[-\w]+)/edit/$', views.TrackUpdate.as_view(), name='track-edit'), url(r'^staff/tracks/(?P<slug>[-\w]+)/edit/$', views.TrackUpdate.as_view(), name='track-edit'),

View File

@ -4,9 +4,9 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.urls import reverse from django.urls import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView, TemplateView from django.views.generic import DeleteView, FormView, TemplateView
from django.contrib import messages from django.contrib import messages
from django.db.models import Q from django.db.models import Q, Count
from django.views.generic import CreateView, DetailView, ListView, UpdateView from django.views.generic import CreateView, DetailView, ListView, UpdateView
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.utils import timezone from django.utils import timezone
@ -824,6 +824,15 @@ class ParticipantUpdate(StaffRequiredMixin, OnSiteFormMixin, UpdateView):
) )
class ParticipantRemove(StaffRequiredMixin, OnSiteFormMixin, DeleteView):
slug_field = 'pk'
slug_url_kwarg = 'participant_id'
success_url = reverse_lazy('participant-list')
def get_queryset(self):
return Participant.objects.annotate(talk_count=Count('talk')).filter(talk_count=0)
@staff_required @staff_required
def participant_add_talk(request, participant_id): def participant_add_talk(request, participant_id):
participant = get_object_or_404(Participant, site=request.conference.site, pk=participant_id) participant = get_object_or_404(Participant, site=request.conference.site, pk=participant_id)