Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)

        if is_officer(self.request.user):
            kwargs['customer'] = application.applicant

            kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                               fromm=self.request.user.get_full_name())
        else:
            kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(payment_utils.
                                                                          get_application_payment_status(application))
        if application.processing_status == 'declined':
            message = "This application has been declined."
            details = ApplicationDeclinedDetails.objects.filter(application=application).first()
            if details and details.reason:
                message += "<br/>Reason:<br/>{}".format(details.reason.replace('\n', '<br/>'))
                kwargs['application']['declined_reason'] = details.reason
            messages.error(self.request, message)

        return super(ViewReadonlyView, self).get_context_data(**kwargs)
Exemplo n.º 2
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        assessment = get_object_or_404(Assessment, pk=self.args[1])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['form_structure'] = application.licence_type.application_schema

        kwargs['assessment'] = serialize(assessment, post_hook=format_assessment)

        kwargs['other_assessments'] = serialize(Assessment.objects.filter(application=application).
                                                exclude(id=assessment.id).order_by('id'), posthook=format_assessment)

        assessors = [{'id': assessor.id, 'text': assessor.get_full_name()} for assessor in
                     assessment.assessor_group.members.all().order_by('first_name')]
        assessors.insert(0, {'id': 0, 'text': 'Unassigned'})

        kwargs['assessors'] = assessors

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())

        return super(EnterConditionsAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 3
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        kwargs['application'] = serialize(application,
                                          posthook=format_application)

        kwargs['assessments'] = serialize(
            Assessment.objects.filter(application=application),
            posthook=format_assessment)

        kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(
            payment_utils.get_application_payment_status(application))

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        return super(ViewReadonlyOfficerView, self).get_context_data(**kwargs)
Exemplo n.º 4
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        kwargs['application'] = serialize(application,
                                          posthook=format_application)
        kwargs['form_structure'] = application.licence_type.application_schema

        assessment = get_object_or_404(Assessment, pk=self.args[1])

        kwargs['assessment'] = serialize(assessment,
                                         post_hook=format_assessment)

        kwargs['other_assessments'] = serialize(Assessment.objects.filter(
            application=application).exclude(id=assessment.id).order_by('id'),
                                                posthook=format_assessment)

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        return super(ViewReadonlyAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 5
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['form_structure'] = application.licence_type.application_schema

        assessment = get_object_or_404(Assessment, pk=self.args[1])

        kwargs['assessment'] = serialize(assessment, post_hook=format_assessment,exclude=['application','applicationrequest_ptr'])

        kwargs['other_assessments'] = serialize(Assessment.objects.filter(application=application).
                                                exclude(id=assessment.id).order_by('id'), posthook=format_assessment,exclude=['application','applicationrequest_ptr'])

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())

        if application.processing_status == 'declined':
            message = "This application has been declined."
            details = ApplicationDeclinedDetails.objects.filter(application=application).first()
            if details and details.reason:
                message += "<br/>Reason:<br/>{}".format(details.reason.replace('\n', '<br/>'))
                kwargs['application']['declined_reason'] = details.reason
            messages.error(self.request, message)

        return super(ViewReadonlyAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 6
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        if 'data' not in kwargs:
            kwargs['data'] = self._build_data(self.request, application)
        kwargs['id_request_form'] = IDRequestForm(application=application, officer=self.request.user)
        kwargs['returns_request_form'] = ReturnsRequestForm(application=application, officer=self.request.user)
        kwargs['amendment_request_form'] = AmendmentRequestForm(application=application, officer=self.request.user)

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())

        return super(ProcessView, self).get_context_data(**kwargs)
Exemplo n.º 7
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        if 'data' not in kwargs:
            kwargs['data'] = self._build_data(self.request, application)
        kwargs['id_request_form'] = IDRequestForm(application=application, officer=self.request.user)
        kwargs['returns_request_form'] = ReturnsRequestForm(application=application, officer=self.request.user)
        kwargs['amendment_request_form'] = AmendmentRequestForm(application=application, officer=self.request.user)
        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())
        kwargs['application_declined_details_form'] = \
            ApplicationDeclinedDetailsForm(application=application, officer=self.request.user)

        return super(ProcessView, self).get_context_data(**kwargs)
