Skip to content

Commit

Permalink
Merge pull request #196 from gaiaresources/master
Browse files Browse the repository at this point in the history
End of sprint checking
  • Loading branch information
dbca-asi committed Mar 7, 2017
2 parents 9e3eef8 + d966d27 commit 8f847e8
Show file tree
Hide file tree
Showing 34 changed files with 627 additions and 271 deletions.
34 changes: 34 additions & 0 deletions wildlifelicensing/apps/applications/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,40 @@ def send_user_name_change_notification_email(licence):
email.send(licence.issuer.email, context=context)


class ApplicationDeclinedEmail(TemplateEmailBase):
subject = 'Wildlife licensing [{} {}]: application declined'
html_template = 'wl/emails/application_declined.html'
txt_template = 'wl/emails/application_declined.txt'

def __init__(self, application):
self.subject = _format_application_email_subject(self.subject, application)


def send_application_declined_email(declined_details, request):
application = declined_details.application
email = ApplicationDeclinedEmail(application)
url = request.build_absolute_uri(reverse('wl_home')) if request else None

reason_text = declined_details.reason or ''
reason_html = reason_text.replace('\n', '<br/>')

context = {
'reason_text': reason_text,
'reason_html': reason_html,
'wl_home': url
}

if application.proxy_applicant is None:
recipient_email = application.applicant_profile.email
else:
recipient_email = application.proxy_applicant.email

msg = email.send(recipient_email, context=context)
sender = request.user if request else settings.DEFAULT_FROM_EMAIL
_log_email(msg, application=application, sender=sender)
return recipient_email


def _log_email(email_message, application, sender=None):
if isinstance(email_message, (EmailMultiAlternatives, EmailMessage,)):
# TODO this will log the plain text body, should we log the html instead
Expand Down
22 changes: 21 additions & 1 deletion wildlifelicensing/apps/applications/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from ledger.accounts.models import Profile

from wildlifelicensing.apps.applications.models import IDRequest, ReturnsRequest, AmendmentRequest, ApplicationLogEntry
from wildlifelicensing.apps.applications.models import IDRequest, ReturnsRequest, AmendmentRequest, ApplicationLogEntry, \
ApplicationDeclinedDetails
from wildlifelicensing.apps.main.forms import CommunicationsLogEntryForm


Expand Down Expand Up @@ -87,3 +88,22 @@ class ApplicationLogEntryForm(CommunicationsLogEntryForm):
class Meta:
model = ApplicationLogEntry
fields = ['to', 'fromm', 'type', 'subject', 'text', 'attachment']


class ApplicationDeclinedDetailsForm(forms.ModelForm):
class Meta:
model = ApplicationDeclinedDetails
fields = ['application', 'officer', 'reason']
widgets = {'application': forms.HiddenInput(), 'officer': forms.HiddenInput()}

def __init__(self, *args, **kwargs):
application = kwargs.pop('application', None)
officer = kwargs.pop('officer', None)

super(ApplicationDeclinedDetailsForm, self).__init__(*args, **kwargs)

if application is not None:
self.fields['application'].initial = application

