def _create_bulk_licence_renewal(licences, site_url, buf=None): bulk_licence_renewal_frame = Frame(LETTER_PAGE_MARGIN, LETTER_PAGE_MARGIN, PAGE_WIDTH - 2 * LETTER_PAGE_MARGIN, PAGE_HEIGHT - 160, id='BulkLicenceRenewalFrame') bulk_licence_renewal_template = PageTemplate( id='BulkLicenceRenewalFrame', frames=bulk_licence_renewal_frame, onPage=_create_letter_header_footer) if buf is None: buf = BytesIO() doc = BaseDocTemplate(buf, pageTemplates=[bulk_licence_renewal_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.site_url = site_url all_elements = [] for licence in licences: all_elements += _create_letter_address(licence) + [Spacer(1, LETTER_ADDRESS_BUFFER_HEIGHT)] + \ _create_licence_renewal_elements(licence) + _create_letter_signature() all_elements.append(PageBreak()) doc.build(all_elements) return doc
def _create_licence_renewal(licence_renewal_buffer, licence, site_url): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=every_page_frame, onPage=_create_header) doc = BaseDocTemplate(licence_renewal_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.site_url = site_url doc.build(_create_licence_renewal_elements(licence)) return licence_renewal_buffer
def _create_cover_letter(cover_letter_buffer, licence, site_url): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=every_page_frame, onPage=_create_header) doc = BaseDocTemplate(cover_letter_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.site_url = site_url elements = [] elements.append(Paragraph('Dear Sir/Madam', styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Congratulations, your Wildlife Licensing application has been approved and the ' 'corresponding licence has been issued.', styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph("You'll find your licence document in this envelope. Please read it carefully.", styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # Removed link to online system for beta # elements.append(Paragraph('You also can access it from your Wildlife Licensing dashboard by copying and pasting ' # 'the following link in your browser:', styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(Paragraph(site_url, styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(Paragraph("Note: If you haven't been on the Wildlife Licensing site recently you might have to " # "login first before using the provided link.", styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) if licence.cover_letter_message: for message in licence.cover_letter_message.split('\r\n'): if message: elements.append(Paragraph(message, styles['Left'])) else: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Best regards,', styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Parks and Wildlife Customer Portal', styles['Left'])) doc.build(elements) return cover_letter_buffer
def _create_bulk_licence_renewal(licences, site_url, buf=None): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=every_page_frame, onPage=lambda canvas, doc_: _create_header(canvas, doc_, draw_page_number=False)) if buf is None: buf = BytesIO() doc = BaseDocTemplate(buf, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.site_url = site_url all_elements = [] for licence in licences: all_elements += _create_licence_renewal_elements(licence) all_elements.append(PageBreak()) doc.build(all_elements) return doc
def _create_bulk_licence_renewal(licences, site_url, buf=None): bulk_licence_renewal_frame = Frame(LETTER_PAGE_MARGIN, LETTER_PAGE_MARGIN, PAGE_WIDTH - 2 * LETTER_PAGE_MARGIN, PAGE_HEIGHT - 160, id='BulkLicenceRenewalFrame') bulk_licence_renewal_template = PageTemplate(id='BulkLicenceRenewalFrame', frames=bulk_licence_renewal_frame, onPage=_create_letter_header_footer) if buf is None: buf = BytesIO() doc = BaseDocTemplate(buf, pageTemplates=[bulk_licence_renewal_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.site_url = site_url all_elements = [] for licence in licences: all_elements += _create_letter_address(licence) + [Spacer(1, LETTER_ADDRESS_BUFFER_HEIGHT)] + \ _create_licence_renewal_elements(licence) + _create_letter_signature() all_elements.append(PageBreak()) doc.build(all_elements) return doc
def _create_renewal(renewal_buffer, approval, proposal): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(renewal_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] title = approval.title.encode('UTF-8') # additional information '''if approval.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(approval.additional_information)''' # delegation holds the dates, approvale and issuer details. delegation = [] # proponent details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = proposal.applicant.organisation.postal_address address_paragraphs = [ Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph( '%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left']) ] delegation.append( Table([[[ Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft']) ], [Paragraph(_format_name(approval.applicant), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) expiry_date = approval.expiry_date.strftime(DATE_FORMAT) full_name = proposal.submitter.get_full_name() delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Dear {} '.format(full_name), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph('This is a reminder that your approval: ', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) title_with_number = '{} - {}'.format(approval.lodgement_number, title) delegation.append( Paragraph(title_with_number, styles['InfoTitleLargeLeft'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph('is due to expire on {}'.format(expiry_date), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'Please note that if you have outstanding compliances these are required to be submitted before the approval can be renewed', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'If you have any queries, contact the {} ' 'on {}.'.format(settings.DEP_NAME, settings.DEP_PHONE), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Yours sincerely ', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('DIRECTOR GENERAL', styles['Left'])) delegation.append(Paragraph('{}'.format(settings.DEP_NAME), styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return renewal_buffer
def _create_approval(approval_buffer, approval, proposal, copied_to_permit, user): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(approval_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url region = approval.region if hasattr(approval, 'region') else '' district = approval.district if hasattr(approval, 'district') else '' region_district = '{} - {}'.format(region, district) if district else region approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] title = approval.title.encode('UTF-8') #Organization details address = proposal.applicant.organisation.postal_address email = proposal.applicant.organisation.organisation_set.all().first( ).contacts.all().first().email elements.append(Paragraph(email, styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph(_format_name(approval.applicant), styles['BoldLeft'])) elements.append(Paragraph(address.line1, styles['BoldLeft'])) elements.append(Paragraph(address.line2, styles['BoldLeft'])) elements.append(Paragraph(address.line3, styles['BoldLeft'])) elements.append( Paragraph( '%s %s %s' % (address.locality, address.state, address.postcode), styles['BoldLeft'])) elements.append(Paragraph(address.country.name, styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #elements.append(Paragraph(title, styles['InfoTitleVeryLargeCenter'])) #elements.append(Paragraph(approval.activity, styles['InfoTitleLargeLeft'])) elements.append( Paragraph( 'APPROVAL OF PROPOSAL {} {} TO UNDERTAKE DISTURBANCE ACTIVITY IN {}' .format(title, proposal.lodgement_number, region_district), styles['InfoTitleLargeLeft'])) #import ipdb; ipdb.set_trace() #elements.append(Paragraph(approval.tenure if hasattr(approval, 'tenure') else '', styles['InfoTitleLargeRight'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph( 'The submitted proposal {} {} has been assessed and approved. The approval is granted on the understanding that: ' .format(title, proposal.lodgement_number), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) list_of_bullets = [] list_of_bullets.append( 'The potential impacts of the proposal on values the department manages have been removed or minimised to a level \'As Low As Reasonably Practicable\' (ALARP) and the proposal is consistent with departmental objectives, associated management plans and the land use category/s in the activity area.' ) list_of_bullets.append( 'Approval is granted for the period {} to {}. This approval is not valid if {} makes changes to what has been proposed or the proposal has expired. To change the proposal or seek an extension, the proponent must re-submit the proposal for assessment.' .format(approval.start_date.strftime(DATE_FORMAT), approval.expiry_date.strftime(DATE_FORMAT), _format_name(approval.applicant))) list_of_bullets.append( 'The proponent accepts responsibility for advising {} of new information or unforeseen threats that may affect the risk of the proposed activity.' .format(settings.DEP_NAME_SHORT)) list_of_bullets.append( 'Information provided by {0} for the purposes of this proposal will not be provided to third parties without permission from {0}.' .format(settings.DEP_NAME_SHORT)) list_of_bullets.append( 'The proponent accepts responsibility for supervising and monitoring implementation of activity/ies to ensure compliance with this proposal. {} reserves the right to request documents and records demonstrating compliance for departmental monitoring and auditing.' .format(settings.DEP_NAME_SHORT)) list_of_bullets.append( 'Non-compliance with the conditions of the proposal may trigger a suspension or withdrawal of the approval for this activity.' ) list_of_bullets.append( 'Management actions listed in Appendix 1 are implemented.') understandingList = ListFlowable([ ListItem( Paragraph(a, styles['Left']), bulletColour='black', value='circle') for a in list_of_bullets ], bulletFontName=BOLD_FONTNAME, bulletFontSize=SMALL_FONTSIZE, bulletType='bullet') #bulletFontName=BOLD_FONTNAME elements.append(understandingList) # proposal requirements requirements = proposal.requirements.all().exclude(is_deleted=True) if requirements.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph( 'The following requirements must be satisfied for the approval of the proposal not to be withdrawn:', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable([ Paragraph(a.requirement, styles['Left']) for a in requirements.order_by('order') ], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) # if copied_to_permit: # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(Paragraph('Assessor Comments', styles['BoldLeft'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # for k,v in copied_to_permit: # elements.append(Paragraph(v.encode('UTF-8'), styles['Left'])) # elements.append(Paragraph(k.encode('UTF-8'), styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements += _layout_extracted_fields(approval.extracted_fields) # additional information '''if approval.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(approval.additional_information)''' # delegation holds the dates, approvale and issuer details. delegation = [] # dates and licensing officer # dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), # ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) # delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), # Paragraph('Date of Expiry', styles['BoldLeft'])] # date_values = [Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['Left']), # Paragraph(approval.start_date.strftime(DATE_FORMAT), styles['Left']), # Paragraph(approval.expiry_date.strftime(DATE_FORMAT), styles['Left'])] # if approval.original_issue_date is not None: # date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) # date_values.insert(0, Paragraph(approval.original_issue_date.strftime(DATE_FORMAT), styles['Left'])) # delegation.append(Table([[date_headings, date_values]], # colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), # style=dates_licensing_officer_table_style)) # proponent details # delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # address = proposal.applicant.organisation.postal_address # address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), # Paragraph(address.line3, styles['Left']), # Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), # Paragraph(address.country.name, styles['Left'])] # delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], # [Paragraph(_format_name(approval.applicant), # styles['Left'])] + address_paragraphs]], # colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), # style=approval_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'Should you have any queries about this approval, please contact {} {}, ' 'on {} or by email at {}'.format(user.first_name, user.last_name, settings.DEP_PHONE, user.email), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'To provide feedback on the system used to submit the approval or update contact details, please ' 'contact {} Works Coordinator - {}'.format( settings.SYSTEM_NAME_SHORT, settings.SUPPORT_EMAIL), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Approved on behalf of the', styles['Left'])) delegation.append( Paragraph('{}'.format(settings.DEP_NAME), styles['BoldLeft'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph('{} {}'.format(user.first_name, user.last_name), styles['Left'])) delegation.append(Paragraph('{}'.format(region_district), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['Left'])) elements.append(KeepTogether(delegation)) # Appendix section elements.append(PageBreak()) elements.append( Paragraph('Appendix 1 - Management Actions', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) if copied_to_permit: # for k,v in copied_to_permit: # elements.append(Paragraph(v.encode('UTF-8'), styles['Left'])) # elements.append(Paragraph(k.encode('UTF-8'), styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) for item in copied_to_permit: for key in item: elements.append(Paragraph(key.encode('UTF-8'), styles['Left'])) elements.append( Paragraph(item[key].encode('UTF-8'), styles['Left'])) else: elements.append( Paragraph('There are no management actions.', styles['Left'])) doc.build(elements) return approval_buffer
def _create_licence(licence_buffer, licence, application): ''' Creates licence summary and purpose details for licence. ''' def _create_licence_purpose(elements, selected_activity, issued_purpose): ''' Creates the licence purpose details per page available on the activity. ''' # delegation holds the dates, licencee and issuer details. delegation = [] sequence = purpose.purpose_sequence licence_display = '{0}-{1}-{2}'.format(licence.licence_number, sequence, issued_purpose.purpose.code) licence_purpose = issued_purpose.purpose.name elements.append( Paragraph(licence_purpose.upper(), styles['InfoTitleVeryLargeCenter'])) elements.append( Paragraph( 'Regulation {}, Biodiversity Conservation Regulations 2018'. format(issued_purpose.purpose.regulation), styles['Center'])) # applicant details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) if application.applicant_type \ == application.APPLICANT_TYPE_ORGANISATION: address = application.org_applicant.address pass elif application.applicant_type == application.APPLICANT_TYPE_PROXY: address = application.proxy_applicant.residential_address pass else: # applic.applicant_type == application.APPLICANT_TYPE_SUBMITTER address = application.submitter.residential_address address_paragraphs = [ Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph( '%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left']) ] delegation.append( Table([[[ Paragraph('Licence Number', styles['BoldLeft']), Paragraph('Licence Holder', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft']) ], [Paragraph(licence_display, styles['Left'])] + [ Paragraph(licence.current_application.applicant, styles['Left']) ] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=licence_table_style)) # dates dates_licensing_officer_table_style = TableStyle([ ('VALIGN', (0, 0), (-2, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'BOTTOM') ]) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) date_headings = [ Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Date Valid From', styles['BoldLeft']), Paragraph('Date of Expiry', styles['BoldLeft']) ] date_values = [ Paragraph(issued_purpose.issue_date.strftime('%d/%m/%Y'), styles['Left']), Paragraph(issued_purpose.start_date.strftime('%d/%m/%Y'), styles['Left']), Paragraph(issued_purpose.expiry_date.strftime('%d/%m/%Y'), styles['Left']) ] if issued_purpose.is_reissued: date_headings.insert( 0, Paragraph('Original Date of Issue', styles['BoldLeft'])) date_values.insert( 0, Paragraph(issued_purpose.original_issue_date, styles['Left'])) delegation.append( Table([[date_headings, date_values]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=dates_licensing_officer_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(KeepTogether(delegation)) # species species_ids = issued_purpose.purpose.get_species_list if species_ids: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('SPECIES', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) species = LicenceSpecies.objects.values_list('data').filter( specie_id__in=species_ids) speciesList = ListFlowable([ Paragraph(s[0][0]['vernacular_names'], styles['Left']) for s in species ], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(speciesList) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) try: # copy-to-licence sections with terms and additional information. activity_util = ActivitySchemaUtil(selected_activity.application) terms = selected_activity.additional_licence_info['terms'] for term in terms: header = term['header'] if not header: continue elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph(header.upper(), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) text = activity_util.get_ctl_text(term) elements.append(Paragraph(text, styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) except BaseException: pass # PurposeSpecies Section # for s in purpose.purpose_species_json: # if s.has_key('is_additional_info') and s['is_additional_info']: # continue # # if s['details']: # parser = HtmlParser(s['details']) # # # Get and Display Purpose Species Header # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append( # Paragraph( # s['header'], # styles['BoldLeft'] # ) # ) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # # purposeSpeciesList = add_parsed_details(parser, list_flowable=False) # for info_item in purposeSpeciesList: # elements.append(KeepTogether(info_item)) for s in purpose.purpose_species_json: if 'is_additional_info' in s and s['is_additional_info']: continue if s['details']: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) purposeSpeciesList, listcounter = html_to_rl( s['details'], styles) for info_item in purposeSpeciesList: elements.append(KeepTogether(info_item)) # End PurposeSpecies Section # application conditions activity_conditions = selected_activity.application.conditions.filter( licence_activity_id=selected_activity.licence_activity_id, licence_purpose_id=issued_purpose.purpose.id) if activity_conditions.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('CONDITIONS', styles['BoldLeft'])) #elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # Conditions Section # conditionList = [] # for s in activity_conditions.order_by('order'): # parser = HtmlParser(s.condition) # conditionList += add_parsed_details(parser, list_flowable=False) # #elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # conditionList = ListFlowable( # conditionList, # bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE # ) # elements.append(conditionList) listcounter = 0 conditionList = [] for s in activity_conditions.order_by('order'): #_conditionList, listcounter += html_to_rl(s.condition, styles) _conditionList, listcounter = html_to_rl( s.condition_text, styles, listcounter) conditionList += _conditionList for info_item in conditionList: elements.append(KeepTogether(info_item)) # End Conditions Section elements += _layout_extracted_fields(licence.extracted_fields) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # signature block elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) issue_officer = '{} {}'.format(selected_activity.updated_by.first_name, selected_activity.updated_by.last_name) elements.append(Paragraph('____________________', styles['Left'])) elements.append(Paragraph(issue_officer, styles['Left'])) elements.append(Paragraph('LICENSING OFFICER', styles['Left'])) elements.append(Paragraph('WILDLIFE PROTECTION BRANCH', styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Delegate of CEO', styles['ItalicLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # additional information # 'is_additional_info' Section from Purposespecies # for s in purpose.purpose_species_json: # if s.has_key('is_additional_info') and s['is_additional_info'] and s['details']: # parser = HtmlParser(s['details']) # # # Get and Display Purpose Species Header # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append( # Paragraph( # s['header'], # styles['BoldLeft'] # ) # ) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # # purposeSpeciesInfoList = add_parsed_details(parser, list_flowable=False) # #elements.append(purposeSpeciesInfoList) # for info_item in purposeSpeciesInfoList: # elements.append(KeepTogether(info_item)) # additional information for s in purpose.purpose_species_json: if 'is_additional_info' in s and s['is_additional_info'] and s[ 'details']: # Get and Display Purpose Species Header elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) purposeSpeciesInfoList, listcounter = html_to_rl( s['details'], styles) for info_item in purposeSpeciesInfoList: elements.append(KeepTogether(info_item)) # End PurposeSpecies Section if licence.has_additional_information_for(selected_activity): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph('ADDITIONAL INFORMATION', styles['BoldLeft'])) #elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditions = activity_conditions infos = [] c_num = 0 for c_id, condition in enumerate(conditions.order_by('order')): info = None if condition.standard_condition: info = condition.standard_condition.additional_information c_num = c_id + 1 if info: infos.append('{0} (related to condition no.{1})'.format( info.encode('utf8'), c_num)) # Conditions Section # for s in infos: # parser = HtmlParser(s) # infoList = add_parsed_details(parser) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(infoList) for s in infos: infoList, listcounter = html_to_rl(s, styles) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #elements.append(infoList) for info_item in infoList: elements.append(KeepTogether(info_item)) # End Conditions Section elements.append(PageBreak()) # create the summary for this licence. site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_licence_header) doc = BaseDocTemplate(licence_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.licence = licence doc.site_url = site_url licence_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] elements.append( Paragraph('Licence Summary', styles['InfoTitleVeryLargeCenter'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(Paragraph('Activities', styles['BoldLeft'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # activityList = ListFlowable( # [Paragraph("{name}".format( # name=selected_activity.licence_activity.name # ), # styles['Left'], # ) for selected_activity in licence.current_activities], # bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) # elements.append(activityList) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Purposes', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) include = [ ApplicationSelectedActivityPurpose.PURPOSE_STATUS_SUSPENDED, ApplicationSelectedActivityPurpose.PURPOSE_STATUS_CURRENT, ApplicationSelectedActivityPurpose.PURPOSE_STATUS_DEFAULT, ] licence_purposes = [ p for p in licence.get_purposes_in_sequence() if p.purpose_status in include and p.is_issued and p.expiry_date ] purposeList = ListFlowable([ Paragraph( "{name} {start} - {end} ({status})".format( name=p.purpose.name, status=p.purpose_status, start=p.start_date.strftime('%d/%m/%Y'), end=p.expiry_date.strftime('%d/%m/%Y'), ), styles['Left'], ) for p in licence_purposes ], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(purposeList) elements.append(PageBreak()) for purpose in licence_purposes: # if not purpose.is_issued or purpose.purpose_status not in include: # # Exclude purposes that are not issued. # continue _create_licence_purpose(elements, purpose.selected_activity, purpose) doc.build(elements) return licence_buffer
def _create_renewal(renewal_buffer, approval, proposal): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(renewal_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] #title = approval.title.encode('UTF-8') title = '' # additional information '''if approval.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(approval.additional_information)''' # delegation holds the dates, approvale and issuer details. delegation = [] # proponent details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #address = proposal.applicant.organisation.postal_address address = proposal.applicant_address address_paragraphs = [ Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph( '%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left']) ] delegation.append( Table([[[ Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft']) ], [Paragraph(_format_name(approval.applicant), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) expiry_date = approval.expiry_date.strftime(DATE_FORMAT) full_name = proposal.submitter.get_full_name() delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Dear {} '.format(full_name), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'This is a reminder that your Commercial Operations licence {} expires on {}. ' .format(approval.lodgement_number, expiry_date), styles['BoldLeft'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'It is important you apply to renew your licence now so that we can process it before your current licence expires.' 'If you would like to continue operating within WA\'s national parks and other conservation reserves you need a licence under the Conservation and Land Management Regulations 2002.', styles['Left'])) #delegation.append(Paragraph('If you would like to continue operating within WA\'s national parks and other conservation reserves you need a licence under the Conservation and Land Management Regulations 2002.' # , styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'As a reminder, the Commercial Operator Handbook outlines the conditions of your licence. ' 'The current handbook is available online at the {} website:'. format(settings.DEP_NAME), styles['Left'])) #delegation.append(Paragraph('The handbook is available online at the {} website: .'.format(settings.DEP_NAME), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph('{}'.format(settings.COLS_HANDBOOK_URL), styles['WebAddress'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'Please make sure you have access to this handbook, either in hardcopy or online, when operating within WA\'s national parks and conservation reserves.', styles['Left'])) #delegation.append(Paragraph('', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Paragraph( 'If you have any questions about how to renew your licence please call Licencing Officer on {} or email [email protected].' .format(settings.DEP_PHONE), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Yours sincerely ', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #delegation.append(Paragraph('DIRECTOR GENERAL', styles['Left'])) delegation.append(Paragraph('{}'.format(settings.DEP_NAME), styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return renewal_buffer
def _create_approval_cols(approval_buffer, approval, proposal, copied_to_permit, user): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(approval_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) box_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP'), ('BOX', (0, 0), (-1, -1), 0.25, black), ('INNERGRID', (0, 0), (-1, -1), 0.25, black), ('ALIGN', (0, 0), (-1, -1), 'RIGHT')]) elements = [] #Organization details address = proposal.applicant_address # address = proposal.applicant_address if proposal.org_applicant: try: email = proposal.org_applicant.organisation.organisation_set.all( ).first().contacts.all().first().email except: raise ValidationError( 'There is no contact for Organisation. Please create an Organisation contact' ) else: email = proposal.submitter.email #elements.append(Paragraph(email,styles['BoldLeft'])) elements.append( Paragraph('CONSERVATION AND LAND MANAGEMENT REGULATIONS 2002 (PART 7)', styles['ItalicCenter'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph('COMMERCIAL OPERATIONS LICENCE', styles['InfoTitleVeryLargeCenter'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph( 'The Chief Executive Officer (CEO) of the Department of Biodiversity, Conservation and Attractions hereby grants a commercial operations licence to enter upon and conduct activities within the parks/reserves listed in Schedule 1 of this licence to:', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # delegation holds the Licence number and applicant name in table format. delegation = [] delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Table( [[[Paragraph('Licensee:', styles['BoldLeft'])], [Paragraph(_format_name(approval.applicant), styles['Left'])]]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) if approval.current_proposal.org_applicant and approval.current_proposal.org_applicant.organisation.trading_name: delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Table([[[Paragraph('Trading Name:', styles['BoldLeft'])], [ Paragraph( _format_name( approval.current_proposal.org_applicant. organisation.trading_name), styles['Left']) ]]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append( Table([[[Paragraph('Licence Number:', styles['BoldLeft'])], [Paragraph(approval.lodgement_number, styles['Left'])]]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(KeepTogether(delegation)) elements.append( Paragraph( 'Commencing on the {} and expiring on {}.'.format( approval.start_date.strftime(DATE_FORMAT2), approval.expiry_date.strftime(DATE_FORMAT2)), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('CONDITIONS', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) list_of_bullets = [] list_of_bullets.append( 'This Commercial Operations Licence is subject to the provisions of the <i>Conservation and Land Management Act 1984</i> and all subsidiary legislation made under it.' ) list_of_bullets.append( 'The Licensee must comply with and not contravene the conditions and restrictions set out in the Commercial Operator Handbook as varied from time to time by the CEO.' ) list_of_bullets.append( 'The Licensee must comply with the conditions contained in any schedule of conditions attached to this Commercial Operations Licence.' ) understandingList = ListFlowable([ ListItem(Paragraph(a, styles['Left']), bulletColour='black') for a in list_of_bullets ], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) #bulletFontName=BOLD_FONTNAME elements.append(understandingList) elements += _layout_extracted_fields(approval.extracted_fields) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph('{} {}'.format(user.first_name, user.last_name), styles['Left'])) if user.position_title: elements.append( Paragraph('{}'.format(user.position_title), styles['Left'])) elements.append(Paragraph('As Delegate of CEO', styles['Left'])) elements.append( Paragraph('Under Section 133(2) of the CALM Act 1984', styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append( Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['Left'])) elements.append(PageBreak()) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) table_data = [ [ Paragraph('Licence Number', styles['BoldLeft']), Paragraph(_format_name(approval.lodgement_number), styles['Left']) ], [ Paragraph('Commencement Date', styles['BoldLeft']), Paragraph( _format_name(approval.start_date).strftime(DATE_FORMAT), styles['Left']) ], [ Paragraph('Expiry Date', styles['BoldLeft']), Paragraph( _format_name(approval.expiry_date).strftime(DATE_FORMAT), styles['Left']) ] ] t = Table(table_data, colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=box_table_style) elements.append(t) # Schedule 1 elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('SCHEDULE 1', styles['BoldCenter'])) elements.append( Paragraph('COMMERCIAL OPERATIONS LICENCE ACTIVITIES', styles['BoldCenter'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) park_data = [] for p in approval.current_proposal.selected_parks_activities_pdf: activities_str = [] for ac in p['activities']: activities_str.append(ac.encode('UTF-8')) access_types_str = [] if 'access_types' in p: for at in p['access_types']: access_types_str.append(at.encode('UTF-8')) activities_str = str(activities_str).strip('[]').replace('\'', '') access_types_str = str(access_types_str).strip('[]').replace('\'', '') activities_str = activities_str if access_types_str == '' else access_types_str + ', ' + activities_str park_data.append([ Paragraph(_format_name(p['park']), styles['BoldLeft']), Paragraph(activities_str.strip().strip(','), styles['Left']) # remove last trailing comma ]) if park_data: t = Table(park_data, colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=box_table_style) elements.append(t) # Schedule 2 elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('SCHEDULE 2', styles['BoldCenter'])) elements.append( Paragraph('COMMERCIAL OPERATIONS LICENCE CONDITIONS', styles['BoldCenter'])) requirements = proposal.requirements.all().exclude(is_deleted=True) if requirements.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #elements.append(Paragraph('The following requirements must be satisfied for the licence not to be withdrawn:', styles['BoldLeft'])) #elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable([ Paragraph(a.requirement, styles['Left']) for a in requirements.order_by('order') ], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) doc.build(elements) return approval_buffer
def _create_licence(licence_buffer, licence, application, site_url, original_issue_date): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=every_page_frame, onPage=_create_licence_header) doc = BaseDocTemplate(licence_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.licence = licence doc.site_url = site_url licence_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] elements.append(Paragraph(licence.licence_type.act, styles['InfoTitleLargeCenter'])) elements.append(Paragraph(licence.licence_type.code.upper(), styles['InfoTitleLargeCenter'])) # cannot use licence get_title_with_variants because licence isn't saved yet so can't get variants if application.variants.exists: title = '{} ({})'.format(application.licence_type.name, ' / '.join(application.variants.all(). values_list('name', flat=True))) else: title = licence.licence_type.name elements.append(Paragraph(title, styles['InfoTitleVeryLargeCenter'])) elements.append(Paragraph(licence.licence_type.statement, styles['InfoTitleLargeLeft'])) elements.append(Paragraph(licence.licence_type.authority, styles['InfoTitleLargeRight'])) # licence conditions if application.conditions.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Conditions', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable( [Paragraph(condition.text, styles['Left']) for condition in application.conditions.all()], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) # purpose if licence.purpose: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Purpose', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) for purpose in licence.purpose.split('\r\n'): if purpose: elements.append(Paragraph(purpose, styles['Left'])) else: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # locations if licence.locations: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Locations', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) for location in licence.locations.split('\r\n'): if location: elements.append(Paragraph(location, styles['Left'])) else: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # authorised persons authorised_persons = _get_authorised_person_names(application) if len(authorised_persons) > 0: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Authorised Persons', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) for ap in authorised_persons: elements.append(Paragraph(ap, styles['Left'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # species species = _get_species(application) if len(species) > 0: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) section_width = (PAGE_WIDTH - (2 * PAGE_MARGIN) - 100) / 2 elements.append(Table([[Paragraph('Species', styles['BoldLeft']), Paragraph('Name', styles['BoldLeft']), Paragraph('Count', styles['BoldLeft'])]], colWidths=(100, section_width, section_width), style=licence_table_style)) for s in species: elements.append(Table([['', Paragraph(s[0], styles['Left']), Paragraph(s[1], styles['Left'])]], colWidths=(100, section_width, section_width), style=licence_table_style)) # additional information if licence.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) for paragraph in licence.additional_information.split('\r\n'): if paragraph: elements.append(Paragraph(paragraph, styles['Left'])) else: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # delegation holds the dates, licencee and issuer details. delegation = [] # dates and licensing officer dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), Paragraph('Date of Expiry', styles['BoldLeft'])] date_values = [Paragraph(licence.issue_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.start_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.end_date.strftime(DATE_FORMAT), styles['Left'])] if original_issue_date is not None: date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) date_values.insert(0, Paragraph(original_issue_date.strftime(DATE_FORMAT), styles['Left'])) delegation.append(Table([[date_headings, date_values]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=dates_licensing_officer_table_style)) # licensee details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = application.applicant_profile.postal_address address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left'])] delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], [Paragraph(render_user_name(application.applicant), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=licence_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Issued by a Wildlife Licensing Officer of the Department of Parks and Wildlife ' 'under delegation from the Minister for Environment pursuant to section 133(1) ' 'of the Conservation and Land Management Act 1984.', styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return licence_buffer
def _create_licence(licence_buffer, licence, application, site_url, original_issue_date): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_licence_header) doc = BaseDocTemplate(licence_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.licence = licence doc.site_url = site_url licence_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] elements.append(Paragraph(licence.licence_type.act, styles['InfoTitleLargeCenter'])) elements.append(Paragraph(licence.licence_type.code.upper(), styles['InfoTitleLargeCenter'])) # cannot use licence get_title_with_variants because licence isn't saved yet so can't get variants if application.variants.exists(): title = '{} ({})'.format(application.licence_type.name.encode('UTF-8'), ' / '.join(application.variants.all(). values_list('name', flat=True))) else: title = licence.licence_type.name.encode('UTF-8') elements.append(Paragraph(title, styles['InfoTitleVeryLargeCenter'])) elements.append(Paragraph(licence.licence_type.statement, styles['InfoTitleLargeLeft'])) elements.append(Paragraph(licence.licence_type.authority, styles['InfoTitleLargeRight'])) # licence conditions if application.conditions.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Conditions', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable( [Paragraph(a.condition.text, styles['Left']) for a in application.applicationcondition_set.order_by('order')], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) # purpose if licence.purpose: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Purpose', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements += _layout_paragraphs(licence.purpose) # locations if licence.locations: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Locations', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements += _layout_paragraphs(licence.locations) elements += _layout_extracted_fields(licence.extracted_fields) # additional information if licence.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(licence.additional_information) # delegation holds the dates, licencee and issuer details. delegation = [] # dates and licensing officer dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), Paragraph('Date of Expiry', styles['BoldLeft'])] date_values = [Paragraph(licence.issue_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.start_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.end_date.strftime(DATE_FORMAT), styles['Left'])] if original_issue_date is not None: date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) date_values.insert(0, Paragraph(original_issue_date.strftime(DATE_FORMAT), styles['Left'])) delegation.append(Table([[date_headings, date_values]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=dates_licensing_officer_table_style)) # licensee details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = application.applicant_profile.postal_address address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left'])] delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], [Paragraph(_format_name(application.applicant, include_first_name=True), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=licence_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Issued by a Wildlife Licensing Officer of the Department of Parks and Wildlife ' 'under delegation from the Minister for Environment pursuant to section 133(1) ' 'of the Conservation and Land Management Act 1984.', styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return licence_buffer
def _create_renewal(renewal_buffer, approval, proposal): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(renewal_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] title = approval.title.encode('UTF-8') # additional information '''if approval.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(approval.additional_information)''' # delegation holds the dates, approvale and issuer details. delegation = [] # proponent details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = proposal.applicant.organisation.postal_address address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left'])] delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], [Paragraph(_format_name(approval.applicant), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=approval_table_style)) expiry_date = approval.expiry_date.strftime(DATE_FORMAT) full_name = proposal.submitter.get_full_name() delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Dear {} '.format(full_name), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('This is a reminder that your approval: ', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) title_with_number = '{} - {}'.format(approval.lodgement_number, title) delegation.append(Paragraph(title_with_number, styles['InfoTitleLargeLeft'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('is due to expire on {}'.format(expiry_date), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Please note that if you have outstanding compliances these are required to be submitted before the approval can be renewed' , styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('If you have any queries, contact the {} ' 'on {}.'.format(settings.DEP_NAME, settings.DEP_PHONE), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Yours sincerely ', styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('DIRECTOR GENERAL', styles['Left'])) delegation.append(Paragraph('{}'.format(settings.DEP_NAME), styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return renewal_buffer
def _create_approval(approval_buffer, approval, proposal, copied_to_permit, user): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_approval_header) doc = BaseDocTemplate(approval_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.approval = approval doc.site_url = site_url region = approval.region if hasattr(approval, 'region') else '' district = approval.district if hasattr(approval, 'district') else '' region_district = '{} - {}'.format(region, district) if district else region approval_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] title = approval.title.encode('UTF-8') #Organization details address = proposal.applicant.organisation.postal_address email = proposal.applicant.organisation.organisation_set.all().first().contacts.all().first().email elements.append(Paragraph(email,styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph(_format_name(approval.applicant),styles['BoldLeft'])) elements.append(Paragraph(address.line1, styles['BoldLeft'])) elements.append(Paragraph(address.line2, styles['BoldLeft'])) elements.append(Paragraph(address.line3, styles['BoldLeft'])) elements.append(Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['BoldLeft'])) elements.append(Paragraph(address.country.name, styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) #elements.append(Paragraph(title, styles['InfoTitleVeryLargeCenter'])) #elements.append(Paragraph(approval.activity, styles['InfoTitleLargeLeft'])) elements.append(Paragraph('APPROVAL OF PROPOSAL {} {} TO UNDERTAKE DISTURBANCE ACTIVITY IN {}'.format(title, proposal.lodgement_number, region_district), styles['InfoTitleLargeLeft'])) #import ipdb; ipdb.set_trace() #elements.append(Paragraph(approval.tenure if hasattr(approval, 'tenure') else '', styles['InfoTitleLargeRight'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('The submitted proposal {} {} has been assessed and approved. The approval is granted on the understanding that: '.format(title, proposal.lodgement_number), styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) list_of_bullets= [] list_of_bullets.append('The potential impacts of the proposal on values the department manages have been removed or minimised to a level \'As Low As Reasonably Practicable\' (ALARP) and the proposal is consistent with departmental objectives, associated management plans and the land use category/s in the activity area.') list_of_bullets.append('Approval is granted for the period {} to {}. This approval is not valid if {} makes changes to what has been proposed or the proposal has expired. To change the proposal or seek an extension, the proponent must re-submit the proposal for assessment.'.format(approval.start_date.strftime(DATE_FORMAT), approval.expiry_date.strftime(DATE_FORMAT),_format_name(approval.applicant))) list_of_bullets.append('The proponent accepts responsibility for advising {} of new information or unforeseen threats that may affect the risk of the proposed activity.'.format(settings.DEP_NAME_SHORT)) list_of_bullets.append('Information provided by {0} for the purposes of this proposal will not be provided to third parties without permission from {0}.'.format(settings.DEP_NAME_SHORT)) list_of_bullets.append('The proponent accepts responsibility for supervising and monitoring implementation of activity/ies to ensure compliance with this proposal. {} reserves the right to request documents and records demonstrating compliance for departmental monitoring and auditing.'.format(settings.DEP_NAME_SHORT)) list_of_bullets.append('Non-compliance with the conditions of the proposal may trigger a suspension or withdrawal of the approval for this activity.') list_of_bullets.append('Management actions listed in Appendix 1 are implemented.') understandingList = ListFlowable( [ListItem(Paragraph(a, styles['Left']), bulletColour='black', value='circle') for a in list_of_bullets], bulletFontName=BOLD_FONTNAME, bulletFontSize=SMALL_FONTSIZE, bulletType='bullet') #bulletFontName=BOLD_FONTNAME elements.append(understandingList) # proposal requirements requirements = proposal.requirements.all().exclude(is_deleted=True) if requirements.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('The following requirements must be satisfied for the approval of the proposal not to be withdrawn:', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable( [Paragraph(a.requirement, styles['Left']) for a in requirements.order_by('order')], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) # if copied_to_permit: # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # elements.append(Paragraph('Assessor Comments', styles['BoldLeft'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # for k,v in copied_to_permit: # elements.append(Paragraph(v.encode('UTF-8'), styles['Left'])) # elements.append(Paragraph(k.encode('UTF-8'), styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements += _layout_extracted_fields(approval.extracted_fields) # additional information '''if approval.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(approval.additional_information)''' # delegation holds the dates, approvale and issuer details. delegation = [] # dates and licensing officer # dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), # ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) # delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), # Paragraph('Date of Expiry', styles['BoldLeft'])] # date_values = [Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['Left']), # Paragraph(approval.start_date.strftime(DATE_FORMAT), styles['Left']), # Paragraph(approval.expiry_date.strftime(DATE_FORMAT), styles['Left'])] # if approval.original_issue_date is not None: # date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) # date_values.insert(0, Paragraph(approval.original_issue_date.strftime(DATE_FORMAT), styles['Left'])) # delegation.append(Table([[date_headings, date_values]], # colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), # style=dates_licensing_officer_table_style)) # proponent details # delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) # address = proposal.applicant.organisation.postal_address # address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), # Paragraph(address.line3, styles['Left']), # Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), # Paragraph(address.country.name, styles['Left'])] # delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], # [Paragraph(_format_name(approval.applicant), # styles['Left'])] + address_paragraphs]], # colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), # style=approval_table_style)) if user.phone_number: contact_number = user.phone_number elif user.mobile_number: contact_number = user.mobile_number else: contact_number= settings.DEP_PHONE delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Should you have any queries about this approval, please contact {} {}, ' 'on {} or by email at {}'.format(user.first_name, user.last_name, contact_number, user.email), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('To provide feedback on the system used to submit the approval or update contact details, please ' 'contact {} Works Coordinator - {}'.format(settings.SYSTEM_NAME_SHORT, settings.SUPPORT_EMAIL), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Approved on behalf of the', styles['Left'])) delegation.append(Paragraph('{}'.format(settings.DEP_NAME), styles['BoldLeft'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('{} {}'.format(user.first_name, user.last_name), styles['Left'])) delegation.append(Paragraph('{}'.format(region_district), styles['Left'])) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph(approval.issue_date.strftime(DATE_FORMAT), styles['Left'])) elements.append(KeepTogether(delegation)) # Appendix section elements.append(PageBreak()) elements.append(Paragraph('Appendix 1 - Management Actions', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) if copied_to_permit: # for k,v in copied_to_permit: # elements.append(Paragraph(v.encode('UTF-8'), styles['Left'])) # elements.append(Paragraph(k.encode('UTF-8'), styles['Left'])) # elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) for item in copied_to_permit: for key in item: elements.append(Paragraph(key.encode('UTF-8'), styles['Left'])) elements.append(Paragraph(item[key].encode('UTF-8'), styles['Left'])) else: elements.append(Paragraph('There are no management actions.', styles['Left'])) doc.build(elements) return approval_buffer
def _create_licence(licence_buffer, licence, application): site_url = settings.SITE_URL every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame], onPage=_create_licence_header) doc = BaseDocTemplate(licence_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.licence = licence doc.site_url = site_url licence_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] title = licence.title.encode('UTF-8') elements.append(Paragraph(title, styles['InfoTitleVeryLargeCenter'])) elements.append(Paragraph(licence.activity, styles['InfoTitleLargeLeft'])) elements.append(Paragraph(licence.region, styles['InfoTitleLargeLeft'])) elements.append(Paragraph(licence.tenure if licence.tenure else '', styles['InfoTitleLargeRight'])) # application conditions if application.conditions.exists(): elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Conditions', styles['BoldLeft'])) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) conditionList = ListFlowable( [Paragraph(a.condition, styles['Left']) for a in application.conditions.order_by('order')], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) elements += _layout_extracted_fields(licence.extracted_fields) # additional information '''if licence.additional_information: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Additional Information', styles['BoldLeft'])) elements += _layout_paragraphs(licence.additional_information)''' # delegation holds the dates, licencee and issuer details. delegation = [] # dates and licensing officer dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), Paragraph('Date of Expiry', styles['BoldLeft'])] date_values = [Paragraph(licence.issue_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.start_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.expiry_date.strftime(DATE_FORMAT), styles['Left'])] if licence.original_issue_date is not None: date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) date_values.insert(0, Paragraph(licence.original_issue_date.strftime(DATE_FORMAT), styles['Left'])) delegation.append(Table([[date_headings, date_values]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=dates_licensing_officer_table_style)) # proponent details delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = application.applicant.organisation.postal_address address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left'])] delegation.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], [Paragraph(_format_name(licence.applicant), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=licence_table_style)) delegation.append(Spacer(1, SECTION_BUFFER_HEIGHT)) delegation.append(Paragraph('Issued by a Wildlife Licensing Officer of the {} ' 'under delegation from the Minister for Environment pursuant to section 133(1) ' 'of the Conservation and Land Management Act 1984.'.format(settings.DEP_NAME), styles['Left'])) elements.append(KeepTogether(delegation)) doc.build(elements) return licence_buffer
def _create_licence(licence_buffer, licence, application, site_url, original_issue_date): every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN, PAGE_HEIGHT - 160, id='EveryPagesFrame') every_page_template = PageTemplate(id='EveryPages', frames=every_page_frame, onPage=_create_header) doc = BaseDocTemplate(licence_buffer, pageTemplates=[every_page_template], pagesize=A4) # this is the only way to get data into the onPage callback function doc.licence = licence doc.site_url = site_url licence_table_style = TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]) elements = [] elements.append(Paragraph(licence.licence_type.act, styles['InfoTitleLargeCenter'])) elements.append(Paragraph(licence.licence_type.code.upper(), styles['InfoTitleLargeCenter'])) elements.append(Paragraph(licence.licence_type.name, styles['InfoTitleVeryLargeCenter'])) elements.append(Paragraph(licence.licence_type.statement, styles['InfoTitleLargeLeft'])) elements.append(Paragraph(licence.licence_type.authority, styles['InfoTitleLargeRight'])) # licence conditions elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Paragraph('Conditions', styles['InfoTitleLargeCenter'])) conditionList = ListFlowable([Paragraph(condition.text, styles['Left']) for condition in application.conditions.all()], bulletFontName=BOLD_FONTNAME, bulletFontSize=MEDIUM_FONTSIZE) elements.append(conditionList) # purpose if licence.purpose: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) purposes = [] for purpose in licence.purpose.split('\r\n'): if purpose: purposes.append(Paragraph(purpose, styles['Left'])) else: purposes.append(Spacer(1, SECTION_BUFFER_HEIGHT)) elements.append(Table([[Paragraph('Purpose', styles['BoldLeft']), purposes]], colWidths=(100, PAGE_WIDTH - (2 * PAGE_MARGIN) - 100), style=licence_table_style)) # authorised persons authorised_persons = _get_authorised_person_names(application) if len(authorised_persons) > 0: elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) authorized_persons = [Paragraph(ap, styles['Left']) for ap in authorised_persons] elements.append(Table([[Paragraph('Authorised Persons', styles['BoldLeft']), authorized_persons]], colWidths=(100, PAGE_WIDTH - (2 * PAGE_MARGIN) - 100), style=licence_table_style)) # dates and licensing officer dates_licensing_officer_table_style = TableStyle([('VALIGN', (0, 0), (-2, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'BOTTOM')]) elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) date_headings = [Paragraph('Date of Issue', styles['BoldLeft']), Paragraph('Valid From', styles['BoldLeft']), Paragraph('Date of Expiry', styles['BoldLeft'])] date_values = [Paragraph(licence.issue_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.start_date.strftime(DATE_FORMAT), styles['Left']), Paragraph(licence.end_date.strftime(DATE_FORMAT), styles['Left'])] if original_issue_date is not None: date_headings.insert(0, Paragraph('Original Date of Issue', styles['BoldLeft'])) date_values.insert(0, Paragraph(original_issue_date.strftime(DATE_FORMAT), styles['Left'])) elements.append(Table([[date_headings, date_values, Paragraph('Licensing Officer', styles['BoldRight'])]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 200, 80), style=dates_licensing_officer_table_style)) # licensee details elements.append(Spacer(1, SECTION_BUFFER_HEIGHT)) address = application.applicant_profile.postal_address address_paragraphs = [Paragraph(address.line1, styles['Left']), Paragraph(address.line2, styles['Left']), Paragraph(address.line3, styles['Left']), Paragraph('%s %s %s' % (address.locality, address.state, address.postcode), styles['Left']), Paragraph(address.country.name, styles['Left'])] elements.append(Table([[[Paragraph('Licensee:', styles['BoldLeft']), Paragraph('Address', styles['BoldLeft'])], [Paragraph(render_user_name(application.applicant_profile.user), styles['Left'])] + address_paragraphs]], colWidths=(120, PAGE_WIDTH - (2 * PAGE_MARGIN) - 120), style=licence_table_style)) doc.build(elements) return licence_buffer