Exemplo n.º 8
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application,posthook=format_application,
                                            related={
                                                'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                'applicant_profile':{'fields':['email','id','institution','name']},
                                                'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                'licence':{'related':{
                                                   'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
						       'exclude': ['postal_address']}
                                                   },'exclude':['holder','issuer','profile','licence_ptr']}
                                            })
        kwargs['form_structure'] = application.licence_type.application_schema

        assessment = get_object_or_404(Assessment, pk=self.args[1])

        kwargs['assessment'] = serialize(assessment, post_hook=format_assessment,exclude=['application','applicationrequest_ptr'],
                                                related={'assessor_group':{'related':{'members':{'exclude':['residential_address']}}},
                                                    'officer':{'exclude':['residential_address']},
                                                    'assigned_assessor':{'exclude':['residential_address']}})


        kwargs['other_assessments'] = serialize(Assessment.objects.filter(application=application).exclude(id=assessment.id).order_by('id'),
                                                posthook=format_assessment,exclude=['application','applicationrequest_ptr'],
                                                related={'assessor_group':{'related':{'members':{'exclude':['residential_address']}}},
                                                    'officer':{'exclude':['residential_address']},
                                                    'assigned_assessor':{'exclude':['residential_address']}})


        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())

        if application.processing_status == 'declined':
            message = "This application has been declined."
            details = ApplicationDeclinedDetails.objects.filter(application=application).first()
            if details and details.reason:
                message += "<br/>Reason:<br/>{}".format(details.reason.replace('\n', '<br/>'))
                kwargs['application']['declined_reason'] = details.reason
            messages.error(self.request, message)

        return super(ViewReadonlyAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 9
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        assessment = get_object_or_404(Assessment, pk=self.args[1])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        #kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['application'] = serialize(application,posthook=format_application,
                                            related={
                                                'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                'applicant_profile':{'fields':['email','id','institution','name']},
                                                'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                'licence':{'related':{
                                                   'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
						       'exclude': ['postal_address']}
                                                   },'exclude':['holder','issuer','profile','licence_ptr']}
                                            })
        kwargs['form_structure'] = application.licence_type.application_schema

        kwargs['assessment'] = serialize(assessment, post_hook=format_assessment,
                                            exclude=['application','applicationrequest_ptr'],
                                            related={'assessor_group':{'related':{'members':{'exclude':['residential_address']}}},
                                                'officer':{'exclude':['residential_address']},
                                                'assigned_assessor':{'exclude':['residential_address']}})

        kwargs['other_assessments'] = serialize(Assessment.objects.filter(application=application).
						exclude(id=assessment.id).order_by('id'),
                                                posthook=format_assessment,exclude=['application','applicationrequest_ptr'],
                                                related={'assessor_group':{'related':{'members':{'exclude':['residential_address']}}},
                                                    'officer':{'exclude':['residential_address']},
                                                    'assigned_assessor':{'exclude':['residential_address']}})

        assessors = [{'id': assessor.id, 'text': assessor.get_full_name()} for assessor in
                     assessment.assessor_group.members.all().order_by('first_name')]
        assessors.insert(0, {'id': 0, 'text': 'Unassigned'})

        kwargs['assessors'] = assessors

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())

        return super(EnterConditionsAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 10
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['form_structure'] = application.licence_type.application_schema
        kwargs['assessments'] = serialize(Assessment.objects.filter(application=application), posthook=format_assessment)

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())

        kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(payment_utils.
                                                                      get_application_payment_status(application))

        return super(EnterConditionsView, self).get_context_data(**kwargs)
Exemplo n.º 11
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application,posthook=format_application,
                                            related={
                                                'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                'applicant_profile':{'fields':['email','id','institution','name']},
                                                'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                'licence':{'related':{
                                                   'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
						       'exclude': ['postal_address']}
                                                   },'exclude':['holder','issuer','profile','licence_ptr']}
                                            })

        kwargs['assessments'] = serialize(Assessment.objects.filter(application=application),
                                             posthook=format_assessment,exclude=['application','applicationrequest_ptr'],
                                             related={'assessor_group':{'related':{'members':{'exclude':['residential_address']}}},
                                                 'officer':{'exclude':['residential_address']},
                                                 'assigned_assessor':{'exclude':['residential_address']}})


        kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(payment_utils.
                                                                      get_application_payment_status(application))

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                           fromm=self.request.user.get_full_name())

        if application.processing_status == 'declined':
            details = ApplicationDeclinedDetails.objects.filter(application=application).first()
            if details and details.reason:
                kwargs['application']['declined_reason'] = details.reason
        return super(ViewReadonlyOfficerView, self).get_context_data(**kwargs)
Exemplo n.º 12
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)

        if is_officer(self.request.user):
            kwargs['customer'] = application.applicant

            kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())
        else:
            kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(payment_utils.
                                                                          get_application_payment_status(application))

        return super(ViewReadonlyView, self).get_context_data(**kwargs)
