Example #1
0
 def get_non_children_queryset(self):
     fields = Location._fields_ordered
     query_params = {key: value or None for key, value in self.request.GET.items() if key in fields}
     user_profile = UserProfile.objects(user=self.request.user).first()
     user_group = self.request.user.group.name
     if user_profile and user_group in getattr(settings, "DISTRICT_GROUPS", []):
         user_locations = get_user_district_locations(self.request.user)
         query_params.update({"id__in": user_locations})
     return Location.objects(**query_params)
Example #2
0
 def get_non_children_queryset(self):
     fields = Location._fields_ordered
     query_params = {
         key: value or None
         for key, value in self.request.GET.items() if key in fields
     }
     user_profile = UserProfile.objects(user=self.request.user).first()
     user_group = self.request.user.group.name
     if user_profile and user_group in getattr(settings, 'DISTRICT_GROUPS',
                                               []):
         user_locations = get_user_district_locations(self.request.user)
         query_params.update({'id__in': user_locations})
     return Location.objects(**query_params)
Example #3
0
    def get_queryset(self):
        query_params = {key: value or None for key, value in self.request.GET.items()}
        user_group = self.request.user.group.name
        if user_group in getattr(settings, 'DISTRICT_GROUPS', []):
            target_locations = get_user_district_locations(self.request.user)
            query_params.update({'location__in': target_locations})

        if 'ordering' in query_params:
            ordering_params = query_params['ordering']
            del query_params['ordering']
            query_set = UserProfile.objects(**query_params).order_by('%s' % ordering_params)
        else:
            query_set = UserProfile.objects(**query_params).order_by('-created_at')
        return query_set
Example #4
0
    def get_queryset(self):
        query_params = Disaster.map_kwargs_to_db_params(self.request.GET.dict())

        location_queried = self.request.GET.get("location", None)
        if not location_queried:
            if self.request.user.has_perm("dms.can_view_disasters"):
                user_profile = UserProfile.objects(user=self.request.user).first()
                user_group = self.request.user.group.name
                if user_profile and user_group in getattr(settings, "DISTRICT_GROUPS", []):
                    user_locations = get_user_district_locations(self.request.user)
                    query_params.update({"locations__in": user_locations})
                else:
                    if not self.request.user.has_perm("dms.can_manage_disasters"):
                        user_location = user_profile.location.id
                        query_params.update({"locations__in": [user_location]})

        return Disaster.objects(**query_params)
Example #5
0
    def get_queryset(self):
        query_params = Disaster.map_kwargs_to_db_params(
            self.request.GET.dict())

        location_queried = self.request.GET.get('location', None)
        if not location_queried:
            if self.request.user.has_perm('dms.can_view_disasters'):
                user_profile = UserProfile.objects(
                    user=self.request.user).first()
                user_group = self.request.user.group.name
                if user_profile and user_group in getattr(
                        settings, 'DISTRICT_GROUPS', []):
                    user_locations = get_user_district_locations(
                        self.request.user)
                    query_params.update({'locations__in': user_locations})
                else:
                    if not self.request.user.has_perm(
                            'dms.can_manage_disasters'):
                        user_location = user_profile.location.id
                        query_params.update({'locations__in': [user_location]})

        return Disaster.objects(**query_params)