Skip to content

Commit

Permalink
Merge pull request #473 from NishantPhour/main
Browse files Browse the repository at this point in the history
task#6956
  • Loading branch information
xzzy authored Oct 17, 2024
2 parents 2c7c126 + f150e0e commit c4090c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
11 changes: 5 additions & 6 deletions mooringlicensing/components/proposals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ def vessel_rego_document(self, request, *args, **kwargs):

return Response({'filedata': returned_file_data})


@detail_route(methods=['POST'], detail=True)
@renderer_classes((JSONRenderer,))
@basic_exception_handler
Expand Down Expand Up @@ -1859,7 +1860,6 @@ def approval_level_document(self, request, *args, **kwargs):
@detail_route(methods=['POST',], detail=True)
@basic_exception_handler
def final_approval(self, request, *args, **kwargs):
print('final_approval() in ProposalViewSet')
instance = self.get_object()
serializer = ProposedApprovalSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down Expand Up @@ -2509,9 +2509,9 @@ def find_related_approvals(self, request, *args, **kwargs):
def lookup_vessel_ownership(self, request, *args, **kwargs):
vessel = self.get_object()
if is_internal(request):
serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.distinct("owner"), many=True)
serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.order_by("owner","-updated").distinct("owner"), many=True)
else:
serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.filter(owner__emailuser=request.user.id).distinct("owner"), many=True)
serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.filter(owner__emailuser=request.user.id).order_by("owner","-updated").distinct("owner"), many=True)
return Response(serializer.data)

@detail_route(methods=['GET',], detail=True)
Expand Down Expand Up @@ -2611,8 +2611,7 @@ def list_internal(self, request, *args, **kwargs):
raise serializers.ValidationError("error")
else:
raise serializers.ValidationError("no email user id provided")

vessel_ownership_list = owner.vesselownership_set.distinct("vessel")
vessel_ownership_list = owner.vesselownership_set.order_by("vessel","-updated").distinct("vessel")

# TODO review - rewrite following for vessel_ownership_list
if search_text:
Expand All @@ -2639,7 +2638,7 @@ def list_external(self, request, *args, **kwargs):
owner_qs = Owner.objects.filter(emailuser=request.user.id)
if owner_qs:
owner = owner_qs[0]
vessel_ownership_list = owner.vesselownership_set.distinct("vessel")
vessel_ownership_list = owner.vesselownership_set.order_by("vessel","-updated").distinct("vessel")

# rewrite following for vessel_ownership_list
if search_text:
Expand Down
4 changes: 2 additions & 2 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ def get_previous_vessel_ownerships(self):
while True:
if proposal.previous_application:
if proposal.previous_application.vessel_ownership:
if proposal.previous_application.vessel_ownership.excludable(proposal):
vessel_ownerships.append(proposal.previous_application.vessel_ownership)
#if proposal.previous_application.vessel_ownership.excludable(proposal):
vessel_ownerships.append(proposal.previous_application.vessel_ownership)

if get_out_of_loop:
break
Expand Down
10 changes: 8 additions & 2 deletions mooringlicensing/components/proposals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,8 @@ def validate(self, data):
class VesselOwnershipSerializer(serializers.ModelSerializer):
# company_ownership = CompanyOwnershipSerializer()
company_ownership = serializers.SerializerMethodField()

proposal_id = serializers.SerializerMethodField()

class Meta:
model = VesselOwnership
fields = '__all__'
Expand All @@ -1660,7 +1661,12 @@ def get_company_ownership(self, obj):
data = serializer.data
return data


def get_proposal_id(self, obj):
proposal = Proposal.objects.filter(vessel_ownership=obj).last()
if(proposal):
return proposal.id
return None

class VesselFullOwnershipSerializer(serializers.ModelSerializer):
# company_ownership = CompanyOwnershipSerializer()
company_ownership = serializers.SerializerMethodField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,13 @@ export default {
},
vesselRegoDocumentUrl: function () {
let url = ''
if (this.proposal){
if (this.proposal && this.proposal.id){
// Call a function defined in the ProposalViewSet
url = '/api/proposal/' + this.proposal.id + '/vessel_rego_document/'
}
else if (this.vesselOwnership.proposal_id){
url = '/api/proposal/' + this.vesselOwnership.proposal_id + '/vessel_rego_document/'
}
return url
},
// vesselRegistrationDocumentUrl: function () {
Expand All @@ -427,6 +430,10 @@ export default {
// Call a function defined in the ProposalViewSet
url = '/api/proposal/' + this.proposal.id + '/hull_identification_number_document/'
}
else if (this.vesselOwnership.proposal_id){
url = '/api/proposal/' + this.vesselOwnership.proposal_id + '/hull_identification_number_document/'
console.log(url)
}
return url
},
companyName: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export default {
},
delete_all_documents: function(){
console.log('aho')
for (let item of this.documents){
this.delete_document(item)
}
Expand Down

0 comments on commit c4090c3

Please sign in to comment.