Exemplo n.º 13
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        #kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['application'] = serialize(
            application,
            posthook=format_application,
            related={
                'applicant': {
                    'exclude': [
                        'residential_address', 'postal_address',
                        'billing_address'
                    ]
                },
                'applicant_profile': {
                    'fields': ['email', 'id', 'institution', 'name']
                }
            })
        kwargs['form_structure'] = application.licence_type.application_schema
        kwargs['assessments'] = serialize(
            Assessment.objects.filter(application=application),
            posthook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'])

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(
            payment_utils.get_application_payment_status(application))

        return super(EnterConditionsView, self).get_context_data(**kwargs)
Exemplo n.º 14
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application,posthook=format_application,
                                            related={
                                                'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                'applicant_profile':{'fields':['email','id','institution','name']},
                                                'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                'licence':{'related':{
                                                   'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
						       'exclude': ['postal_address']}
                                                   },'exclude':['holder','issuer','profile','licence_ptr']}
                                            })

        if is_officer(self.request.user):
            kwargs['customer'] = application.applicant

            kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application),
                                                               fromm=self.request.user.get_full_name())
        else:
            kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(payment_utils.
                                                                          get_application_payment_status(application))
        if application.processing_status == 'declined':
            message = "This application has been declined."
            details = ApplicationDeclinedDetails.objects.filter(application=application).first()
            if details and details.reason:
                message += "<br/>Reason:<br/>{}".format(details.reason.replace('\n', '<br/>'))
                kwargs['application']['declined_reason'] = details.reason
            messages.error(self.request, message)

        return super(ViewReadonlyView, self).get_context_data(**kwargs)
