Added a view, to get the list of open events for registration as json
This commit is contained in:
@@ -4,6 +4,7 @@ import logging
|
||||
from django.apps import apps
|
||||
from django.contrib import messages
|
||||
from django.db.models import Q
|
||||
from django.http import JsonResponse
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views import generic
|
||||
@@ -64,6 +65,30 @@ class EventListView(generic.ListView):
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
def EventListAsJSONView(request):
|
||||
filter_cleaned = []
|
||||
if 'filter' in request.GET:
|
||||
choices = SPORT_CHOICES.codes + LEVEL_CHOICES.codes
|
||||
filter_input = request.GET['filter'].split(',')
|
||||
filter_cleaned = list(set(filter_input) & set(choices))
|
||||
|
||||
today = datetime.date.today()
|
||||
|
||||
filter_exp = Q(flags__status__code__in=('publishing', 'publishing_web', 'publishing_facebook',
|
||||
'published', 'published_web', 'published_facebook'))
|
||||
filter_exp &= Q(planned_publication_date__isnull=True) | Q(planned_publication_date__lte=today)
|
||||
filter_exp &= Q(first_day__gte=today)
|
||||
# filter_exp &= Q(registration_closed=False)
|
||||
# filter_exp &= Q(deadline__isnull=True) | Q(deadline__gte=today)
|
||||
if filter_cleaned:
|
||||
filter_exp &= Q(sport__in=filter_cleaned) | Q(level__in=filter_cleaned)
|
||||
|
||||
qs = Event.objects.filter(filter_exp).order_by('first_day', 'number').distinct()
|
||||
data = [event.as_dict(json=True) for event in qs]
|
||||
response = JsonResponse(data, safe=False)
|
||||
return response
|
||||
|
||||
|
||||
class EventDetailView(generic.DetailView):
|
||||
model = Event
|
||||
template_name = 'dav_registration/event_detail.html'
|
||||
|
||||
Reference in New Issue
Block a user