Browse Source

Show offer reference in JSON endpoint.

opi 8 years ago
parent
commit
b39654c07b
2 changed files with 9 additions and 5 deletions
  1. 1 1
      coin/offers/models.py
  2. 8 4
      coin/offers/views.py

+ 1 - 1
coin/offers/models.py

@@ -96,7 +96,7 @@ class OfferSubscriptionQuerySet(models.QuerySet):
     def offer_summary(self):
     def offer_summary(self):
         """ Agregates as a count of subscriptions per offer
         """ Agregates as a count of subscriptions per offer
         """
         """
-        return self.values('offer__name').annotate(
+        return self.values('offer__name', 'offer__reference').annotate(
             num_subscriptions=Count('offer'))
             num_subscriptions=Count('offer'))
 
 
 
 

+ 8 - 4
coin/offers/views.py

@@ -28,7 +28,7 @@ class ConfigurationRedirectView(RedirectView):
 
 
 # @cache_control(max_age=7200)
 # @cache_control(max_age=7200)
 def subscription_count_json(request):
 def subscription_count_json(request):
-    output = {}
+    output = []
 
 
     # Get date form url, or set default
     # Get date form url, or set default
     date = request.GET.get('date', datetime.date.today())
     date = request.GET.get('date', datetime.date.today())
@@ -41,9 +41,13 @@ def subscription_count_json(request):
             return HttpResponseServerError("Incorrect date format, should be YYYY-MM-DD")
             return HttpResponseServerError("Incorrect date format, should be YYYY-MM-DD")
 
 
     # Get current offer subscription
     # Get current offer subscription
-    offersubscriptions = OfferSubscription.objects.running(date).offer_summary()
+    offersubscriptions = list(OfferSubscription.objects.running(date).offer_summary())
     for offersub in offersubscriptions:
     for offersub in offersubscriptions:
-        output[offersub['offer__name']] = offersub['num_subscriptions']
+        output.append({
+            'reference' : offersub['offer__reference'],
+            'name' : offersub['offer__name'],
+            'subscriptions_count' : offersub['num_subscriptions']
+        })
 
 
     # Return JSON
     # Return JSON
-    return JsonResponse(output)
+    return JsonResponse(output, safe=False)