Skip to content

Commit

Permalink
Merge pull request #475 from NishantPhour/main
Browse files Browse the repository at this point in the history
Latest Work
  • Loading branch information
xzzy authored Oct 28, 2024
2 parents d2a307c + 925eef0 commit 3c57824
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 56 deletions.
2 changes: 1 addition & 1 deletion mooringlicensing/components/approvals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 24 additions & 14 deletions mooringlicensing/components/proposals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@
logger = logging.getLogger(__name__)

class GetDcvOrganisations(views.APIView):

def get(self, request, format=None):
search_term = request.GET.get('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]
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):
Expand Down Expand Up @@ -1173,10 +1174,14 @@ def vessel_rego_document(self, request, *args, **kwargs):
action = request.data.get('action')
if 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:
Expand Down Expand Up @@ -1274,10 +1279,15 @@ def hull_identification_number_document(self, request, *args, **kwargs):
action = request.data.get('action')
if 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:
Expand Down
28 changes: 25 additions & 3 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,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)
Expand Down Expand Up @@ -2077,7 +2094,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:
Expand Down Expand Up @@ -2127,7 +2146,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:
Expand Down Expand Up @@ -5038,6 +5059,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)
Expand Down
3 changes: 2 additions & 1 deletion mooringlicensing/components/proposals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="">Organisation</label>
<select class="form-control" v-model="filterDcvOrganisation">
<option value="All">All</option>
<option v-for="org in dcv_organisations" :value="org.id">{{ org.name }}</option>
</select>
<label for="organisation_lookup">Organisation</label>
<select
id="organisation_lookup"
name="organisation_lookup"
ref="organisation_lookup"
class="form-control">
<option v-for="org in dcv_organisations" :key="org.id" :value="org.id">
{{ org.name }}
</option>
</select>
</div>
</div>
<div class="col-md-3">
Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand Down Expand Up @@ -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();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<div class="col-md-3">
<div class="form-group">
<label for="">Organisation</label>
<select class="form-control" v-model="filterDcvOrganisation">
<option value="All">All</option>
<option v-for="org in dcv_organisations" :value="org.id">{{ org.name }}</option>
</select>
<select
id="organisation_lookup1"
name="organisation_lookup1"
ref="organisation_lookup1"
class="form-control">
<option v-for="org in dcv_organisations" :key="org.id" :value="org.id">
{{ org.name }}
</option>
</select>
</div>
</div>
<div class="col-md-3">
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -488,6 +523,7 @@ export default {
let vm = this;
this.$nextTick(() => {
vm.addEventListeners();
vm.initialiseOrganisationLookup()
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,21 +574,20 @@ export default {
return data;
},
initialiseCompanyNameSelect: async function () {
console.log('in initialiseCompanyNameSelect()')
let vm = this;
// Vessel search
$(vm.$refs.company_name).select2({
minimumInputLength: 2,
"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',
Expand All @@ -599,6 +598,19 @@ export default {
}
return query;
},
processResults: function(data, params) {
const searchOption = {
id: params.term,
text: params.term ,
tag : true
};
return {
results: [searchOption,
...data.results
],
};
},
},
}).
on("select2:select", async function (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3c57824

Please sign in to comment.