views now supports no account available warning
@@ -18,6 +18,7 @@ from urlparse import urlparse
from django import forms
from django.conf import settings
from django.contrib import messages
+from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse, reverse_lazy
@@ -37,7 +38,7 @@ from TWLight.view_mixins import (CoordinatorOrSelf,
SelfOnly,
DataProcessingRequired,
NotDeleted)
-from TWLight.resources.models import Partner
+from TWLight.resources.models import Partner, Stream
from TWLight.users.groups import get_coordinators
from TWLight.users.models import Editor
@@ -867,12 +868,47 @@ class SendReadyApplicationsView(CoordinatorsOnly, DetailView):
editor__user__groups__name='restricted'
)
app_outputs = {}
+ stream_outputs = []
for app in apps:
app_outputs[app] = get_output_for_application(app)
+ stream_outputs.append(app.specific_stream)
context['app_outputs'] = app_outputs
+ # This part checks to see if there are applications from stream(s) with no accounts available.
+ # Additionally, supports send_partner template with total approved/sent applications.
+ partner = self.get_object()
+
+ context['total_apps_approved'] = Application.objects.filter(
+ partner=partner, status=Application.APPROVED).count()
+
+ context['total_apps_sent'] = Application.objects.filter(
+ partner=partner, status=Application.SENT).count()
+
+ context['total_apps_approved_or_sent'] = context['total_apps_approved'] + context['total_apps_sent']
+
+ partner_streams = Stream.objects.filter(partner=partner)
+ if partner_streams.count() > 0:
+ unavailable_streams = []
+
+ for stream in partner_streams:
+ 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()
+ after_distribution = stream.accounts_available - total_apps_approved_or_sent_stream - stream_outputs.count(stream)
+
+ context['total_apps_approved_or_sent_stream'] = total_apps_approved_or_sent_stream
+
+ if after_distribution < 0 and (stream in stream_outputs):
+ unavailable_streams.append(stream.name)
+
+ context['unavailable_streams'] = unavailable_streams
+
+ else:
+ context['total_apps_approved_or_sent_stream'] = None
+
return context
