Esempio n. 1
0
 def get(self, request, format=None):
     return Response({
         'template_group': settings.DOMAIN_DETECTED,
         'is_das_admin': True if is_disturbance_admin(request) else False,
         'is_apiary_admin': True if is_apiary_admin(request) else False,
         'is_das_apiary_admin': True if is_das_apiary_admin(request) else False,
     })
Esempio n. 2
0
    def approvals_external(self, request, *args, **kwargs):
        """
        Paginated serializer for datatables - used by the internal and external dashboard (filtered by the get_queryset method)

        To test:
            http://localhost:8000/api/approval_paginated/approvals_external/?format=datatables&draw=1&length=2
        """

        #qs = self.queryset().order_by('lodgement_number', '-issue_date').distinct('lodgement_number')
        #qs = ProposalFilterBackend().filter_queryset(self.request, qs, self)

        #ids = self.get_queryset().distinct('lodgement_number').values_list('id', flat=True)
        ids = self.get_queryset().order_by('lodgement_number', '-issue_date').distinct('lodgement_number').values_list('id', flat=True)
        #qs = Approval.objects.filter(id__in=ids)
        #web_url = request.META.get('HTTP_HOST', None)
        template_group = get_template_group(request)
        if template_group == 'apiary':
            #qs = self.get_queryset().filter(application_type__apiary_group_application_type=True)
            qs = self.get_queryset().filter(
                    apiary_approval=True
                    ).filter(id__in=ids)
        else:
            if is_das_apiary_admin(self.request):
                qs = self.get_queryset()
            else:
                qs = self.get_queryset().exclude(
                        apiary_approval=True
                        ).filter(id__in=ids)

        #if template_group == 'apiary':
        #    qs = self.get_queryset().filter(
        #            apiary_approval=True
        #            ).filter(id__in=ids)
        #else:
        #    qs = self.get_queryset().exclude(
        #            apiary_approval=True
        #            ).filter(id__in=ids)
        qs = self.filter_queryset(qs)

        # on the internal organisations dashboard, filter the Proposal/Approval/Compliance datatables by applicant/organisation
        applicant_id = request.GET.get('org_id')
        if applicant_id:
            # qs = qs.filter(org_applicant_id=applicant_id)
            qs = qs.filter(applicant__id=applicant_id)
        submitter_id = request.GET.get('submitter_id', None)
        if submitter_id:
            qs = qs.filter(submitter_id=submitter_id)

        # Set default order
        #qs = qs.order_by('-lodgement_number', '-issue_date')

        self.paginator.page_size = qs.count()
        result_page = self.paginator.paginate_queryset(qs, request)
        #import ipdb; ipdb.set_trace()
        serializer = DTApprovalSerializer(result_page, context={
            'request':request,
            'template_group': template_group
            }, many=True)
        return self.paginator.get_paginated_response(serializer.data)
Esempio n. 3
0
 def get_queryset(self, request):
     #import ipdb;ipdb.set_trace()
     # filter based on membership of Apiary Admin or Disturbance Admin
     qs = super(ProposalStandardRequirementAdmin,
                self).get_queryset(request)
     if request.user.is_superuser or is_das_apiary_admin(request):
         return qs
     group_list = []
     if is_apiary_admin(request):
         group_list.append('apiary')
     if is_disturbance_admin(request):
         group_list.append('disturbance')
     return qs.filter(system__in=group_list)
Esempio n. 4
0
 def formfield_for_choice_field(self, db_field, request, **kwargs):
     if db_field.name == 'system':
         if (request.user.is_superuser or is_das_apiary_admin(request) or
             (is_apiary_admin(request) and is_disturbance_admin(request))):
             # user will see both choices
             kwargs["choices"] = (
                 ('apiary', 'Apiary'),
                 ('disturbance', 'Disturbance'),
             )
         elif is_apiary_admin(request):
             kwargs["choices"] = (('apiary', 'Apiary'), )
         elif is_disturbance_admin(request):
             kwargs["choices"] = (('disturbance', 'Disturbance'), )
     return super(ProposalStandardRequirementAdmin,
                  self).formfield_for_choice_field(db_field, request,
                                                   **kwargs)