Commit 9c1a2693 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Add event attendance registration

parent 461eddb8
django.jQuery(function () {
var $ = django.jQuery;
var url = $("#content-main").attr("data-url");
var paid_url = url + "paid/";
var present_url = url + "present/";
$(".present-check").change(function () {
var checkbox = $(this);
var id = checkbox.attr("data-id");
var checked = checkbox.prop('checked');
post(present_url, { checked: checked, id: id }, function(result) {
if (!result.success) {
checkbox.prop('checked', !checked);
}
}, function() {
checkbox.prop('checked', !checked);
});
});
$(".paid-check").change(function () {
var checkbox = $(this);
var id = checkbox.attr("data-id");
var checked = checkbox.prop('checked');
post(paid_url, { checked: checked, id: id }, function(result) {
if (!result.success) {
checkbox.prop('checked', !checked);
}
}, function() {
checkbox.prop('checked', !checked);
});
});
});
function post(url, data, success, error) {
django.jQuery.post({
url: url,
type: 'post',
data: data,
headers: {
"X-CSRFToken": getCookie('csrftoken')
},
dataType: 'json'
}).done(success).fail(error);
}
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = django.jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
\ No newline at end of file
{% extends 'admin/index.html' %}
{% load i18n admin_urls static admin_modify %}
{% block title %}{{ event.title }}{{ block.super }}{% endblock %}
{% block title %}{{ event.title }} | {{ site_title|default:_('Thalia site admin') }}{% endblock %}
{% block extrastyle %}
{{ block.super }}
<link href="{% static "events/css/admin.css" %}" rel="stylesheet" type="text/css">
{% endblock %}
{% block extrahead %}
{{ block.super }}
<script type="text/javascript" src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script>
<script type="text/javascript" src="{% static "admin/js/jquery.init.js" %}"></script>
<script type="text/javascript" src="{% static "events/js/admin.js" %}"></script>
{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Thalia administration') }}</a></h1>
{% endblock %}
......@@ -23,7 +30,7 @@
{% block content_title %}<h1>{% blocktrans with event=event.title %}Event overview: {{ event }}{% endblocktrans %}</h1>{% endblock %}
{% block content %}
<div id="content-main">
<div id="content-main" data-url="{% url 'events:admin-registration' event.id %}">
<div class="module">
{% with event.registrationinformationfield_set.all as fields %}
<h2>{% trans "registrations"|capfirst %}</h2>
......
......@@ -38,8 +38,8 @@
<td>{{ field.value }}</td>
{% endif %}
{% endfor %}
<td>{{ registration.present|yesno }}</td>
<td>{{ registration.paid|yesno }}</td>
<td><input type="checkbox" {{ registration.present|yesno:'checked="checked",' }} data-id="{{ registration.id }}" class="present-check" /></td>
<td><input type="checkbox" {{ registration.paid|yesno:'checked="checked",' }} data-id="{{ registration.id }}" class="paid-check" /></td>
{% if registration.date_cancelled is not None %}
<td>{{ registration.is_late_cancellation|yesno }}</td>
{% endif %}
......
......@@ -9,6 +9,10 @@ from . import views
urlpatterns = [
url(r'admin/(?P<event_id>\d+)/$', views.admin_details, name='admin-details'),
url(r'admin/(?P<event_id>\d+)/registration/(?P<action>[-\w]+)/$',
views.admin_change_registration, name='admin-registration'),
url(r'admin/(?P<event_id>\d+)/registration/$',
views.admin_change_registration, name='admin-registration'),
url(r'admin/(?P<event_id>\d+)/export/$', views.export, name='export'),
url(r'^(?P<event_id>\d+)/$', views.event, name='event'),
url(r'^(?P<event_id>\d+)/registration/(?P<action>[-\w]+)/$',
......
import csv
import json
from datetime import timedelta
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.views.decorators.http import require_http_methods
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
......@@ -29,6 +31,30 @@ def admin_details(request, event_id):
})
@staff_member_required
@permission_required('events.change_event')
@require_http_methods(["POST"])
def admin_change_registration(request, event_id, action=None):
data = {
'success': True
}
try:
id = request.POST.get("id", -1)
checked = json.loads(request.POST.get("checked"))
obj = Registration.objects.get(event=event_id, pk=id)
if checked is not None:
if action == 'present':
obj.present = checked
elif action == 'paid':
obj.paid = checked
obj.save()
except Registration.DoesNotExist:
data['success'] = False
return JsonResponse(data)
@staff_member_required
@permission_required('events.change_event')
def export(request, event_id):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment