示例#1
0
    def get_queryset(self):
        bounds = self.request.GET.get('bounds', None)
        zoom = self.request.GET.get('zoom', 8)
        qs = super(EventViewSet, self).get_queryset()
        if not self.request.user.is_authenticated():
            qs = qs.prefetch_related('category')
        else:
            # TODO: Use the current_age property instead of age here
            age_range = self.request.user.children.aggregate(Min('age'), Max('age'))
            min_age = age_range['age__min'] if age_range['age__min'] else Event.DEFAULT_MAX_AGE_EVENT #Yes, DEFAULT_MAX!
            max_age = age_range['age__max'] if age_range['age__max'] else Event.DEFAULT_MIN_AGE_EVENT #Yes, DEFAULT_MIN!
            # The above defaults are set in such a way so that no events are filtered unnecessarily
            qs = qs.filter(min_age__lte=min_age, max_age__gte=max_age).prefetch_related('category')
        event_service = EventSearchServices(zoom, bounds)
        if event_service.bounds:
            if self.request.user.is_authenticated():
                profile = self.request.user.profile
                profile.last_known_location_bounds = event_service.bounds
                profile.last_map_zoom = event_service.zoom
                profile.save()

            if not event_service.bounds and self.request.user.is_authenticated():
                event_service.bounds = self.request.user.profile.last_known_location_bounds
                event_service.zoom = self.request.user.profile.last_map_zoom

            qs = event_service.get_events_within_bounds(qs)

        return qs
示例#2
0
 def filter_location(self, queryset, value):
     event_service = EventSearchServices(circle=value)
     qs = event_service.get_events_near_center(queryset)
     return qs