if officer is not None:
self.fields['officer'].initial = officer
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
<a class="collapse-link-top pull-right"><span class="glyphicon glyphicon-chevron-down"></a>
<div class="children-anchor-point collapse in" style="padding-left: 0px">
</div>
{{#unless isPreviewMode }}
{{#if isRepeatable }}
<a id="copy_{{name}}">Copy {{label}}</a>
{{/if}}
{{#unless isPreviewMode}}
<span class="{{#unless isRemovable}}hidden{{/unless}}">
<span class="margin-left margin-right">|</span>
<a id="remove_{{name}}" ">Remove {{label}}</a>
</span>
{{/unless}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-01 09:22
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wl_applications', '0014_assessment_assigned_assessor'),
]

operations = [
migrations.CreateModel(
name='ApplicationDeclinedDetails',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reason', models.TextField(blank=True)),
('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wl_applications.Application')),
('officer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
8 changes: 7 additions & 1 deletion wildlifelicensing/apps/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Application(RevisionedMixin):
'id_and_returns_and_amendment_required']

# List of statuses from above that allow a customer to view an application (read-only)
CUSTOMER_VIEWABLE_STATE = ['under_review', 'id_required', 'returns_required', 'approved']
CUSTOMER_VIEWABLE_STATE = ['under_review', 'id_required', 'returns_required', 'approved', 'declined']

PROCESSING_STATUS_CHOICES = (('temp', 'Temporary'), ('draft', 'Draft'), ('new', 'New'), ('renewal', 'Renewal'),
('licence_amendment', 'Licence Amendment'), ('ready_for_action', 'Ready for Action'),
Expand Down Expand Up @@ -277,6 +277,12 @@ def log_action(cls, application, action, user):
application = models.ForeignKey(Application)


class ApplicationDeclinedDetails(models.Model):
application = models.ForeignKey(Application)
officer = models.ForeignKey(EmailUser, null=False)
reason = models.TextField(blank=True)


@receiver(pre_delete, sender=Application)
def delete_documents(sender, instance, *args, **kwargs):
for document in instance.documents.all():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,16 @@ define(['jQuery', 'lodash', 'js/entry/application_preview', 'select2'], function
}

function initForm() {
$('#issueLicence').click(function(e) {
var $conditionsForm = $('#conditionsForm');
$conditionsForm.append($('<input>').attr('type', 'hidden').attr('name', 'submissionType').val(this.id));
$conditionsForm.submit();
});
var $conditionsForm = $('#conditionsForm');

$('#backToProcessing').click(function(e) {
var $conditionsForm = $('#conditionsForm');
function _submitForm(e) {
$conditionsForm.append($('<input>').attr('type', 'hidden').attr('name', 'submissionType').val(this.id));
$conditionsForm.submit();
});
}

$('#issueLicence').click(_submitForm);
$('#save').click(_submitForm);
$('#backToProcessing').click(_submitForm);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet
}

if(item.isRepeatable) {
_setupCopyRemoveEvents(item, $itemContainer, suffix);
_setupRemoveEvents(item, $itemContainer, suffix);
}

return $itemContainer;
Expand Down Expand Up @@ -232,69 +232,7 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet
}
}

function _setupCopyRemoveEvents(item, itemSelector, suffix) {
itemSelector.find('[id^="copy_' + item.name + '"]').first().click(function(e) {
var itemCopy = itemSelector.clone(true, true),
groupInput = $('[name^="' + item.name + suffix + '"]'),
groupCount = parseInt(groupInput.val());

// clone doesn't copy selected item in select elements, so need to do it manually
itemSelector.find('select').each(function(index) {
$(itemCopy).find('select').eq(index).val($(this).val());
});

// update field names to have correct suffix
itemCopy.find('input, select, textarea').each(function() {
var name = $(this).attr('name'),
namePrefix = name.substring(0, name.indexOf(suffix) + suffix.length),
nameSuffix = name.substring(namePrefix.length);

// cut out first section of nameSuffix to be replaced with current index
nameSuffix = nameSuffix.substring(nameSuffix.indexOf('-', 1));

$(this).attr('name', namePrefix + '-' + groupCount + nameSuffix);
});

// need to replace date inputs with clones of themselves without event binding
// which causes the datetime picker to inadvertantly show on the original date input
itemCopy.find('.date').each(function() {
$(this).replaceWith($(this).clone(false));
})

// need to replace species inputs with clones of themselves without event binding
// which causes the typeahead to show on original species input
itemCopy.find('.species').each(function() {
var speciesClone = $(this).clone(false),
species_type_arg = '';

if(speciesClone.attr('data-species-type')) {
species_type_arg = '&type=' + speciesClone.attr('data-species-type');
}
speciesClone.typeahead({
minLength: 3,
items: 'all',
source: function (query, process) {
return $.get('/taxonomy/species_name?search=' + query + species_type_arg, function (data) {
return process(data);
});
}
});

$(this).replaceWith(speciesClone);
});

itemCopy.find('[id^="copy_' + item.name + '"]').off('click');
itemCopy.find('[id^="remove_' + item.name + '"]').parent().removeClass('hidden');
itemCopy.find('[id^="description_' + item.name + '"]').addClass('hidden');

itemSelector.after(itemCopy);

_initCollapsible(itemCopy, true);

groupInput.val(groupCount + 1);
_setupCopyRemoveEvents(item, itemCopy, suffix);
});

function _setupRemoveEvents(item, itemSelector, suffix) {
itemSelector.find('[id^="remove_' + item.name + '"]').off('click').click(function(e) {
var groupInput = $('[name^="' + item.name + suffix + '"]');
itemSelector.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ define([
});
});

$issueButton.click(function(e) {
function _submitForm(e) {
if(!$(this).hasClass('disabled')) {
$issueLicenceForm.append($('<input>').attr('type', 'hidden').attr('name', 'submissionType').val(this.id));
$issueLicenceForm.submit();
}
});
}

$('#save').click(_submitForm);

$issueButton.click(_submitForm);

if($issueButton.hasClass('disabled')) {
$issueButton.tooltip({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ define([

$($decline).click(function() {
$buttonClicked = $(this);
declineApplication();
});

$submissionForm.submit(function(e) {
Expand All @@ -639,6 +640,11 @@ define([
}
}

function declineApplication() {
var $modal = $('#declinedDetailsModal');
$modal.modal('show');
}

return {
initialiseApplicationProcesssing: function (data) {
$processingStatus = $('#processingStatus');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,33 @@ define([
});
}

function initDeclineStatus(reason) {
var $declinedReasonContainer = $('<div>'),
$status = $('#status');

if ($status) {
if (!reason) {
$declinedReasonContainer.append($('<p>').html("No reason"))
} else {
reason.split('\n').forEach(function (reason) {
$declinedReasonContainer.append($('<p>').html(reason));
});
}
$status.html('').append('<a>Declined</a>');
$status.popover({container: 'body', content: $declinedReasonContainer, html: true});
}
}

return {
init: function (assessment, application, formStructure, otherAssessments) {
initApplicationDetailsPopover(application, formStructure);
initOtherAssessorsCommentsPopover(otherAssessments);
initDefaultConditions(application.licence_type.default_conditions);
initAdditionalConditions(assessment);
initForm();
if (application['processing_status'].toLowerCase() === 'declined') {
initDeclineStatus(application['declined_reason'] || '')
}
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@ define(['jQuery', 'lodash', 'js/entry/application_preview', 'select2'], function
$viewAssessorsComments.popover({container: 'body', content: $contentContainer, html: true});
}

function initDeclineStatus(reason) {
var $declinedReasonContainer = $('<div>'),
$status = $('#status');

if ($status) {
if (!reason) {
$declinedReasonContainer.append($('<p>').html("No reason"))
} else {
reason.split('\n').forEach(function (reason) {
$declinedReasonContainer.append($('<p>').html(reason));
});
}
$status.html('').append('<a>Declined</a>');
$status.popover({container: 'body', content: $declinedReasonContainer, html: true});
}
}

return {
init: function(application, assessments) {
applicationPreview.layoutPreviewItems('#applicationContainer', application.licence_type.application_schema,
application.data);
initAssessorsCommentsPopover(assessments);
if (application['processing_status'].toLowerCase() === 'declined') {
initDeclineStatus(application['declined_reason'] || '')
}
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
</div>
{% endblock %}

{% block messages %}
{% endblock %}

{% block intro_title %}<h3>Enter Licence Conditions</h3>{% endblock %}
{% block intro_subtitle %}
<h4 class="inline">
Expand All @@ -57,6 +60,16 @@ <h4 class="inline">

{% block content %}
<div class="container bottom-buffer">
<div class="row">
<div class="col-md-12">
{% for message in messages %}
<div class="{{ message|bootstrap_message_classes }} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&#215;</button>
{{ message|safe }}
</div>
{% endfor %}
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="row">
Expand Down Expand Up @@ -181,8 +194,9 @@ <h4 class="inline">
</div>
</div>
</div>
<button id="backToProcessing" type="button" class="btn btn-sm btn-default">Processing</button>
<button id="save" type="button" class="btn btn-sm btn-info left-buffer-m">Save</button>
<button id="issueLicence" type="button" class="btn btn-sm btn-success pull-right">Issue Licence</button>
<button id="backToProcessing" type="button" class="btn btn-sm btn-default">Back to Processing</button>
</div>
<div class="col-md-9">
<h3>Current Conditions</h3>
Expand Down
Loading

0 comments on commit 8f847e8

Please sign in to comment.