diff --git a/wildlifelicensing/apps/applications/mixins.py b/wildlifelicensing/apps/applications/mixins.py index d39984fc16..2e207c2aa8 100755 --- a/wildlifelicensing/apps/applications/mixins.py +++ b/wildlifelicensing/apps/applications/mixins.py @@ -1,3 +1,5 @@ +import datetime + from django.core.urlresolvers import reverse_lazy from django.contrib.auth.mixins import UserPassesTestMixin @@ -9,7 +11,7 @@ class UserCanEditApplicationMixin(UserPassesTestMixin): """ CBV mixin that check that the user is the applicant and that the status of the application is in editable mode. - This mixin assume that the url contains the pk of the application on 2nd position. + If the user is not logged-in it redirects to the login page, else it throws a 403 Officers can edit an application """ @@ -25,7 +27,7 @@ def get_application(self): def test_func(self): """ - implementation of the UserPassesTestMixin test_func + implementation of the UserCanEditApplicationMixin test_func """ user = self.request.user if not user.is_authenticated(): @@ -41,6 +43,83 @@ def test_func(self): return True +class UserCanRenewApplicationMixin(UserPassesTestMixin): + """ + CBV mixin that check that the user is the applicant and that the application is renewable. + + If the user is not logged-in it redirects to the login page, else it throws a 403 + Officers can edit an application + """ + login_url = reverse_lazy('home') + permission_denied_message = "You don't have the permission to access this resource." + raise_exception = True + + def get_application(self): + if self.args: + return Application.objects.filter(licence=self.args[0]).first() + else: + return None + + def test_func(self): + """ + implementation of the UserCanRenewApplicationMixin test_func + """ + user = self.request.user + if not user.is_authenticated(): + self.raise_exception = False + return False + if is_officer(user): + return True + self.raise_exception = True + application = self.get_application() + if application is not None: + if application.applicant != user: + return False + + expiry_days = (application.licence.end_date - datetime.date.today()).days + return expiry_days <= 30 and application.licence.is_renewable + else: + return False + + +class UserCanAmendApplicationMixin(UserPassesTestMixin): + """ + CBV mixin that check that the user is the applicant and that the application is amendable. + + If the user is not logged-in it redirects to the login page, else it throws a 403 + Officers can edit an application + """ + login_url = reverse_lazy('home') + permission_denied_message = "You don't have the permission to access this resource." + raise_exception = True + + def get_application(self): + if self.args: + return Application.objects.filter(licence=self.args[0]).first() + else: + return None + + def test_func(self): + """ + implementation of the UserCanAmendApplicationMixin test_func + """ + user = self.request.user + if not user.is_authenticated(): + self.raise_exception = False + return False + if is_officer(user): + return True + self.raise_exception = True + application = self.get_application() + if application is not None: + if application.applicant != user: + return False + + return application.licence.end_date >= datetime.date.today() + else: + return False + + class CanPerformAssessmentMixin(UserPassesTestMixin): """ CBV mixin that check the 'editability' of assessment that the user is a assessor and that he/she belongs to the right assessor group. @@ -74,7 +153,7 @@ def test_func(self): class UserCanViewApplicationMixin(UserPassesTestMixin): """ - CBV mixin that check that the user is the applicant or an officer and that the status of the + CBV mixin that check that the user is the applicant or an officer and that the status of the application is in approved mode. If the user is not logged-in it redirects to the login page, else it throws a 403 """ diff --git a/wildlifelicensing/apps/applications/models.py b/wildlifelicensing/apps/applications/models.py index 25be6dbb8a..1f5a186944 100755 --- a/wildlifelicensing/apps/applications/models.py +++ b/wildlifelicensing/apps/applications/models.py @@ -127,8 +127,8 @@ def can_user_view(self): @property def is_senior_offer_applicable(self): return self.licence_type.senior_applicable and \ - self.applicant.is_senior and \ - bool(self.applicant.senior_card) + self.applicant.is_senior and \ + bool(self.applicant.senior_card) def log_user_action(self, action, request): return ApplicationUserAction.log_action(self, action, request.user) diff --git a/wildlifelicensing/apps/applications/static/wl/css/application.css b/wildlifelicensing/apps/applications/static/wl/css/applications.css similarity index 98% rename from wildlifelicensing/apps/applications/static/wl/css/application.css rename to wildlifelicensing/apps/applications/static/wl/css/applications.css index 8faf6dc790..ab9a785724 100755 --- a/wildlifelicensing/apps/applications/static/wl/css/application.css +++ b/wildlifelicensing/apps/applications/static/wl/css/applications.css @@ -29,9 +29,10 @@ hr { a { cursor: pointer; -} +}intro /* enter details / preview */ +{% load bootstrap3 %} #sectionList > ul > .active { font-weight: bold; diff --git a/wildlifelicensing/apps/applications/templates/wl/applications_base.html b/wildlifelicensing/apps/applications/templates/wl/applications_base.html new file mode 100644 index 0000000000..140a052f75 --- /dev/null +++ b/wildlifelicensing/apps/applications/templates/wl/applications_base.html @@ -0,0 +1,18 @@ +{% extends 'wl/base.html' %} + +{% load static %} + +{% block extra_css %} + +{% endblock %} + +{% block intro %} +
+ The application process is now complete and your application is now under review. Please allow up to 20 working days for processing. You can see the status of the application + on the dashboard and view a read-only version of the application details. You may receive requests for amendments to the application, at which + point you will be able to modify the content and resubmit. +
+- The application process is now complete and your application is now under review. Please allow up to 20 working days for processing. You can see the status of the application - on the dashboard and view a read-only version of the application details. You may receive requests for amendments to the application, at which - point you will be able to modify the content and resubmit. -
{% if show_invoice %}Note that if your licence requires payment, the invoice must be paid before the licence can be issued. You can download the invoice from the links below. diff --git a/wildlifelicensing/apps/applications/templates/wl/entry/create_select_customer.html b/wildlifelicensing/apps/applications/templates/wl/entry/create_select_customer.html index 10f2ea4a93..f3599bf17a 100755 --- a/wildlifelicensing/apps/applications/templates/wl/entry/create_select_customer.html +++ b/wildlifelicensing/apps/applications/templates/wl/entry/create_select_customer.html @@ -1,4 +1,4 @@ -{% extends 'wl/base.html' %} +{% extends 'wl/applications_base.html' %} {% load static %} @@ -9,7 +9,7 @@ - + {{ block.super }} {% endblock %} {% block requirements %} @@ -33,16 +33,13 @@
- Select or create the customer for whom the application is being applied on behalf of. -