Verified Commit 1c21bbba authored by Lennart Jansen's avatar Lennart Jansen Committed by Sébastiaan Versteeg
Browse files

Voegt de ongepubliceerde evenementen toe aan de gangbare kalender van iedereen...

Voegt de ongepubliceerde evenementen toe aan de gangbare kalender van iedereen die de permissie heeft om een evenement toe te voegen. Dit geldt voor zowel de lijst-, week- als ook maand-weergave.
Close #308
parent a9ddc595
from rest_framework import permissions
class UnpublishedEventPermissions(permissions.DjangoModelPermissions):
perms_map = {
'GET': ['%(app_label)s.add_%(model_name)s'],
}
...@@ -73,3 +73,18 @@ class EventSerializer(CalenderJSSerializer): ...@@ -73,3 +73,18 @@ class EventSerializer(CalenderJSSerializer):
return instance.is_member_registered(self.context['user'].member) return instance.is_member_registered(self.context['user'].member)
except AttributeError: except AttributeError:
return None return None
class UnpublishedEventSerializer(CalenderJSSerializer):
class Meta(CalenderJSSerializer.Meta):
model = Event
def _background_color(self, instance):
return "#888888"
def _text_color(self, instance):
return "white"
def _url(self, instance):
return reverse('events:admin-details', kwargs={
'event_id': instance.id})
...@@ -2,17 +2,17 @@ from datetime import datetime ...@@ -2,17 +2,17 @@ from datetime import datetime
from django.utils import timezone from django.utils import timezone
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response from rest_framework.response import Response
from events.api.serializers import EventSerializer from events.api.permissions import UnpublishedEventPermissions
from events.api.serializers import EventSerializer, UnpublishedEventSerializer
from events.models import Event from events.models import Event
class EventViewset(viewsets.ViewSet): def _extract_date_range(request):
queryset = Event.objects.all()
def list(self, request):
try: try:
start = timezone.make_aware( start = timezone.make_aware(
datetime.strptime(request.query_params['start'], '%Y-%m-%d') datetime.strptime(request.query_params['start'], '%Y-%m-%d')
...@@ -22,6 +22,14 @@ class EventViewset(viewsets.ViewSet): ...@@ -22,6 +22,14 @@ class EventViewset(viewsets.ViewSet):
) )
except: except:
raise ParseError(detail='start or end query parameters invalid') raise ParseError(detail='start or end query parameters invalid')
return end, start
class EventViewset(viewsets.ViewSet):
queryset = Event.objects.all()
def list(self, request):
end, start = _extract_date_range(request)
queryset = self.queryset.filter( queryset = self.queryset.filter(
end__gte=start, end__gte=start,
...@@ -32,3 +40,17 @@ class EventViewset(viewsets.ViewSet): ...@@ -32,3 +40,17 @@ class EventViewset(viewsets.ViewSet):
serializer = EventSerializer(queryset, many=True, serializer = EventSerializer(queryset, many=True,
context={'user': request.user}) context={'user': request.user})
return Response(serializer.data) return Response(serializer.data)
@list_route(permission_classes=(IsAdminUser, UnpublishedEventPermissions,))
def unpublished(self, request):
end, start = _extract_date_range(request)
queryset = self.queryset.filter(
end__gte=start,
start__lte=end,
published=False
)
serializer = UnpublishedEventSerializer(queryset, many=True,
context={'user': request.user})
return Response(serializer.data)
...@@ -6,24 +6,24 @@ ListView = View.extend({ // make a subclass of View ...@@ -6,24 +6,24 @@ ListView = View.extend({ // make a subclass of View
title: gettext("Upcoming Events"), title: gettext("Upcoming Events"),
updateTitle: function() { updateTitle: function () {
// this space intentionally left blank // this space intentionally left blank
}, },
computeRange: function(date) { computeRange: function (date) {
var range = View.prototype.computeRange.call(this, date); var range = View.prototype.computeRange.call(this, date);
range.end.add(1, 'years'); range.end.add(1, 'years');
return range; return range;
}, },
renderEvents: function(events) { renderEvents: function (events) {
var ul = $('<ul>').addClass('toggles'); var ul = $('<ul>').addClass('toggles');
if (this.opt('maxEvents') != undefined) { if (this.opt('maxEvents') != undefined) {
events = events.slice(0, this.opt('maxEvents')); events = events.slice(0, this.opt('maxEvents'));
} }
events.sort(function(a, b) { events.sort(function (a, b) {
return a.start < b.start ? -1 : a.start > b.start ? 1 : 0; return a.start < b.start ? -1 : a.start > b.start ? 1 : 0;
}); });
...@@ -49,6 +49,15 @@ ListView = View.extend({ // make a subclass of View ...@@ -49,6 +49,15 @@ ListView = View.extend({ // make a subclass of View
li.append('<div class="event-indication" title="' + gettext("Not registered for this event") + '"><div class="no-registration"></div></div>'); li.append('<div class="event-indication" title="' + gettext("Not registered for this event") + '"><div class="no-registration"></div></div>');
} }
if (e.backgroundColor !== null) {
li.css('background-color', e.backgroundColor);
}
if (e.textColor !== null) {
li.find(".toggle-title a").css('color', e.textColor);
li.find(".toggle-content a").css('color', e.textColor);
}
ul.append(li); ul.append(li);
} }
// This originates from theme_thimbus/themes/thimbus/assets/js/scripts_dev.js, // This originates from theme_thimbus/themes/thimbus/assets/js/scripts_dev.js,
...@@ -61,9 +70,9 @@ ListView = View.extend({ // make a subclass of View ...@@ -61,9 +70,9 @@ ListView = View.extend({ // make a subclass of View
return; return;
} }
if ($parent.hasClass('current')) { if ($parent.hasClass('current')) {
$parent.removeClass('current').find('.toggle-content').stop().css('display','block').slideUp(500,'easeOutExpo'); $parent.removeClass('current').find('.toggle-content').stop().css('display', 'block').slideUp(500, 'easeOutExpo');
} else { } else {
$parent.addClass('current').find('.toggle-content').stop().css('display','none').slideDown(500,'easeOutExpo'); $parent.addClass('current').find('.toggle-content').stop().css('display', 'none').slideDown(500, 'easeOutExpo');
$parent.siblings('.current').find('.toggle-title').trigger('click'); $parent.siblings('.current').find('.toggle-title').trigger('click');
}; };
}); });
......
...@@ -37,9 +37,19 @@ ...@@ -37,9 +37,19 @@
var sources = { var sources = {
events: "/api/events", events: "/api/events",
birthdays: "/api/members/birthdays", birthdays: "/api/members/birthdays",
partners: "/api/partners/events" partners: "/api/partners/events",
unpublishedEvents: "/api/events/unpublished"
}; };
var eventSources = [sources.events, sources.partners];
{% if perms.events.change_event %}
eventSources.push(sources.unpublishedEvents);
{% endif %}
if (Cookies.get('showbirthdays')) {
eventSources.push(sources.birthdays);
}
$('#calendar').fullCalendar({ $('#calendar').fullCalendar({
defaultDate: defaultDate:
{% spaceless %} {% spaceless %}
...@@ -84,7 +94,7 @@ ...@@ -84,7 +94,7 @@
titleRangeSeparator: ' - ', titleRangeSeparator: ' - ',
timeFormat: 'H:mm', timeFormat: 'H:mm',
eventLimit: true, // allow "more" link when too many events eventLimit: true, // allow "more" link when too many events
eventSources: Cookies.get('showbirthdays') ? [sources.events, sources.birthdays, sources.partners] : [sources.events, sources.partners], eventSources: eventSources,
eventClick: function(event) { eventClick: function(event) {
if(event.url && event.blank) { if(event.url && event.blank) {
window.open(event.url, '_blank'); window.open(event.url, '_blank');
......
Supports Markdown
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