Skip to content

Commit

Permalink
Merge 3982917 into 98f32ee
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-gaia committed Oct 26, 2016
2 parents 98f32ee + 3982917 commit c5bd2ae
Show file tree
Hide file tree
Showing 29 changed files with 918 additions and 109 deletions.
5 changes: 3 additions & 2 deletions ledger/accounts/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase
from django_dynamic_fixture import get as get_ddf
from ledger.accounts.models import EmailUser, Address
from ledger.accounts.models import EmailUser, Address, Country


class EmailUserTest(TestCase):
Expand Down Expand Up @@ -50,7 +50,8 @@ class AddressTest(TestCase):

def setUp(self):
super(AddressTest, self).setUp()
self.address1 = get_ddf(Address)
get_ddf(Country, iso_3166_1_a2='AU')
self.address1 = get_ddf(Address, country='AU')

def test_prop_join_fields(self):
"""Test the Address join_fields property
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ django-cron==0.4.6
django-dynamic-fixture>=1.9.0
openpyxl==2.3.5
datapackage>=0.6.1
jsontableschema>=0.6.3
jsontableschema==0.6.5
python-dateutil==2.5.3
py4j==0.10.2.1
djangorestframework==3.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</p>
<p></p>
<p>
from Jim Sharp<br>
for Jim Sharp<br>
DIRECTOR GENERAL
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Yours sincerely



from Jim Sharp
for Jim Sharp

DIRECTOR GENERAL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</p>
<p></p>
<p>
from Jim Sharp<br>
for Jim Sharp<br>
DIRECTOR GENERAL
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Yours sincerely



from Jim Sharp
for Jim Sharp

DIRECTOR GENERAL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ <h4 class="panel-title">Editable application fields (will appear on licence)</h4
<div class="form-group">
<label class="control-label" for="id_{{ item.name }}">{{ item.label }}</label>
{% include 'wl/issue/extracted_field.html' with field=item %}
{% if item.help_text %}
<p class="help-block">{{ item.help_text }}</p>
{% endif %}
</div>
{% else %}
<label class="control-label" for="id_{{ item.name }}">{{ item.label }}</label>
{% if item.help_text %}
<p class="help-block">{{ item.help_text }}</p>
{% endif %}
{% for item_group in item.children %}
<div class="row">
{% with width=item_group|length|derive_col_width %}
Expand Down
12 changes: 7 additions & 5 deletions wildlifelicensing/apps/applications/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from datetime import datetime

from django.test import TestCase
from django_dynamic_fixture import get as get_ddf
from django_dynamic_fixture import G

from django.core.urlresolvers import reverse, reverse_lazy

from ledger.accounts.models import Profile
from ledger.accounts.models import Profile, Address

from wildlifelicensing.apps.applications.views.entry import LICENCE_TYPE_NUM_CHARS, LODGEMENT_NUMBER_NUM_CHARS
from wildlifelicensing.apps.applications.models import Application, Assessment, Condition
from wildlifelicensing.apps.main.tests.helpers import create_random_customer, get_or_create_licence_type, \
SocialClient, get_or_create_default_assessor_group, get_or_create_default_officer
SocialClient, get_or_create_default_assessor_group, get_or_create_default_officer, create_default_country


def create_profile(user):
return get_ddf(Profile, user=user)
create_default_country()
address = G(Address, user=user, country='AU')
return G(Profile, adress=address, user=user)


def create_application(user=None, **kwargs):
Expand All @@ -28,7 +30,7 @@ def create_application(user=None, **kwargs):
kwargs['licence_type'] = get_or_create_licence_type()
if 'data' not in kwargs:
kwargs['data'] = {}
application = get_ddf(Application, **kwargs)
application = G(Application, **kwargs)
return application


Expand Down
1 change: 1 addition & 0 deletions wildlifelicensing/apps/applications/tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ApplicationEntryTestCase(TestCase):
fixtures = ['licences.json', 'catalogue.json', 'partner.json']

def setUp(self):
helpers.create_default_country()
self.customer = get_or_create_default_customer()

self.client = SocialClient()
Expand Down
35 changes: 15 additions & 20 deletions wildlifelicensing/apps/applications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ def _extract_licence_fields_from_item(item, data, licence_fields):
if 'children' not in item:
# label / checkbox types are extracted differently so skip here
if item['type'] not in ('label', 'checkbox'):
licence_field = {
'name': item['name'],
'label': item['licenceFieldLabel'] if 'licenceFieldLabel' in item else item['label'],
'type': item['type'],
'readonly': item.get('isLicenceFieldReadonly', False)
}
licence_field = _create_licence_field(item)

if 'options' in item:
licence_field['options'] = item['options']
Expand All @@ -99,13 +94,8 @@ def _extract_licence_fields_from_item(item, data, licence_fields):

licence_fields.append(licence_field)
else:
licence_field = {
'name': item['name'],
'label': item['licenceFieldLabel'] if 'licenceFieldLabel' in item else item['label'],
'type': item['type'],
'readonly': item.get('isLicenceFieldReadonly', False),
'children': []
}
licence_field = _create_licence_field(item)
licence_field['children'] = []

child_data = _extract_item_data(item['name'], data)

Expand Down Expand Up @@ -139,13 +129,8 @@ def _extract_licence_fields_from_item(item, data, licence_fields):


def _extract_label_and_checkboxes(current_item, items, data, licence_fields):
licence_field = {
'name': current_item['name'],
'label': current_item['licenceFieldLabel'] if 'licenceFieldLabel' in current_item else current_item['label'],
'type': current_item['type'],
'readonly': current_item.get('isLicenceFieldReadonly', False),
'options': []
}
licence_field = _create_licence_field(current_item)
licence_field['options'] = []

# find index of first checkbox after checkbox label within current item list
checkbox_index = 0
Expand All @@ -170,6 +155,16 @@ def _extract_label_and_checkboxes(current_item, items, data, licence_fields):
licence_fields.append(licence_field)


def _create_licence_field(item):
return {
'name': item['name'],
'type': item['type'],
'label': item['licenceFieldLabel'] if 'licenceFieldLabel' in item else item['label'],
'help_text': item.get('licenceFieldHelpText', ''),
'readonly': item.get('isLicenceFieldReadonly', False)
}


def _extract_item_data(name, data):
def ___extract_item_data(name, data):
if isinstance(data, dict):
Expand Down
2 changes: 2 additions & 0 deletions wildlifelicensing/apps/applications/views/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def get(self, request, *args, **kwargs):

application.licence_type = WildlifeLicenceType.objects.get(id=self.args[0])

application.data = None

application.variants.clear()

for index, variant_id in enumerate(request.GET.getlist('variants', [])):
Expand Down
6 changes: 6 additions & 0 deletions wildlifelicensing/apps/main/fixtures/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
"fields": {
"name": "Assessors"
}
},
{
"model": "auth.Group",
"fields": {
"name": "API"
}
}
]
19 changes: 18 additions & 1 deletion wildlifelicensing/apps/main/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

DEFAULT_FONTNAME = 'Helvetica'
BOLD_FONTNAME = 'Helvetica-Bold'
ITALIC_FONTNAME = 'Helvetica-Oblique'
BOLD_ITALIC_FONTNAME = 'Helvetica-BoldOblique'

VERY_LARGE_FONTSIZE = 14
Expand Down Expand Up @@ -79,6 +80,8 @@
rightIndent=PAGE_WIDTH / 10))
styles.add(ParagraphStyle(name='BoldLeft', fontName=BOLD_FONTNAME, fontSize=MEDIUM_FONTSIZE, alignment=enums.TA_LEFT))
styles.add(ParagraphStyle(name='BoldRight', fontName=BOLD_FONTNAME, fontSize=MEDIUM_FONTSIZE, alignment=enums.TA_RIGHT))
styles.add(ParagraphStyle(name='ItalicLeft', fontName=ITALIC_FONTNAME, fontSize=MEDIUM_FONTSIZE, alignment=enums.TA_LEFT))
styles.add(ParagraphStyle(name='ItalifRight', fontName=ITALIC_FONTNAME, fontSize=MEDIUM_FONTSIZE, alignment=enums.TA_RIGHT))
styles.add(ParagraphStyle(name='Center', alignment=enums.TA_CENTER))
styles.add(ParagraphStyle(name='Left', alignment=enums.TA_LEFT))
styles.add(ParagraphStyle(name='Right', alignment=enums.TA_RIGHT))
Expand Down Expand Up @@ -264,6 +267,11 @@ def _layout_extracted_fields(extracted_fields):
elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))
elements.append(Paragraph(field['label'], styles['BoldLeft']))

if field['help_text']:
elements.append(Paragraph(field['help_text'], styles['ItalicLeft']))

elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))

if field['type'] in ['text', 'text_area']:
elements += _layout_paragraphs(field['data'])
elif field['type'] in ['radiobuttons', 'select']:
Expand All @@ -276,13 +284,22 @@ def _layout_extracted_fields(extracted_fields):
if any([option.get('data', 'off') == 'on' for option in field['options']]):
elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))
elements.append(Paragraph(field['label'], styles['BoldLeft']))

if field['help_text']:
elements.append(Paragraph(field['help_text'], styles['ItalicLeft']))

elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))

elements.append(Paragraph(', '.join([option['label'] for option in field['options']
if option.get('data', 'off') == 'on']),
styles['Left']))
else:
elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))
elements.append(Paragraph(field['label'], styles['BoldLeft']))

if field['help_text']:
elements.append(Paragraph(field['help_text'], styles['ItalicLeft']))

table_data = []
for index, group in enumerate(field['children']):
if index == 0:
Expand Down Expand Up @@ -398,7 +415,7 @@ def _create_letter_signature():
signature_elements = []
signature_elements.append(Paragraph('Yours sincerely', styles['LetterLeft']))
signature_elements.append(Spacer(1, SECTION_BUFFER_HEIGHT * 4))
signature_elements.append(Paragraph('from Jim Sharp', styles['LetterLeft']))
signature_elements.append(Paragraph('for Jim Sharp', styles['LetterLeft']))
signature_elements.append(Paragraph('DIRECTOR GENERAL', styles['LetterLeft']))
signature_elements.append(Spacer(1, SECTION_BUFFER_HEIGHT))

Expand Down
23 changes: 20 additions & 3 deletions wildlifelicensing/apps/main/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from django.utils.encoding import smart_text
from django_dynamic_fixture import get as get_ddf
from django_dynamic_fixture import G

from ledger.accounts.models import EmailUser, Profile, Address
from ledger.accounts.models import EmailUser, Profile, Address, Country
from wildlifelicensing.apps.main import helpers as accounts_helpers
from wildlifelicensing.apps.main.models import WildlifeLicenceType, WildlifeLicence, AssessorGroup

Expand Down Expand Up @@ -48,6 +48,12 @@ class TestData(object):
'name': 'ass group',
'email': 'assessor@test.com',
}
DEFAULT_API_USER = {
'email': 'apir@test.com',
'first_name': 'api',
'last_name': 'user',
'dob': '1979-12-13',
}


class SocialClient(Client):
Expand All @@ -70,6 +76,10 @@ def logout(self):
self.get(reverse('accounts:logout'))


def create_default_country():
return G(Country, iso_3166_1_a2='AU')


def is_client_authenticated(client):
return '_auth_user_id' in client.session

Expand All @@ -92,7 +102,7 @@ def get_or_create_user(email, defaults):


def create_random_user():
return get_ddf(EmailUser, dob='1970-01-01')
return G(EmailUser, dob='1970-01-01')


def create_random_customer():
Expand All @@ -117,6 +127,13 @@ def get_or_create_default_officer():
return user


def get_or_create_api_user():
user, created = get_or_create_user(TestData.DEFAULT_API_USER['email'], TestData.DEFAULT_API_USER)
if created:
add_to_group(user, 'API')
return user


def get_or_create_licence_type(product_code='regulation-17'):
return WildlifeLicenceType.objects.get_or_create(product_code=product_code)[0]

Expand Down
3 changes: 2 additions & 1 deletion wildlifelicensing/apps/main/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

from ledger.accounts.models import EmailUser, Profile
from wildlifelicensing.apps.main.tests.helpers import SocialClient, get_or_create_default_customer, \
get_or_create_default_officer, TestData, upload_id
get_or_create_default_officer, TestData, upload_id, create_default_country

TEST_ID_PATH = TestData.TEST_ID_PATH


class AccountsTestCase(TestCase):
def setUp(self):
create_default_country()
self.customer = get_or_create_default_customer()

self.officer = get_or_create_default_officer()
Expand Down
4 changes: 1 addition & 3 deletions wildlifelicensing/apps/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,13 @@ def post(self, request, *args, **kwargs):
original_last_name = emailuser.last_name
emailuser_form = EmailUserForm(request.POST, instance=emailuser)
if emailuser_form.is_valid():
emailuser = emailuser_form.save(commit=False)
emailuser = emailuser_form.save()
is_name_changed = any([original_first_name != emailuser.first_name, original_last_name != emailuser.last_name])

# send signal if either first name or last name is changed
if is_name_changed:
messages.warning(request, "Please upload new identification after you changed your name.")
return redirect(self.identification_url)
elif not emailuser.identification:
messages.warning(request, "Please upload your identification.")
else:
messages.success(request, "User account was saved.")

Expand Down
7 changes: 4 additions & 3 deletions wildlifelicensing/apps/payments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __append_variant_codes(product_code, variant_group, current_variant_codes):
return

for variant in variant_group.variants.all():
variant_code = '{}_{}'.format(product_code, variant.product_code)
variant_code = '{} {}'.format(product_code, variant.product_code)

__append_variant_codes(variant_code, variant_group.child, variant_codes)

Expand All @@ -50,8 +50,9 @@ def generate_product_code(application):
product_code = application.licence_type.product_code

if application.variants.exists():
product_code += '_' + '_'.join(application.variants.through.objects.filter(application=application).
order_by('order').values_list('variant__product_code', flat=True))
product_code = '{} {}'.format(product_code,
' '.join(application.variants.through.objects.filter(application=application).
order_by('order').values_list('variant__product_code', flat=True)))

return product_code

Expand Down
4 changes: 3 additions & 1 deletion wildlifelicensing/apps/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def get(self, request):
data = {
'system': PAYMENT_SYSTEM_ID,
'start': start,
'end': end
'end': end,
'banked_start': start,
'banked_end': end
}
if 'items' in request.GET:
data['items'] = True
Expand Down
1 change: 0 additions & 1 deletion wildlifelicensing/apps/reports/templates/wl/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ <h3>Payments</h3>
<div class="col-md-8">
<button type=submit class="btn btn-primary pull-left" name="items">Generate Report By Accounts</button>
<button type=submit class="btn btn-primary pull-right" name="flat">Generate Report Flat</button>
<hr>
</div>
</div>
</form>
Expand Down
Loading

0 comments on commit c5bd2ae

Please sign in to comment.