Added delete functionality for events. Additionally, made improvements and fixed to the validation for event creation.
This commit is contained in:
parent
11abbb8a64
commit
7b2ac3ec38
7 changed files with 188 additions and 33 deletions
|
@ -27,6 +27,7 @@ urlpatterns = [
|
|||
url(r'^(?P<event_id>[0-9]+)/encrypt/$', login_required(views.event_addec), name='enc-event'),
|
||||
url(r'^(?P<pk>[0-9]+)/launch/$', views.EventDetailLaunchView.as_view(), name='launch-event'),
|
||||
url(r'^edit/(?P<event_id>[0-9]+)/$', login_required(views.edit_event), name='edit-event'),
|
||||
url(r'^delete/(?P<event_id>[0-9]+)/$', login_required(views.del_event), name='del-event'),
|
||||
url(r'^(?P<event_id>[0-9]+)/create/poll/$', login_required(views.manage_questions), name='create-poll'),
|
||||
url(r'^(?P<event_id>[0-9]+)/poll/(?P<poll_num>[0-9]+)/$', login_required(views.view_poll), name='view-poll'),
|
||||
url(r'^(?P<event_id>[0-9]+)/poll/(?P<poll_num>[0-9]+)/edit$', login_required(views.edit_poll), name='edit-poll'),
|
||||
|
|
|
@ -297,7 +297,7 @@ def create_event(request):
|
|||
# TODO: Based on whether validation was successful within update model and whether
|
||||
# TODO: data was actually persisted, either perform a redirect (success) or flag an error
|
||||
|
||||
return HttpResponseRedirect("/event/")
|
||||
return HttpResponseRedirect(reverse('polls:index'))
|
||||
elif request.method == "GET":
|
||||
# Obtain context data for the rendering of the html template
|
||||
events = Event.objects.all()
|
||||
|
@ -354,6 +354,14 @@ def edit_event(request, event_id):
|
|||
|
||||
#class CreatePoll(generic.View):
|
||||
|
||||
def del_event(request, event_id):
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
if request.method == "GET":
|
||||
return render(request, "polls/del_event.html", {"event_title": event.title, "event_id": event.id})
|
||||
elif request.method == "POST":
|
||||
event.delete()
|
||||
return HttpResponseRedirect(reverse('polls:index'))
|
||||
|
||||
def can_vote(user, event):
|
||||
if event.voters.filter(email=user.email).exists():
|
||||
return True
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
<!-- The following UI was ported from the Election Authority UI in DEMOS1 by Vincent de Almeida -->
|
||||
<!-- The DEMOS1 repository can be found at: https://github.com/mlevogiannis/demos-voting -->
|
||||
<!-- TODO: look into i18n translations as this was a feature implemented in DEMOS1 -->
|
||||
<hr/>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h2>Create New Event with Polls</h2>
|
||||
|
@ -105,6 +104,9 @@
|
|||
<span id="vote-end-input-error-block" class="help-block errorText">
|
||||
<!-- Errors flagged here -->
|
||||
</span>
|
||||
<span id="event-timings-error-block" class="help-block errorText">
|
||||
<!-- Errors flagged here -->
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Questions -->
|
||||
|
@ -112,7 +114,7 @@
|
|||
<label for="questions-input" class="col-sm-3 col-md-2 control-label">Polls:</label> <!-- This text can be a template variable -->
|
||||
<div class="col-sm-9 col-md-10">
|
||||
<div class="form-group">
|
||||
<table id="questions-input-table" class="table table-hover">
|
||||
<table id="polls-input-table" class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">#</th>
|
||||
|
@ -120,9 +122,9 @@
|
|||
<th class="text-center">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="formset questions-formset" data-formset-prefix="questions" data-formset-type="modal" data-formset-modal-title="Add a New Poll">
|
||||
<!-- Question / Statement -->
|
||||
<tr class="formset-form formset-form-empty hidden" data-formset-form-prefix="question">
|
||||
<tbody class="formset questions-formset" data-formset-prefix="polls" data-formset-type="modal" data-formset-modal-title="Add a New Poll">
|
||||
<!-- Poll -->
|
||||
<tr class="formset-form formset-form-empty hidden" data-formset-form-prefix="poll">
|
||||
<!-- # -->
|
||||
<td class="formset-form-index text-center" scope=row>
|
||||
1
|
||||
|
@ -228,7 +230,7 @@
|
|||
</table>
|
||||
<div class="clearfix">
|
||||
<button type="button" class="btn btn-primary formset-add" data-formset-prefix="options">
|
||||
<i class="fa fa-plus-circle" aria-hidden="true"></i>
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
Add Poll Option
|
||||
</button>
|
||||
</div>
|
||||
|
@ -245,11 +247,11 @@
|
|||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<label class="sr-only" for="minimum-input">Minimum</label>
|
||||
<input type="number" class="form-control min-input" id="minimum-input" placeholder="Minimum" value="" name="minimum-input" min="0"> <!-- TODO: Max should be set to the number of options -->
|
||||
<input type="number" class="form-control min-input" id="minimum-input" placeholder="Minimum" value="" name="minimum-input" min="0" max="2"> <!-- Max is the default number of options initially displayed (2) -->
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<label class="sr-only" for="maximum-input">Maximum</label>
|
||||
<input type="number" class="form-control max-input" id="maximum-input" placeholder="Maximum" value="" name="maximum-input" min="1"> <!-- TODO: Max should be set to the number of options -->
|
||||
<input type="number" class="form-control max-input" id="maximum-input" placeholder="Maximum" value="" name="maximum-input" min="1" max="2"> <!-- Max is the default number of options initially displayed (2) -->
|
||||
</div>
|
||||
</div>
|
||||
<span id="question-input-help-block" class="help-block">
|
||||
|
@ -265,21 +267,21 @@
|
|||
</tbody>
|
||||
</table>
|
||||
<div class="clearfix">
|
||||
<button type="button" class="btn btn-primary formset-add" data-formset-prefix="questions">
|
||||
<i class="fa fa-plus-circle" aria-hidden="true"></i>
|
||||
<button type="button" class="btn btn-primary formset-add" data-formset-prefix="polls">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
Add Poll
|
||||
</button>
|
||||
</div>
|
||||
<span id="question-input-help-block" class="help-block">
|
||||
Drag and drop to re-order polls.
|
||||
</span>
|
||||
<span id="question-input-error-block" class="help-block errorText">
|
||||
<span id="polls-input-error-block" class="help-block errorText">
|
||||
<!-- Errors flagged here -->
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Number of Polls -->
|
||||
<!-- { Hidden field: Number of Polls } -->
|
||||
<input type="number" id="poll-count-input" name="poll-count-input" class="hidden">
|
||||
<!-- Organisers -->
|
||||
<div class="form-group">
|
||||
|
@ -357,7 +359,7 @@
|
|||
</table>
|
||||
<div class="clearfix">
|
||||
<button type="button" class="btn btn-primary formset-add" data-formset-prefix="organisers">
|
||||
<i class="fa fa-plus-circle" aria-hidden="true"></i>
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
Add Organiser Email
|
||||
</button>
|
||||
</div>
|
||||
|
@ -446,7 +448,7 @@
|
|||
</table>
|
||||
<div class="clearfix">
|
||||
<button type="button" class="btn btn-primary formset-add" data-formset-prefix="trustees">
|
||||
<i class="fa fa-plus-circle" aria-hidden="true"></i>
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
Add Trustee Email
|
||||
</button>
|
||||
</div>
|
||||
|
@ -468,10 +470,11 @@
|
|||
Manually enter email addresses separated with commas. Alternatively, you can also upload a CSV file:
|
||||
</span>
|
||||
<label for="files" class="btn btn-primary">
|
||||
Upload CSV
|
||||
<span class="glyphicon glyphicon-cloud-upload"></span>
|
||||
Upload CSV
|
||||
</label>
|
||||
<input type="file" id="files" name="file" class="btn-info">
|
||||
<h4 id="result" class="hidden"></h4>
|
||||
<h4 id="result" class="hidden successText"></h4>
|
||||
<span id="voters-input-error-block" class="help-block errorText">
|
||||
<!-- Errors flagged here -->
|
||||
</span>
|
||||
|
|
27
allauthdemo/templates/polls/del_event.html
Executable file
27
allauthdemo/templates/polls/del_event.html
Executable file
|
@ -0,0 +1,27 @@
|
|||
{% extends "bases/bootstrap-with-nav.html" %}
|
||||
{% load staticfiles %}
|
||||
{% load bootstrap3 %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h3>Confirm Event Deletion</h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<form method="POST" action="{% url 'polls:del-event' event_id %}" novalidate>
|
||||
{% csrf_token %}
|
||||
<label>Are you sure you want to delete the event '{{ event_title }}' ?</label>
|
||||
<hr/>
|
||||
<div class="confirm-footer">
|
||||
<a href="{% url 'polls:index' %}">
|
||||
<span class="btn btn-default">Cancel</span>
|
||||
</a>
|
||||
<input type="submit" class="btn btn-danger delete" value="Delete"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -41,7 +41,7 @@
|
|||
<a href="{% url 'polls:edit-event' event.id %}">
|
||||
<span class="btn btn-default glyphicon glyphicon-pencil"></span>
|
||||
</a>
|
||||
<a href="#">
|
||||
<a href="{% url 'polls:del-event' event.id %}">
|
||||
<span class="btn btn-default glyphicon glyphicon-trash"></span>
|
||||
</a>
|
||||
</td>
|
||||
|
|
Reference in a new issue