Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions TWLight/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from TWLight.resources.models import Partner, Stream
from TWLight.users.models import Editor

class ValidApplicationsManager(models.Manager):
def get_queryset(self):
return super(ValidApplicationsManager, self).get_queryset(
).exclude(status=Application.INVALID)

class Application(models.Model):
class Meta:
Expand All @@ -24,12 +28,16 @@ class Meta:
verbose_name_plural = 'applications'
ordering = ['-date_created', 'editor', 'partner']

# Managers defined here
include_invalid = models.Manager()
objects = ValidApplicationsManager()

PENDING = 0
QUESTION = 1
APPROVED = 2
NOT_APPROVED = 3
SENT = 4
INVALID = 5

STATUS_CHOICES = (
# Translators: This is the status of an application that has not yet been reviewed.
Expand All @@ -42,11 +50,13 @@ class Meta:
(NOT_APPROVED, _('Not approved')),
# Translators: This is the status of an application that has been sent to a partner.
(SENT, _('Sent to partner')),
# Translators: This is the status of an application that has been marked as invalid, therefore not as such declined.
(INVALID, _('Invalid')),
)

# This list should contain all statuses that are the end state of an
# Application - statuses which are not expected to be further modified.
FINAL_STATUS_LIST = [APPROVED, NOT_APPROVED, SENT]
FINAL_STATUS_LIST = [APPROVED, NOT_APPROVED, SENT, INVALID]

status = models.IntegerField(choices=STATUS_CHOICES, default=PENDING)
# Moved from auto_now_add=True so that we can set the date for import.
Expand Down Expand Up @@ -155,6 +165,7 @@ def renew(self):

LABELMAKER = {
PENDING: '-primary',
INVALID: '-danger',
QUESTION: '-warning',
APPROVED: '-success',
NOT_APPROVED: '-danger',
Expand Down Expand Up @@ -232,7 +243,7 @@ def get_num_days_open(self):
if self.status in [self.PENDING, self.QUESTION]:
return (date.today() - self.date_created).days
else:
assert self.status in [self.APPROVED, self.NOT_APPROVED, self.SENT]
assert self.status in [self.APPROVED, self.NOT_APPROVED, self.SENT, self.INVALID]
return (self.date_closed - self.date_created).days


Expand Down
12 changes: 8 additions & 4 deletions TWLight/applications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,8 @@ def setUpClass(cls):
ApplicationFactory(status=Application.NOT_APPROVED)
ApplicationFactory(status=Application.NOT_APPROVED)
ApplicationFactory(status=Application.NOT_APPROVED)
ApplicationFactory(status=Application.INVALID)
ApplicationFactory(status=Application.INVALID)

# Make sure there are some up-for-renewal querysets, too.
ApplicationFactory(status=Application.PENDING, parent=parent)
Expand Down Expand Up @@ -1510,7 +1512,7 @@ def test_list_rejected_authorization(self):
def test_list_rejected_object_visibility(self):
url = reverse('applications:list_rejected')
queryset = Application.objects.filter(
status=Application.NOT_APPROVED)
status__in=[Application.NOT_APPROVED, Application.INVALID])
self._base_test_object_visibility(url,
views.ListRejectedApplicationsView, queryset)

Expand Down Expand Up @@ -1557,7 +1559,7 @@ def test_list_approved_object_visibility(self):
def test_list_rejected_object_visibility(self):
url = reverse('applications:list_rejected')
queryset = Application.objects.filter(
status=Application.NOT_APPROVED)
status__in=[Application.NOT_APPROVED, Application.INVALID])
self._base_test_deleted_object_visibility(url,
views.ListRejectedApplicationsView, queryset)

Expand Down Expand Up @@ -2580,7 +2582,8 @@ def test_missing_params_raise_http_bad_request(self):
assert 6 not in [Application.PENDING,
Application.QUESTION,
Application.APPROVED,
Application.NOT_APPROVED]
Application.NOT_APPROVED,
Application.INVALID]

response = self.client.post(self.url,
data={'applications': 1, 'batch_status': 6}, follow=True)
Expand All @@ -2602,7 +2605,8 @@ def test_bogus_applications_parameter_handled(self):
assert 3 in [Application.PENDING,
Application.QUESTION,
Application.APPROVED,
Application.NOT_APPROVED]
Application.NOT_APPROVED,
Application.INVALID]

# Make sure the applications parameter actually is bogus.
assert Application.objects.filter(pk=2).count() == 0
Expand Down
11 changes: 6 additions & 5 deletions TWLight/applications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,13 @@ class ListRejectedApplicationsView(_BaseListApplicationView):

def get_queryset(self):
if self.request.user.is_superuser:
return Application.objects.filter(
status=Application.NOT_APPROVED,
return Application.include_invalid.filter(
status__in=[Application.NOT_APPROVED, Application.INVALID],
editor__isnull=False
).order_by('date_closed', 'partner')
else:
return Application.objects.filter(
status=Application.NOT_APPROVED,
return Application.include_invalid.filter(
status__in=[Application.NOT_APPROVED, Application.INVALID],
partner__coordinator__pk=self.request.user.pk,
editor__isnull=False
).order_by('date_closed', 'partner')
Expand Down Expand Up @@ -803,7 +803,8 @@ def post(self, request, *args, **kwargs):
Application.QUESTION,
Application.APPROVED,
Application.NOT_APPROVED,
Application.SENT]
Application.SENT,
Application.INVALID]
except (AssertionError, ValueError):
# ValueError will be raised if the status cannot be cast to int.
logger.exception('Did not find valid data for batch editing')
Expand Down
2 changes: 1 addition & 1 deletion TWLight/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_context_data(self, **kwargs):
context = super(EditorDetailView, self).get_context_data(**kwargs)
editor = self.get_object()
context['editor'] = editor # allow for more semantic templates
context['object_list'] = editor.applications.all().order_by('status', '-date_closed')
context['object_list'] = editor.applications.model.include_invalid.all().order_by('status', '-date_closed')
context['form'] = EditorUpdateForm(instance=editor)
context['language_form'] = SetLanguageForm(user=self.request.user)

Expand Down