latest app shouldn't be unapproved
@@ -37,6 +37,7 @@ import urllib.request, urllib.parse, urllib.error
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
+from django.db.models import Q
from django.utils.timezone import now
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
@@ -563,16 +564,25 @@ class Authorization(models.Model):
)
def get_latest_app(self):
+ """
+ Returns the latest application for a corresponding authorization,
+ except when the status of the application is NOT_APPROVED, in which
+ case returns the previous not NOT_APPROVED application.
+ """
from TWLight.applications.models import Application
try:
if self.stream:
return Application.objects.filter(
- specific_stream=self.stream, editor=self.user.editor
+ ~Q(status=Application.NOT_APPROVED),
+ specific_stream=self.stream,
+ editor=self.user.editor,
).latest("id")
else:
return Application.objects.filter(
- partner=self.partner, editor=self.user.editor
+ ~Q(status=Application.NOT_APPROVED),
+ partner=self.partner,
+ editor=self.user.editor,
).latest("id")
except Application.DoesNotExist:
return None
