def get_queryset(self): if is_internal(self.request): return Compliance.objects.all().exclude( processing_status='discarded') elif is_customer(self.request): user_orgs = [ org.id for org in self.request.user.mooringlicensing_organisations.all() ] queryset = Compliance.objects.filter( Q(proposal__org_applicant_id__in=user_orgs) | Q(proposal__submitter=self.request.user)).exclude( processing_status='discarded') return queryset return Compliance.objects.none()
def get_queryset(self): request_user = self.request.user qs = Compliance.objects.none() target_email_user_id = int( self.request.GET.get('target_email_user_id', 0)) if is_internal(self.request): if target_email_user_id: target_user = EmailUser.objects.get(id=target_email_user_id) qs = Compliance.objects.filter( Q(approval__submitter=target_user)) else: qs = Compliance.objects.all() elif is_customer(self.request): qs = Compliance.objects.filter(Q(approval__submitter=request_user)) return qs
def get_queryset(self): request_user = self.request.user # Filter by Type(s) according to the tables filter_approval_types = self.request.GET.get('filter_approval_types', '') filter_approval_types = filter_approval_types.split(',') q = Q() for filter_approval_type in filter_approval_types: if filter_approval_type: for item in Approval.__subclasses__(): if hasattr(item, 'code') and item.code == filter_approval_type: lookup = "{}__isnull".format(item._meta.model_name) q |= Q(**{lookup: False}) qs = Approval.objects.filter(q).order_by( '-id') if q else Approval.objects.none() if is_internal(self.request): return qs.all() elif is_customer(self.request): # Filter by to_be_endorsed filter_by_endorsement = self.request.GET.get( 'filter_by_endorsement', 'false') filter_by_endorsement = True if filter_by_endorsement.lower() in [ 'true', 'yes', 't', 'y', ] else False if filter_by_endorsement: # qs = qs.filter(authoriseduserpermit__endorsed_by=request_user) else: qs = qs.filter( Q(submitter=request_user )) # Not sure if the submitter is the licence holder return qs return qs