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)
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, })
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)
def is_apiary_admin(context): # checks if user is an AdminUser request = context['request'] return disturbance_helpers.is_apiary_admin(request)