def calendarjs(self, request): """Return response with serialized partner event calender data.""" start, end = extract_date_range(request) queryset = PartnerEvent.objects.filter( end__gte=start, start__lte=end, published=True ) serializer = PartnerEventCalendarJSSerializer(queryset, many=True) return Response(serializer.data)
def birthdays(self, request): start, end = extract_date_range(request) queryset = Member.current_members.with_birthdays_in_range(start, end).filter( profile__show_birthday=True ) all_birthdays = [self._get_birthdays(m, start, end) for m in queryset.all()] birthdays = [x for sublist in all_birthdays for x in sublist] serializer = MemberBirthdaySerializer(birthdays, many=True) return Response(serializer.data)
def get_queryset(self): queryset = Event.objects.filter(published=True) if (self.action == "retrieve" or api_settings.SEARCH_PARAM in self.request.query_params): return queryset start, end = extract_date_range(self.request, allow_empty=True) if start is not None: queryset = queryset.filter(start__gte=start) if end is not None: queryset = queryset.filter(end__lte=end) if start is None and end is None: queryset = queryset.filter(end__gte=timezone.now()) return queryset
def unpublished(self, request): """ Defines a custom route that outputs the correctly formatted events information for CalendarJS, unpublished events only :param request: the request object :return: response containing the data """ start, end = extract_date_range(request) queryset = Event.objects.filter(end__gte=start, start__lte=end, published=False) serializer = UnpublishedEventsCalenderJSSerializer( queryset, many=True, context={"member": request.member}) return Response(serializer.data)