Exemplo n.º 15
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        assessment = get_object_or_404(Assessment, pk=self.args[1])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(), '')

        kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['form_structure'] = application.licence_type.application_schema

        kwargs['assessment'] = serialize(assessment, post_hook=format_assessment)

        kwargs['other_assessments'] = serialize(Assessment.objects.filter(application=application).
                                                exclude(id=assessment.id).order_by('id'), posthook=format_assessment)

        kwargs['log_entry_form'] = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())

        return super(EnterConditionsAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 16
0
    def post(self, request, *args, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        is_save = request.POST.get('submissionType') == 'save'
        skip_required = is_save

        # get extract fields from licence if it exists, else extract from application data
        if application.licence is not None:
            issue_licence_form = IssueLicenceForm(request.POST,
                                                  instance=application.licence,
                                                  files=request.FILES,
                                                  skip_required=skip_required)
            extracted_fields = application.licence.extracted_fields
        else:
            issue_licence_form = IssueLicenceForm(request.POST,
                                                  files=request.FILES,
                                                  skip_required=skip_required)
            extracted_fields = extract_licence_fields(
                application.licence_type.application_schema, application.data)

        # update contents of extracted field based on posted data
        extracted_fields = update_licence_fields(extracted_fields,
                                                 request.POST)

        payment_status = payment_utils.get_application_payment_status(
            application)
        payment_status_verbose = payment_utils.PAYMENT_STATUSES.get(
            payment_status)

        log_entry_form = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        if issue_licence_form.is_valid():
            licence = issue_licence_form.save(commit=False)

            # save required fields that aren't contained in the form
            licence.licence_type = application.licence_type
            licence.profile = application.applicant_profile
            licence.holder = application.applicant
            licence.extracted_fields = extracted_fields
            licence.save()

            # clear re-form variants from application
            licence.variants.clear()
            for index, avl in enumerate(
                    application.variants.through.objects.filter(
                        application=application).order_by('order')):
                WildlifeLicenceVariantLink.objects.create(licence=licence,
                                                          variant=avl.variant,
                                                          order=index)

            # save m2m fields of licence (must be done after licence saved)
            issue_licence_form.save_m2m()

            application.licence = licence
            application.save()

            if is_save:
                messages.warning(request, 'Licence saved but not yet issued.')

                return render(
                    request,
                    self.template_name,
                    {
                        #'application': serialize(application, posthook=format_application),
                        'application':
                        serialize(
                            application,
                            posthook=format_application,
                            related={
                                'applicant': {
                                    'exclude': [
                                        'residential_address',
                                        'postal_address', 'billing_address'
                                    ]
                                },
                                'applicant_profile': {
                                    'fields':
                                    ['email', 'id', 'institution', 'name']
                                },
                                'previous_application': {
                                    'exclude': [
                                        'applicant', 'applicant_profile',
                                        'previous_application', 'licence'
                                    ]
                                },
                                'licence': {
                                    'related': {
                                        'holder': {
                                            'exclude': [
                                                'residential_address',
                                                'postal_address',
                                                'billing_address'
                                            ]
                                        },
                                        'issuer': {
                                            'exclude': [
                                                'residential_address',
                                                'postal_address',
                                                'billing_address'
                                            ]
                                        },
                                        'profile': {
                                            'related': {
                                                'user': {
                                                    'exclude': [
                                                        'residential_address',
                                                        'postal_address',
                                                        'billing_address'
                                                    ]
                                                }
                                            },
                                            'exclude': ['postal_address']
                                        }
                                    },
                                    'exclude': [
                                        'holder', 'issuer', 'profile',
                                        'licence_ptr'
                                    ]
                                }
                            }),
                        'issue_licence_form':
                        issue_licence_form,
                        'extracted_fields':
                        extracted_fields,
                        'payment_status':
                        payment_status_verbose,
                        'log_entry_form':
                        log_entry_form
                    })
            else:
                try:
                    self._issue_licence(request, application,
                                        issue_licence_form)
                except PaymentException as pe:
                    messages.error(request, pe.message)
                    return redirect(request.get_full_path())

                return redirect('wl_dashboard:home')
        else:
            messages.error(
                request,
                'Please fix the errors below before saving / issuing the licence.'
            )

            return render(
                request,
                self.template_name,
                {
                    #'application': serialize(application, posthook=format_application),
                    'application':
                    serialize(
                        application,
                        posthook=format_application,
                        related={
                            'applicant': {
                                'exclude': [
                                    'residential_address', 'postal_address',
                                    'billing_address'
                                ]
                            },
                            'applicant_profile': {
                                'fields':
                                ['email', 'id', 'institution', 'name']
                            },
                            'previous_application': {
                                'exclude': [
                                    'applicant', 'applicant_profile',
                                    'previous_application', 'licence'
                                ]
                            },
                            'licence': {
                                'related': {
                                    'holder': {
                                        'exclude': [
                                            'residential_address',
                                            'postal_address', 'billing_address'
                                        ]
                                    },
                                    'issuer': {
                                        'exclude': [
                                            'residential_address',
                                            'postal_address', 'billing_address'
                                        ]
                                    },
                                    'profile': {
                                        'related': {
                                            'user': {
                                                'exclude': [
                                                    'residential_address',
                                                    'postal_address',
                                                    'billing_address'
                                                ]
                                            }
                                        },
                                        'exclude': ['postal_address']
                                    }
                                },
                                'exclude':
                                ['holder', 'issuer', 'profile', 'licence_ptr']
                            }
                        }),
                    'issue_licence_form':
                    issue_licence_form,
                    'extracted_fields':
                    extracted_fields,
                    'payment_status':
                    payment_status_verbose,
                    'log_entry_form':
                    log_entry_form
                })
Exemplo n.º 17
0
    def post(self, request, *args, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        payment_status = payment_utils.get_application_payment_status(
            application)

        if payment_status == payment_utils.PAYMENT_STATUS_AWAITING:
            messages.error(request,
                           'Payment is required before licence can be issued')

            return redirect(request.get_full_path())

        # do credit card payment if required
        if payment_status == payment_utils.PAYMENT_STATUS_CC_READY:
            payment_utils.invoke_credit_card_payment(application)

        original_issue_date = None
        if application.licence is not None:
            issue_licence_form = IssueLicenceForm(request.POST,
                                                  instance=application.licence,
                                                  files=request.FILES)
            original_issue_date = application.licence.issue_date
        else:
            issue_licence_form = IssueLicenceForm(request.POST,
                                                  files=request.FILES)

        if issue_licence_form.is_valid():
            licence = issue_licence_form.save(commit=False)

            licence.licence_type = application.licence_type

            licence.profile = application.applicant_profile
            licence.holder = application.applicant
            licence.issuer = request.user

            if application.previous_application is not None:
                licence.licence_number = application.previous_application.licence.licence_number

                # if licence is renewal, use previous licence's sequence number
                if licence.licence_sequence == 0:
                    licence.licence_sequence = application.previous_application.licence.licence_sequence

            if not licence.licence_number:
                licence.save(no_revision=True)
                licence.licence_number = '%s-%s' % (
                    str(licence.licence_type.pk).zfill(LICENCE_TYPE_NUM_CHARS),
                    str(licence.id).zfill(LICENCE_NUMBER_NUM_CHARS))

            licence.licence_sequence += 1

            licence_filename = 'licence-%s-%d.pdf' % (licence.licence_number,
                                                      licence.licence_sequence)

            licence.licence_document = create_licence_pdf_document(
                licence_filename, licence, application,
                request.build_absolute_uri(reverse('home')),
                original_issue_date)

            cover_letter_filename = 'cover-letter-%s-%d.pdf' % (
                licence.licence_number, licence.licence_sequence)

            licence.cover_letter_document = create_cover_letter_pdf_document(
                cover_letter_filename, licence,
                request.build_absolute_uri(reverse('home')))

            licence.save()

            licence.variants.clear()
            for index, avl in enumerate(
                    application.variants.through.objects.all().order_by(
                        'order')):
                WildlifeLicenceVariantLink.objects.create(licence=licence,
                                                          variant=avl.variant,
                                                          order=index)

            issue_licence_form.save_m2m()

            licence_issued.send(sender=self.__class__,
                                wildlife_licence=licence)

            application.customer_status = 'approved'
            application.processing_status = 'issued'
            application.licence = licence

            application.save()

            # The licence should be emailed to the customer if they applied for it online. If an officer entered
            # the application on their behalf, the licence needs to be posted to the user.

            # CC's and attachments
            # Rules for emails:
            #  If application lodged by proxy officer and there's a CC list: send email to CCs (to recipients = CCs)
            #  else send the email to customer and if there are CCs put them into the bccs of the email
            ccs = None
            if 'ccs' in issue_licence_form.cleaned_data and issue_licence_form.cleaned_data[
                    'ccs']:
                ccs = re.split('[,;]', issue_licence_form.cleaned_data['ccs'])
            attachments = []
            if request.FILES and 'attachments' in request.FILES:
                for _file in request.FILES.getlist('attachments'):
                    doc = Document.objects.create(file=_file, name=_file.name)
                    attachments.append(doc)
            if application.proxy_applicant is None:
                # customer applied online
                messages.success(
                    request,
                    'The licence has now been issued and sent as an email attachment to the '
                    'licencee.')
                send_licence_issued_email(licence,
                                          application,
                                          request,
                                          bcc=ccs,
                                          additional_attachments=attachments)
            else:
                # customer applied offline
                messages.success(
                    request,
                    'The licence has now been issued and must be posted to the licencee. Click '
                    'this link to show the licence <a href="{0}" target="_blank">Licence PDF'
                    '</a><img height="20px" src="{1}"></img> and this link to show the cover letter '
                    '<a href="{2}" target="_blank">Cover Letter PDF</a><img height="20px" src="{3}">'
                    '</img>'.format(licence.licence_document.file.url,
                                    static('wl/img/pdf.png'),
                                    licence.cover_letter_document.file.url,
                                    static('wl/img/pdf.png')))

            if ccs:
                send_licence_issued_email(licence,
                                          application,
                                          request,
                                          to=ccs,
                                          additional_attachments=attachments)
            return redirect('wl_dashboard:home')
        else:
            messages.error(request, issue_licence_form.errors)

            log_entry_form = ApplicationLogEntryForm(
                to=get_log_entry_to(application),
                fromm=self.request.user.get_full_name())

            return render(
                request, self.template_name, {
                    'application':
                    serialize(application, posthook=format_application),
                    'issue_licence_form':
                    issue_licence_form,
                    'log_entry_form':
                    log_entry_form
                })
Exemplo n.º 18
0
    def post(self, request, *args, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        payment_status = payment_utils.get_application_payment_status(application)

        if payment_status == payment_utils.PAYMENT_STATUS_AWAITING:
            messages.error(request, 'Payment is required before licence can be issued')

            return redirect(request.get_full_path())

        original_issue_date = None
        if application.licence is not None:
            issue_licence_form = IssueLicenceForm(request.POST, instance=application.licence, files=request.FILES)
            original_issue_date = application.licence.issue_date
            extracted_fields = application.licence.extracted_fields
        else:
            issue_licence_form = IssueLicenceForm(request.POST, files=request.FILES)
            extracted_fields = extract_licence_fields(application.licence_type.application_schema, application.data)

        # update contents of extracted field based on posted data
        extracted_fields = update_licence_fields(extracted_fields, request.POST)

        if issue_licence_form.is_valid():
            licence = issue_licence_form.save(commit=False)

            licence.licence_type = application.licence_type

            licence.profile = application.applicant_profile
            licence.holder = application.applicant
            licence.issuer = request.user

            previous_licence = None
            if application.previous_application is not None:
                previous_licence = application.previous_application.licence
                licence.licence_number = previous_licence.licence_number

                # if licence is renewal, start with previous licence's sequence number
                if licence.licence_sequence == 0:
                    licence.licence_sequence = previous_licence.licence_sequence

            if not licence.licence_number:
                licence.save(no_revision=True)
                licence.licence_number = '%s-%s' % (str(licence.licence_type.pk).zfill(LICENCE_TYPE_NUM_CHARS),
                                                    str(licence.id).zfill(LICENCE_NUMBER_NUM_CHARS))

            licence.licence_sequence += 1

            licence.extracted_fields = extracted_fields

            # reset renewal_sent flag in case of reissue
            licence.renewal_sent = False

            licence_filename = 'licence-%s-%d.pdf' % (licence.licence_number, licence.licence_sequence)

            licence.licence_document = create_licence_pdf_document(licence_filename, licence, application,
                                                                   request.build_absolute_uri(reverse('home')),
                                                                   original_issue_date)

            cover_letter_filename = 'cover-letter-%s-%d.pdf' % (licence.licence_number, licence.licence_sequence)

            licence.cover_letter_document = create_cover_letter_pdf_document(cover_letter_filename, licence,
                                                                             request.build_absolute_uri(reverse('home')))

            licence.save()

            if previous_licence is not None:
                previous_licence.replaced_by = licence
                previous_licence.save()

            licence.variants.clear()
            for index, avl in enumerate(application.variants.through.objects.all().order_by('order')):
                WildlifeLicenceVariantLink.objects.create(licence=licence, variant=avl.variant, order=index)

            issue_licence_form.save_m2m()

            licence_issued.send(sender=self.__class__, wildlife_licence=licence)

            application.customer_status = 'approved'
            application.processing_status = 'issued'
            application.licence = licence

            application.save()

            application.log_user_action(
                ApplicationUserAction.ACTION_ISSUE_LICENCE_.format(licence),
                request
            )

            # do credit card payment if required
            if payment_status == payment_utils.PAYMENT_STATUS_CC_READY:
                payment_utils.invoke_credit_card_payment(application)

            # The licence should be emailed to the customer if they applied for it online. If an officer entered
            # the application on their behalf, the licence needs to be posted to the user.

            # CC's and attachments
            # Rules for emails:
            #  If application lodged by proxy officer and there's a CC list: send email to CCs (to recipients = CCs)
            #  else send the email to customer and if there are CCs put them into the bccs of the email
            ccs = None
            if 'ccs' in issue_licence_form.cleaned_data and issue_licence_form.cleaned_data['ccs']:
                ccs = re.split('[,;]', issue_licence_form.cleaned_data['ccs'])
            attachments = []
            if request.FILES and 'attachments' in request.FILES:
                for _file in request.FILES.getlist('attachments'):
                    doc = Document.objects.create(file=_file, name=_file.name)
                    attachments.append(doc)
            if application.proxy_applicant is None:
                # customer applied online
                messages.success(request, 'The licence has now been issued and sent as an email attachment to the '
                                 'licencee.')
                send_licence_issued_email(licence, application, request, bcc=ccs, additional_attachments=attachments)
            else:
                # customer applied offline
                messages.success(request, 'The licence has now been issued and must be posted to the licencee. Click '
                                 'this link to show the licence <a href="{0}" target="_blank">Licence PDF'
                                 '</a><img height="20px" src="{1}"></img> and this link to show the cover letter '
                                 '<a href="{2}" target="_blank">Cover Letter PDF</a><img height="20px" src="{3}">'
                                 '</img>'.format(licence.licence_document.file.url, static('wl/img/pdf.png'),
                                                 licence.cover_letter_document.file.url, static('wl/img/pdf.png')))
                if ccs:
                    send_licence_issued_email(licence, application, request, to=ccs, additional_attachments=attachments)
            return redirect('wl_dashboard:home')
        else:
            messages.error(request, issue_licence_form.errors)

            log_entry_form = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())

            payment_status = payment_utils.PAYMENT_STATUSES.get(payment_utils.get_application_payment_status(application))

            return render(request, self.template_name, {'application': serialize(application, posthook=format_application),
                                                        'issue_licence_form': issue_licence_form,
                                                        'extracted_fields': extracted_fields,
                                                        'payment_status': payment_status,
                                                        'log_entry_form': log_entry_form})
Exemplo n.º 19
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        kwargs['application'] = serialize(
            application,
            posthook=format_application,
            related={
                'applicant': {
                    'exclude': [
                        'residential_address', 'postal_address',
                        'billing_address'
                    ]
                },
                'applicant_profile': {
                    'fields': ['email', 'id', 'institution', 'name']
                },
                'previous_application': {
                    'exclude': [
                        'applicant', 'applicant_profile',
                        'previous_application', 'licence'
                    ]
                },
                'licence': {
                    'related': {
                        'holder': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'issuer': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'profile': {
                            'related': {
                                'user': {
                                    'exclude': [
                                        'residential_address',
                                        'postal_address', 'billing_address'
                                    ]
                                }
                            },
                            'exclude': ['postal_address']
                        }
                    },
                    'exclude': ['holder', 'issuer', 'profile', 'licence_ptr']
                }
            })

        kwargs['assessments'] = serialize(
            Assessment.objects.filter(application=application),
            posthook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'],
            related={
                'assessor_group': {
                    'related': {
                        'members': {
                            'exclude': ['residential_address']
                        }
                    }
                },
                'officer': {
                    'exclude': ['residential_address']
                },
                'assigned_assessor': {
                    'exclude': ['residential_address']
                }
            })

        kwargs['payment_status'] = payment_utils.PAYMENT_STATUSES.get(
            payment_utils.get_application_payment_status(application))

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        if application.processing_status == 'declined':
            details = ApplicationDeclinedDetails.objects.filter(
                application=application).first()
            if details and details.reason:
                kwargs['application']['declined_reason'] = details.reason
        return super(ViewReadonlyOfficerView, self).get_context_data(**kwargs)
Exemplo n.º 20
0
    def post(self, request, *args, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        is_save = request.POST.get('submissionType') == 'save'
        skip_required = is_save

        # get extract fields from licence if it exists, else extract from application data
        if application.licence is not None:
            issue_licence_form = IssueLicenceForm(request.POST, instance=application.licence, files=request.FILES,
                                                  skip_required=skip_required)
            extracted_fields = application.licence.extracted_fields
        else:
            issue_licence_form = IssueLicenceForm(request.POST, files=request.FILES,
                                                  skip_required=skip_required)
            extracted_fields = extract_licence_fields(application.licence_type.application_schema, application.data)

        # update contents of extracted field based on posted data
        extracted_fields = update_licence_fields(extracted_fields, request.POST)

        payment_status = payment_utils.get_application_payment_status(application)
        payment_status_verbose = payment_utils.PAYMENT_STATUSES.get(payment_status)

        log_entry_form = ApplicationLogEntryForm(to=get_log_entry_to(application), fromm=self.request.user.get_full_name())

        if issue_licence_form.is_valid():
            licence = issue_licence_form.save(commit=False)

            # save required fields that aren't contained in the form
            licence.licence_type = application.licence_type
            licence.profile = application.applicant_profile
            licence.holder = application.applicant
            licence.extracted_fields = extracted_fields
            licence.save()

            # clear re-form variants from application
            licence.variants.clear()
            for index, avl in enumerate(application.variants.through.objects.filter(application=application).
                                        order_by('order')):
                WildlifeLicenceVariantLink.objects.create(licence=licence, variant=avl.variant, order=index)

            # save m2m fields of licence (must be done after licence saved)
            issue_licence_form.save_m2m()

            application.licence = licence
            application.save()

            if is_save:
                messages.warning(request, 'Licence saved but not yet issued.')

                return render(request, self.template_name, {
                    #'application': serialize(application, posthook=format_application),
                    'application': serialize(application,posthook=format_application,
                                                related={
                                                    'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                    'applicant_profile':{'fields':['email','id','institution','name']},
                                                    'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                    'licence':{'related':{
                                                       'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                       'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                       'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
                                                           'exclude': ['postal_address']}
                                                       },'exclude':['holder','issuer','profile','licence_ptr']}
                                                }),
                    'issue_licence_form': issue_licence_form,
                    'extracted_fields': extracted_fields,
                    'payment_status': payment_status_verbose,
                    'log_entry_form': log_entry_form
                })
            else:
                try:
                    self._issue_licence(request, application, issue_licence_form)
                except PaymentException as pe:
                    messages.error(request, pe.message)
                    return redirect(request.get_full_path())

                return redirect('wl_dashboard:home')
        else:
            messages.error(request, 'Please fix the errors below before saving / issuing the licence.')

            return render(request, self.template_name, {
                #'application': serialize(application, posthook=format_application),
                'application': serialize(application,posthook=format_application,
                                            related={
                                                'applicant': {'exclude': ['residential_address','postal_address','billing_address']},
                                                'applicant_profile':{'fields':['email','id','institution','name']},
                                                'previous_application':{'exclude':['applicant','applicant_profile','previous_application','licence']},
                                                'licence':{'related':{
                                                   'holder':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'issuer':{'exclude': ['residential_address','postal_address','billing_address']},
                                                   'profile':{'related': {'user': {'exclude': ['residential_address','postal_address','billing_address']}},
                                                       'exclude': ['postal_address']}
                                                   },'exclude':['holder','issuer','profile','licence_ptr']}
                                            }),
                'issue_licence_form': issue_licence_form,
                'extracted_fields': extracted_fields,
                'payment_status': payment_status_verbose,
                'log_entry_form': log_entry_form
            })
Exemplo n.º 21
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        kwargs['application'] = serialize(
            application,
            posthook=format_application,
            related={
                'applicant': {
                    'exclude': [
                        'residential_address', 'postal_address',
                        'billing_address'
                    ]
                },
                'applicant_profile': {
                    'fields': ['email', 'id', 'institution', 'name']
                },
                'previous_application': {
                    'exclude': [
                        'applicant', 'applicant_profile',
                        'previous_application', 'licence'
                    ]
                },
                'licence': {
                    'related': {
                        'holder': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'issuer': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'profile': {
                            'related': {
                                'user': {
                                    'exclude': [
                                        'residential_address',
                                        'postal_address', 'billing_address'
                                    ]
                                }
                            },
                            'exclude': ['postal_address']
                        }
                    },
                    'exclude': ['holder', 'issuer', 'profile', 'licence_ptr']
                }
            })
        kwargs['form_structure'] = application.licence_type.application_schema

        assessment = get_object_or_404(Assessment, pk=self.args[1])

        kwargs['assessment'] = serialize(
            assessment,
            post_hook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'],
            related={
                'assessor_group': {
                    'related': {
                        'members': {
                            'exclude': ['residential_address']
                        }
                    }
                },
                'officer': {
                    'exclude': ['residential_address']
                },
                'assigned_assessor': {
                    'exclude': ['residential_address']
                }
            })

        kwargs['other_assessments'] = serialize(
            Assessment.objects.filter(application=application).exclude(
                id=assessment.id).order_by('id'),
            posthook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'],
            related={
                'assessor_group': {
                    'related': {
                        'members': {
                            'exclude': ['residential_address']
                        }
                    }
                },
                'officer': {
                    'exclude': ['residential_address']
                },
                'assigned_assessor': {
                    'exclude': ['residential_address']
                }
            })

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        if application.processing_status == 'declined':
            message = "This application has been declined."
            details = ApplicationDeclinedDetails.objects.filter(
                application=application).first()
            if details and details.reason:
                message += "<br/>Reason:<br/>{}".format(
                    details.reason.replace('\n', '<br/>'))
                kwargs['application']['declined_reason'] = details.reason
            messages.error(self.request, message)

        return super(ViewReadonlyAssessorView, self).get_context_data(**kwargs)
Exemplo n.º 22
0
    def get_context_data(self, **kwargs):
        application = get_object_or_404(Application, pk=self.args[0])
        assessment = get_object_or_404(Assessment, pk=self.args[1])

        if application.hard_copy is not None:
            application.licence_type.application_schema, application.data = \
                append_app_document_to_schema_data(application.licence_type.application_schema, application.data,
                                                   application.hard_copy.file.url)

        convert_documents_to_url(application.data, application.documents.all(),
                                 '')

        #kwargs['application'] = serialize(application, posthook=format_application)
        kwargs['application'] = serialize(
            application,
            posthook=format_application,
            related={
                'applicant': {
                    'exclude': [
                        'residential_address', 'postal_address',
                        'billing_address'
                    ]
                },
                'applicant_profile': {
                    'fields': ['email', 'id', 'institution', 'name']
                },
                'previous_application': {
                    'exclude': [
                        'applicant', 'applicant_profile',
                        'previous_application', 'licence'
                    ]
                },
                'licence': {
                    'related': {
                        'holder': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'issuer': {
                            'exclude': [
                                'residential_address', 'postal_address',
                                'billing_address'
                            ]
                        },
                        'profile': {
                            'related': {
                                'user': {
                                    'exclude': [
                                        'residential_address',
                                        'postal_address', 'billing_address'
                                    ]
                                }
                            },
                            'exclude': ['postal_address']
                        }
                    },
                    'exclude': ['holder', 'issuer', 'profile', 'licence_ptr']
                }
            })
        kwargs['form_structure'] = application.licence_type.application_schema

        kwargs['assessment'] = serialize(
            assessment,
            post_hook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'],
            related={
                'assessor_group': {
                    'related': {
                        'members': {
                            'exclude': ['residential_address']
                        }
                    }
                },
                'officer': {
                    'exclude': ['residential_address']
                },
                'assigned_assessor': {
                    'exclude': ['residential_address']
                }
            })

        kwargs['other_assessments'] = serialize(
            Assessment.objects.filter(application=application).exclude(
                id=assessment.id).order_by('id'),
            posthook=format_assessment,
            exclude=['application', 'applicationrequest_ptr'],
            related={
                'assessor_group': {
                    'related': {
                        'members': {
                            'exclude': ['residential_address']
                        }
                    }
                },
                'officer': {
                    'exclude': ['residential_address']
                },
                'assigned_assessor': {
                    'exclude': ['residential_address']
                }
            })

        assessors = [{
            'id': assessor.id,
            'text': assessor.get_full_name()
        } for assessor in assessment.assessor_group.members.all().order_by(
            'first_name')]
        assessors.insert(0, {'id': 0, 'text': 'Unassigned'})

        kwargs['assessors'] = assessors

        kwargs['log_entry_form'] = ApplicationLogEntryForm(
            to=get_log_entry_to(application),
            fromm=self.request.user.get_full_name())

        return super(EnterConditionsAssessorView,
                     self).get_context_data(**kwargs)