Ejemplo n.º 1
0
 def get_results(self, request, queryset, display_fields=None):
     filter = self.filterset_class(request.session.get(
         '%s-report:filter_criteria_GET' % self.app_label),
                                   queryset=queryset)
     self._results = process_queryset(filter.qs,
                                      display_fields=display_fields)
     return self._results
Ejemplo n.º 2
0
	def test_results(self):

		"""
		Our fixtures contain 5 people, 3 of whom have each 2 contacts, one inside small_range and one outside.
		One who has only large_range contacts.
		One who has no contacts.

		The sequence hours for the contacts are fibonacci
		"""

		# Dead simple
		qs = process_queryset(testmodels.Person.objects.all())
		self.assertEquals(len(qs),5)

		small_range = ('2010-01-01','2011-01-01')
		large_range = ('2009-01-01','2012-01-01')

		smallrange_qs = testmodels.Person.objects.filter(contact__date__range=small_range)
		largerange_qs = testmodels.Person.objects.filter(contact__date__range=large_range)
		
		# One result per person since its not displaying anything
		qs = process_queryset(smallrange_qs)
		self.assertEquals(len(qs),3)

		# Same
		qs = process_queryset(testmodels.Person.objects.filter(contact__date__range=large_range))
		self.assertEquals(len(qs),4)

		# One result per contact, but its still one per person
		qs = process_queryset(smallrange_qs,display_fields=['contact__date'])
		self.assertEquals(len(qs),3)

		# Same but check aggregated hours
		qs = process_queryset(smallrange_qs,display_fields=['contact__hours'])
		self.assertEquals(qs.aggregate(Sum('contact__hours'))['contact__hours__sum'],12)

		# One result per contact
		qs = process_queryset(largerange_qs,display_fields=['contact__date'])
		self.assertEquals(len(qs),8)

		qs = process_queryset(largerange_qs,display_fields=['contact__hours'])
		self.assertEquals(qs.aggregate(Sum('contact__hours'))['contact__hours__sum'],54)

		# Annotation
		anno_q = testmodels.Person.objects.annotate(Max('contact__date'))
		qs = process_queryset(anno_q)
		self.assertEquals(len(qs),5)

		# Repeating above, just with annotation. Things should return the same results
		qs = process_queryset(smallrange_qs.annotate(Max('contact__date')))
		self.assertEquals(len(qs),3)

		qs = process_queryset(largerange_qs.annotate(Max('contact__date')))
		self.assertEquals(len(qs),4)

		qs = process_queryset(smallrange_qs.annotate(Max('contact__date')),display_fields=['contact__date'])
		self.assertEquals(len(qs),3)

		#These next tests will fail because in django extra() doesn't currently play nice with aggregates

		"""
Ejemplo n.º 3
0
 def get_results(self, request, queryset, display_fields=None):
     filter = self.filterset_class(
         request.session.get("%s-report:filter_criteria_GET" % self.app_label), queryset=queryset
     )
     self._results = process_queryset(filter.qs, display_fields=display_fields)
     return self._results
Ejemplo n.º 4
0
    def test_results(self):
        """
		Our fixtures contain 5 people, 3 of whom have each 2 contacts, one inside small_range and one outside.
		One who has only large_range contacts.
		One who has no contacts.

		The sequence hours for the contacts are fibonacci
		"""

        # Dead simple
        qs = process_queryset(testmodels.Person.objects.all())
        self.assertEquals(len(qs), 5)

        small_range = ('2010-01-01', '2011-01-01')
        large_range = ('2009-01-01', '2012-01-01')

        smallrange_qs = testmodels.Person.objects.filter(
            contact__date__range=small_range)
        largerange_qs = testmodels.Person.objects.filter(
            contact__date__range=large_range)

        # One result per person since its not displaying anything
        qs = process_queryset(smallrange_qs)
        self.assertEquals(len(qs), 3)

        # Same
        qs = process_queryset(
            testmodels.Person.objects.filter(contact__date__range=large_range))
        self.assertEquals(len(qs), 4)

        # One result per contact, but its still one per person
        qs = process_queryset(smallrange_qs, display_fields=['contact__date'])
        self.assertEquals(len(qs), 3)

        # Same but check aggregated hours
        qs = process_queryset(smallrange_qs, display_fields=['contact__hours'])
        self.assertEquals(
            qs.aggregate(Sum('contact__hours'))['contact__hours__sum'], 12)

        # One result per contact
        qs = process_queryset(largerange_qs, display_fields=['contact__date'])
        self.assertEquals(len(qs), 8)

        qs = process_queryset(largerange_qs, display_fields=['contact__hours'])
        self.assertEquals(
            qs.aggregate(Sum('contact__hours'))['contact__hours__sum'], 54)

        # Annotation
        anno_q = testmodels.Person.objects.annotate(Max('contact__date'))
        qs = process_queryset(anno_q)
        self.assertEquals(len(qs), 5)

        # Repeating above, just with annotation. Things should return the same results
        qs = process_queryset(smallrange_qs.annotate(Max('contact__date')))
        self.assertEquals(len(qs), 3)

        qs = process_queryset(largerange_qs.annotate(Max('contact__date')))
        self.assertEquals(len(qs), 4)

        qs = process_queryset(smallrange_qs.annotate(Max('contact__date')),
                              display_fields=['contact__date'])
        self.assertEquals(len(qs), 3)

        #These next tests will fail because in django extra() doesn't currently play nice with aggregates
        """