Example #1
0
 def add_filter(self, qs, obj):
     if isinstance(obj, datetime.date):
         obj = DateRangeValue(obj, obj)
     qs = qs.filter(start_date__isnull=False)
     if obj.start_date:
         qs = qs.filter(start_date__gte=obj.start_date)
     if obj.end_date:
         qs = qs.filter(start_date__lte=obj.end_date)
     return qs
Example #2
0
 def get_places_sum(self, today=None, **flt):
     Enrolment = rt.models.courses.Enrolment
     PeriodEvents = rt.models.system.PeriodEvents
     qs = Enrolment.objects.filter(course=self, **flt)
     # see voga.projects.roger.tests.test_max_places
     if today is None:
         rng = DateRangeValue(dd.today(), None)
         qs = PeriodEvents.active.add_filter(qs, rng)
     else:
         qs = PeriodEvents.active.add_filter(qs, today)
     # logger.info("20160502 %s", qs.query)
     res = qs.aggregate(models.Sum('places'))
     # logger.info("20140819 %s", res)
     return res['places__sum'] or 0