From 03a3f550d0cf31f005ae04e2da720ee14d739f63 Mon Sep 17 00:00:00 2001 From: Nishant Date: Wed, 23 Oct 2024 09:40:13 +0800 Subject: [PATCH 1/5] amendment shows previous proposal attachments --- mooringlicensing/components/proposals/api.py | 25 +++++++++++------ .../components/proposals/models.py | 28 +++++++++++++++++-- .../components/proposals/utils.py | 3 +- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/mooringlicensing/components/proposals/api.py b/mooringlicensing/components/proposals/api.py index 3b8622255..f8f9d9aed 100755 --- a/mooringlicensing/components/proposals/api.py +++ b/mooringlicensing/components/proposals/api.py @@ -1303,10 +1303,14 @@ def vessel_rego_document(self, request, *args, **kwargs): pass elif action == 'delete': document_id = request.data.get('document_id') - document = VesselRegistrationDocument.objects.get( - proposal=instance, - id=document_id, - ) + try: + document = VesselRegistrationDocument.objects.get( + proposal=instance, + id=document_id, + can_delete=True, + ) + except: + raise serializers.ValidationError("Vessel Registration Document can't be deleted") if document._file and os.path.isfile(document._file.path): os.remove(document._file.path) if document: @@ -1430,10 +1434,15 @@ def hull_identification_number_document(self, request, *args, **kwargs): pass elif action == 'delete': document_id = request.data.get('document_id') - document = HullIdentificationNumberDocument.objects.get( - proposal=instance, - id=document_id, - ) + try: + document = HullIdentificationNumberDocument.objects.get( + proposal=instance, + id=document_id, + can_delete=True, + ) + except: + raise serializers.ValidationError("Hull Identification Number Document can't be deleted") + if document._file and os.path.isfile(document._file.path): os.remove(document._file.path) if document: diff --git a/mooringlicensing/components/proposals/models.py b/mooringlicensing/components/proposals/models.py index 907ae56a1..417a8bbd3 100644 --- a/mooringlicensing/components/proposals/models.py +++ b/mooringlicensing/components/proposals/models.py @@ -443,13 +443,30 @@ def copy_written_proof_documents(self, proposal): if link_item.enabled: # Create link to the proposal only when the doc is not deleted. ProposalWrittenProofDocument.objects.create(proposal=proposal, written_proof_document=doc) - + def copy_signed_licence_agreement_documents(self, proposal): for doc in self.signed_licence_agreement_documents.all(): link_item = ProposalSignedLicenceAgreementDocument.objects.get(proposal=self, signed_licence_agreement_document=doc) if link_item.enabled: # Create link to the proposal only when the doc is not deleted. ProposalSignedLicenceAgreementDocument.objects.create(proposal=proposal, signed_licence_agreement_document=doc) + def copy_vessel_registration_documents(self, proposal): + doc_list = VesselRegistrationDocument.objects.filter(proposal=self) + if doc_list.count() > 0: + doc = doc_list.last() #get the latest vesssel registration document + doc.pk = None + doc.proposal = proposal + doc.can_delete = True + doc.save() + + def copy_hull_identification_number_document(self, proposal): + doc_list = HullIdentificationNumberDocument.objects.filter(proposal=self) + if doc_list.count() > 0: + doc = doc_list.last() #get the latest vesssel registration document + doc.pk = None + doc.proposal = proposal + doc.can_delete = True + doc.save() def __str__(self): return str(self.lodgement_number) @@ -2150,7 +2167,9 @@ def renew_approval(self,request): self.copy_mooring_report_documents(proposal) self.copy_written_proof_documents(proposal) self.copy_signed_licence_agreement_documents(proposal) - + + self.copy_vessel_registration_documents(proposal) + self.copy_hull_identification_number_document(proposal) req=self.requirements.all().exclude(is_deleted=True) from copy import deepcopy if req: @@ -2200,7 +2219,9 @@ def amend_approval(self,request): self.copy_mooring_report_documents(proposal) self.copy_written_proof_documents(proposal) self.copy_signed_licence_agreement_documents(proposal) - + + self.copy_vessel_registration_documents(proposal) + self.copy_hull_identification_number_document(proposal) req=self.requirements.all().exclude(is_deleted=True) from copy import deepcopy if req: @@ -5115,6 +5136,7 @@ def upload_to(self, filename): can_delete = models.BooleanField(default=True) # after initial submit prevent document from being deleted can_hide= models.BooleanField(default=False) # after initial submit, document cannot be deleted but can be hidden hidden=models.BooleanField(default=False) # after initial submit prevent document from being deleted + # test proposal = models.ForeignKey(Proposal, null=True, blank=True, related_name='temp_vessel_registration_documents', on_delete=models.CASCADE) original_file_name = models.CharField(max_length=512, null=True, blank=True) diff --git a/mooringlicensing/components/proposals/utils.py b/mooringlicensing/components/proposals/utils.py index 6c5c7e725..c758ac77c 100644 --- a/mooringlicensing/components/proposals/utils.py +++ b/mooringlicensing/components/proposals/utils.py @@ -960,7 +960,8 @@ def handle_vessel_registrarion_documents_in_limbo(proposal_id, vessel_ownership) for doc in documents_in_limbo: doc.vessel_ownership = vessel_ownership # Link to the vessel_ownership - doc.proposal = None # Unlink to the proposal. This link is used when proposal is draft and vessel_ownership is unknown. + doc.can_delete = False + # doc.proposal = None # Unlink to the proposal. This link is used when proposal is draft and vessel_ownership is unknown. doc.save() logger.info(f'VesselRegistrationFile: {doc} has had a link to the vessel_ownership: {vessel_ownership}') From 0610242ef540ab2437d240529c340fd225e41792 Mon Sep 17 00:00:00 2001 From: Nishant Date: Wed, 23 Oct 2024 10:38:31 +0800 Subject: [PATCH 2/5] display appliact and company name dropdown select fix --- .../mooringlicensing/src/components/common/vessels.vue | 9 ++++++++- .../mooringlicensing/src/components/user/profile.vue | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue index a9736acc2..763268f8d 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue @@ -599,9 +599,16 @@ export default { } return query; }, + processResults: function(data, params){ // This function is called after the results are returned. + // Mainly used for modifying the items before being displayed. + console.log({data}) + return { + results: data.results, // This is the array of items to be displayed + } + } }, }). - on("select2:select", async function (e) { + on("select2:select", function (e) { var selected = $(e.currentTarget); let data = e.params.data.id; vm.$nextTick(async () => { diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/user/profile.vue b/mooringlicensing/frontend/mooringlicensing/src/components/user/profile.vue index 92c59bfa3..4f8e499ba 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/user/profile.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/user/profile.vue @@ -466,10 +466,11 @@ export default { getApplicantDisplay: function () { let vm = this; console.log("getApplicantDisplay") + let display = null if (vm.profile.legal_first_name) { - let display = vm.profile.legal_first_name + " " + vm.profile.legal_last_name + " (DOB: "+vm.profile.legal_dob+")"; + display = vm.profile.legal_first_name + " " + vm.profile.legal_last_name + " (DOB: "+vm.profile.legal_dob+")"; } else { - let display = vm.profile.first_name + " " + vm.profile.last_name + " (DOB: "+vm.profile.legal_dob+")"; + display = vm.profile.first_name + " " + vm.profile.last_name + " (DOB: "+vm.profile.legal_dob+")"; } var newOption = new Option(display, vm.profile.id, false, true); $('#person_lookup').append(newOption); From 2b207e481e7bc83e5e3a30455b455ae245f900f0 Mon Sep 17 00:00:00 2001 From: Nishant Date: Fri, 25 Oct 2024 12:31:22 +0800 Subject: [PATCH 3/5] company select dropdown fix --- .../src/components/common/vessels.vue | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue index 458aa7413..0a5f54f17 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue @@ -574,7 +574,6 @@ export default { return data; }, initialiseCompanyNameSelect: async function () { - console.log('in initialiseCompanyNameSelect()') let vm = this; // Vessel search $(vm.$refs.company_name).select2({ @@ -582,13 +581,13 @@ export default { "theme": "bootstrap", placeholder: "", tags: true, - createTag: function (tag) { - return { - id: tag.term, - text: tag.term, - tag: true - }; - }, + // createTag: function (tag) { + // return { + // id: tag.term, + // text: tag.term, + // tag: true + // }; + // }, ajax: { url: api_endpoints.company_names, dataType: 'json', @@ -599,16 +598,22 @@ export default { } return query; }, - processResults: function(data, params){ // This function is called after the results are returned. - // Mainly used for modifying the items before being displayed. - console.log({data}) + processResults: function(data, params) { + const searchOption = { + id: params.term, + text: params.term , + tag : true + }; return { - results: data.results, // This is the array of items to be displayed - } - } + results: [searchOption, + ...data.results + + ], + }; + }, }, }). - on("select2:select", function (e) { + on("select2:select", async function (e) { var selected = $(e.currentTarget); let data = e.params.data.id; vm.$nextTick(async () => { From 1ce8f7d56f447b1cdb47048715f47af67a27c4f0 Mon Sep 17 00:00:00 2001 From: Nishant Date: Fri, 25 Oct 2024 16:27:25 +0800 Subject: [PATCH 4/5] organisation filter changed to lookup --- mooringlicensing/components/approvals/api.py | 2 +- mooringlicensing/components/proposals/api.py | 19 ++++-- .../common/table_dcv_admissions.vue | 64 ++++++++++++++----- .../components/common/table_dcv_permits.vue | 58 +++++++++++++---- 4 files changed, 109 insertions(+), 34 deletions(-) diff --git a/mooringlicensing/components/approvals/api.py b/mooringlicensing/components/approvals/api.py index f8ae51181..c49e4db9e 100755 --- a/mooringlicensing/components/approvals/api.py +++ b/mooringlicensing/components/approvals/api.py @@ -1522,7 +1522,7 @@ def filter_queryset(self, request, queryset, view): # filter by dcv_organisation filter_organisation_id = request.GET.get('filter_dcv_organisation_id') if filter_organisation_id and not filter_organisation_id.lower() == 'all': - queryset = queryset.filter(dcv_vessel__dcv_organisation__id=filter_organisation_id) + queryset = queryset.filter(dcv_organisation__id=filter_organisation_id) queries = Q() # filter by date from diff --git a/mooringlicensing/components/proposals/api.py b/mooringlicensing/components/proposals/api.py index 15fc4a512..589527abf 100755 --- a/mooringlicensing/components/proposals/api.py +++ b/mooringlicensing/components/proposals/api.py @@ -127,14 +127,21 @@ logger = logging.getLogger(__name__) class GetDcvOrganisations(views.APIView): - + print("outside") def get(self, request, format=None): + print("inside fun") + search_term = request.GET.get('search_term', '') + print("this is search") + print(search_term) if is_internal(request): #currently only used internally, but may be acceptable for external access - data = DcvOrganisation.objects.all() - data_transform = [{'id': org.id, 'name': org.name} for org in data] - return Response(data_transform) - - + if search_term: + data = DcvOrganisation.objects.filter(name__icontains=search_term)[:10] + print("THIS IS THE DATA") + print(data) + data_transform = [{'id': org.id, 'name': org.name} for org in data] + return Response({"results": data_transform}) + return Response() + class GetDcvVesselRegoNos(views.APIView): def get(self, request, format=None): diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_admissions.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_admissions.vue index 9a94274a2..e9de9107a 100644 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_admissions.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_admissions.vue @@ -3,11 +3,16 @@
- - + +
@@ -303,6 +308,43 @@ export default { } }, methods: { + initialiseOrganisationLookup: function(){ + let vm = this; + $(vm.$refs.organisation_lookup).select2({ + minimumInputLength: 2, + theme: "bootstrap", + allowClear: true, + placeholder: "", + ajax: { + url: api_endpoints.dcv_organisations, + dataType: 'json', + data: function(params) { + return { + search_term: params.term, + } + }, + processResults: function(data) { + const results = data.results.map(org => ({ + id: org.id, + text: org.name + })); + return { + results: results, + }; + }, + }, + }) + .on("select2:select", function (e) { + vm.filterDcvOrganisation = e.params.data.id; + }) + .on("select2:unselect", function (e) { + vm.filterDcvOrganisation = null; + }) + .on("select2:open", function (e) { + const searchField = $('[aria-controls="select2-organisation_lookup-results"]'); + searchField[0].focus(); + }); + }, new_application_button_clicked: function(){ if (this.is_internal){ this.$router.push({ @@ -315,16 +357,6 @@ export default { }) } }, - fetchFilterLists: function(){ - let vm = this; - - // DcvOrganisation list - vm.$http.get(api_endpoints.dcv_organisations).then((response) => { - vm.dcv_organisations = response.body - },(error) => { - console.log(error); - }) - }, addEventListeners: function(){ let vm = this @@ -371,12 +403,12 @@ export default { }, created: function(){ console.log('table_applications created') - this.fetchFilterLists() }, mounted: function(){ let vm = this; this.$nextTick(() => { vm.addEventListeners(); + vm.initialiseOrganisationLookup(); }); } } diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_permits.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_permits.vue index 407fd4ad8..51ad10da9 100644 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_permits.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/table_dcv_permits.vue @@ -4,10 +4,15 @@
- +
@@ -333,6 +338,43 @@ export default { } }, methods: { + initialiseOrganisationLookup: function(){ + let vm = this; + $(vm.$refs.organisation_lookup1).select2({ + minimumInputLength: 2, + theme: "bootstrap", + allowClear: true, + placeholder: "", + ajax: { + url: api_endpoints.dcv_organisations, + dataType: 'json', + data: function(params) { + return { + search_term: params.term, + } + }, + processResults: function(data) { + const results = data.results.map(org => ({ + id: org.id, + text: org.name + })); + return { + results: results, + }; + }, + }, + }) + .on("select2:select", function (e) { + vm.filterDcvOrganisation = e.params.data.id; + }) + .on("select2:unselect", function (e) { + vm.filterDcvOrganisation = null; + }) + .on("select2:open", function (e) { + const searchField = $('[aria-controls="select2-organisation_lookup-results"]'); + searchField[0].focus(); + }); + }, sendDataForCreateNewSticker: function(params){ let vm = this vm.$http.post('/api/internal_dcv_permit/' + params.dcv_permit_id + '/create_new_sticker/', params).then( @@ -445,13 +487,6 @@ export default { }, fetchFilterLists: function(){ let vm = this; - - // DcvOrganisation list - vm.$http.get(api_endpoints.dcv_organisations).then((response) => { - vm.dcv_organisations = response.body - },(error) => { - console.log(error); - }) // FeeSeason list //vm.$http.get(api_endpoints.fee_seasons_dict + '?application_type_codes=dcvp').then((response) => { vm.$http.get(api_endpoints.fee_seasons_dict + '?application_type_codes=dcvp').then((response) => { @@ -488,6 +523,7 @@ export default { let vm = this; this.$nextTick(() => { vm.addEventListeners(); + vm.initialiseOrganisationLookup() }); } } From 925eef060fa649f421abeaf96d73350d23ca966d Mon Sep 17 00:00:00 2001 From: Nishant Date: Fri, 25 Oct 2024 16:32:14 +0800 Subject: [PATCH 5/5] update --- mooringlicensing/components/proposals/api.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mooringlicensing/components/proposals/api.py b/mooringlicensing/components/proposals/api.py index 589527abf..622b79d59 100755 --- a/mooringlicensing/components/proposals/api.py +++ b/mooringlicensing/components/proposals/api.py @@ -127,17 +127,11 @@ logger = logging.getLogger(__name__) class GetDcvOrganisations(views.APIView): - print("outside") def get(self, request, format=None): - print("inside fun") search_term = request.GET.get('search_term', '') - print("this is search") - print(search_term) if is_internal(request): #currently only used internally, but may be acceptable for external access if search_term: data = DcvOrganisation.objects.filter(name__icontains=search_term)[:10] - print("THIS IS THE DATA") - print(data) data_transform = [{'id': org.id, 'name': org.name} for org in data] return Response({"results": data_transform}) return Response()