oops (accidents can happen)
@@ -40,6 +40,23 @@ class PartnersFilterView(FilterView):
+class PartnersFilterView(FilterView):
+ model = Partner
+
+ def get_queryset(self):
+ # The ordering here is useful primarily to people familiar with the
+ # English alphabet. :/
+ if self.request.user.is_staff:
+ messages.add_message(self.request, messages.INFO,
+ # Translators: Staff members can see partners on the Browse page (https://wikipedialibrary.wmflabs.org/partners/) which are hidden from other users.
+ _('Because you are a staff member, this page may include '
+ 'Partners who are not yet available to all users.'))
+ return Partner.even_not_available.order_by('company_name')
+ else:
+ return Partner.objects.order_by('company_name')
+
+
+
class PartnersDetailView(DetailView):
model = Partner
@@ -69,6 +86,38 @@ class PartnersDetailView(DetailView):
context['total_apps_approved_or_sent'] = context['total_apps_approved'] + context['total_apps_sent']
+ # 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_stream'] = {}
+ context['stream_unique_accepted'] = {}
+
+ for stream in partner_streams:
+ if stream.accounts_available is not None:
+ 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_stream'][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_accounts_available_stream'] = None
+ context['stream_unique_accepted'] = None
+
+ if partner.accounts_available is not None:
+ context['total_accounts_available_partner'] = partner.accounts_available - context['total_apps_approved_or_sent']
+
context['unique_users'] = User.objects.filter(
editor__applications__partner=partner).distinct().count()
