Skip to content

Commit

Permalink
email work
Browse files Browse the repository at this point in the history
  • Loading branch information
NishantPhour committed Oct 10, 2024
2 parents 7a2b2ad + 2c6841b commit fa8b73e
Show file tree
Hide file tree
Showing 76 changed files with 382 additions and 6,804 deletions.
51 changes: 2 additions & 49 deletions mooringlicensing/components/approvals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
)
from mooringlicensing.components.users.utils import get_user_name
from mooringlicensing.components.users.serializers import UserSerializer
from mooringlicensing.components.organisations.models import Organisation, OrganisationContact
from mooringlicensing.helpers import is_customer, is_internal
from mooringlicensing.settings import PROPOSAL_TYPE_NEW, LOV_CACHE_TIMEOUT
from rest_framework_datatables.pagination import DatatablesPageNumberPagination
Expand Down Expand Up @@ -249,26 +248,19 @@ def get(self, request, format=None):


class ApprovalPaymentFilterViewSet(generics.ListAPIView):
""" https://cop-internal.dbca.wa.gov.au/api/filtered_organisations?search=Org1
"""
queryset = Approval.objects.none()
serializer_class = ApprovalPaymentSerializer
filter_backends = (filters.SearchFilter,)
search_fields = ('id',)

def get_queryset(self):
"""
Return All approvals associated with user (proxy_applicant and org_applicant)
Return All approvals associated with user
"""
user = self.request.user

# get all orgs associated with user
user_org_ids = OrganisationContact.objects.filter(email=user.email).values_list('organisation_id', flat=True)

now = datetime.now().date()
approval_qs = Approval.objects.filter(
Q(proxy_applicant=user) |
Q(org_applicant_id__in=user_org_ids) |
Q(current_proposal__proposal_applicant__email_user_id=user.id))
approval_qs = approval_qs.exclude(current_proposal__application_type__name='E Class')
approval_qs = approval_qs.exclude(expiry_date__lt=now)
Expand Down Expand Up @@ -394,17 +386,9 @@ def filter_queryset(self, request, queryset, view):
return queryset


class ApprovalRenderer(DatatablesRenderer):
def render(self, data, accepted_media_type=None, renderer_context=None):
if 'view' in renderer_context and hasattr(renderer_context['view'], '_datatables_total_count'):
data['recordsTotal'] = renderer_context['view']._datatables_total_count
return super(ApprovalRenderer, self).render(data, accepted_media_type, renderer_context)


class ApprovalPaginatedViewSet(viewsets.ModelViewSet):
filter_backends = (ApprovalFilterBackend,)
pagination_class = DatatablesPageNumberPagination
renderer_classes = (ApprovalRenderer,)
queryset = Approval.objects.none()
serializer_class = ListApprovalSerializer
search_fields = ['lodgement_number', ]
Expand Down Expand Up @@ -462,9 +446,7 @@ def get_queryset(self):
if is_internal(self.request):
return Approval.objects.all()
elif is_customer(self.request):
user_orgs = Organisation.objects.filter(delegates__contains=[self.request.user.id])
queryset = Approval.objects.filter(
Q(org_applicant__in=user_orgs) |
Q(current_proposal__proposal_applicant__email_user_id=self.request.user.id)
)
return queryset
Expand Down Expand Up @@ -1498,33 +1480,6 @@ def filter_queryset(self, request, queryset, view):
elif search_text.strip().lower() in DcvPermit.DCV_PERMIT_STATUS_EXPIRED:
status = DcvPermit.DCV_PERMIT_STATUS_EXPIRED

# common_search_criteria = (
# Q(lodgement_number__icontains=search_text) |
# Q(dcv_organisation__name__icontains=search_text) |
# Q(dcv_permit_fees__invoice_reference__icontains=search_text) |
# Q(fee_season__name__icontains=search_text) |
# Q(stickers__number__icontains=search_text)
# )
# # search_text
# if search_text:
# if status == DcvPermit.DCV_PERMIT_STATUS_CURRENT:
# queryset = queryset.filter(
# (Q(start_date__lte=target_date) & Q(end_date__gte=target_date)) |
# common_search_criteria
# )
# elif status == DcvPermit.DCV_PERMIT_STATUS_EXPIRED:
# queryset = queryset.filter(
# ~Q(Q(start_date__lte=target_date) & Q(end_date__gte=target_date)) |
# common_search_criteria
# )
# else:
# queryset = queryset.filter(
# common_search_criteria
# )

# getter = request.query_params.get
# fields = self.get_fields(getter)
# ordering = self.get_ordering(getter, fields)
fields = self.get_fields(request)
ordering = self.get_ordering(request, view, fields)
queryset = queryset.order_by(*ordering)
Expand Down Expand Up @@ -1917,9 +1872,7 @@ def get_queryset(self):
qs = WaitingListAllocation.objects.all()
return qs
elif is_customer(self.request):
user_orgs = Organisation.objects.filter(delegates__contains=[self.request.user.id])
queryset = WaitingListAllocation.objects.filter(Q(org_applicant__in=user_orgs) |
Q(current_proposal__proposal_applicant__email_user_id=self.request.user.id))
queryset = WaitingListAllocation.objects.filter(Q(current_proposal__proposal_applicant__email_user_id=self.request.user.id))
return queryset
logger.warn("User is neither customer nor internal user: {} <{}>".format(user.get_full_name(), user.email))
return WaitingListAllocation.objects.none()
Expand Down
Loading

0 comments on commit fa8b73e

Please sign in to comment.