collate if blocks, rm redundancies, perform calcs
@@ -63,22 +63,36 @@ class PartnersDetailView(DetailView):
# This if else block supports the template with the number of accounts available
partner_streams = Stream.objects.filter(partner=partner)
+ context['partner_streams'] = partner_streams
+
if partner_streams.count() > 0:
context['total_accounts_available_current'] = {}
+ context['stream_unique_accepted'] = {}
+
for stream in partner_streams:
- context['total_apps_approved_or_sent_stream'] = User.objects.filter(
+ total_apps_approved_or_sent_stream = User.objects.filter(
editor__applications__partner=partner,
editor__applications__status__in=(Application.APPROVED, Application.SENT),
editor__applications__specific_stream=stream).count()
total_accounts_available = stream.accounts_available
- context['total_accounts_available'] = total_accounts_available
- context['total_accounts_available_current'][stream.name] = context['total_accounts_available'] - context['total_apps_approved_or_sent_stream']
+ context['total_accounts_available_current'][stream.name] = total_accounts_available - total_apps_approved_or_sent_stream
+
+ stream_unique_accepted = User.objects.filter(
+ editor__applications__partner=partner,
+ editor__applications__status__in=(Application.APPROVED, Application.SENT),
+ editor__applications__specific_stream=stream).distinct().count()
+ context['stream_unique_accepted'][stream.name] = stream_unique_accepted
+
else:
- context['total_apps_approved_or_sent_stream'] = None
+ context['partner_streams'] = None
+
+ context['stream_unique_accepted'] = None
+
+ context['total_accounts_available'] = partner.accounts_available
- context['negation_total_apps_approved_or_sent'] = - context['total_apps_approved_or_sent']
+ context['total_accounts_available_current'] = context['total_accounts_available'] - context['total_apps_approved_or_sent']
context['unique_users'] = User.objects.filter(
editor__applications__partner=partner).distinct().count()
@@ -147,18 +161,6 @@ class PartnersDetailView(DetailView):
context['multiple_open_apps'] = False
context['open_app_pk'] = open_apps[0].pk
- partner_streams = Stream.objects.filter(partner=partner)
- if partner_streams.count() > 0:
- context['stream_unique_accepted'] = {}
- for stream in partner_streams:
- stream_unique_accepted = User.objects.filter(
- editor__applications__partner=partner,
- editor__applications__status__in=(Application.APPROVED, Application.SENT),
- editor__applications__specific_stream=stream).distinct().count()
- context['stream_unique_accepted'][stream.name] = stream_unique_accepted
- else:
- context['stream_unique_accepted'] = None
-
return context
