Example #1
0
    def selected(self):
        """
        Values returned by this method are displayed in select box
        It should return locations passed in GET parameters without their descendants
        :return: Selected locations without their descendants
        """
        location_ids = self.request.GET.getlist(self.slug)

        if len(location_ids) == 0 \
                and not self.request.couch_user.has_permission(self.request.domain, 'access_all_locations'):
            # Display the user's location in the filter if none is selected
            location_ids = self.request.couch_user.get_location_ids(
                self.request.domain)

        choice_provider = LocationChoiceProvider(
            StubReport(domain=self.domain), None)
        # We don't include descendants here because they will show up in select box
        choice_provider.configure({'include_descendants': False})
        choices = choice_provider.get_choices_for_known_values(
            location_ids, self.request.couch_user)
        if not choices:
            return self.default_options
        else:
            return [{
                'id': choice.value,
                'text': choice.display
            } for choice in choices]
Example #2
0
 def get_value(cls, request, domain):
     selected = super(EnikshayLocationFilter,
                      cls).get_value(request, domain)
     choice_provider = LocationChoiceProvider(StubReport(domain=domain),
                                              None)
     choice_provider.configure({'include_descendants': True})
     return [
         choice.value for choice in
         choice_provider.get_choices_for_known_values(selected)
     ]
Example #3
0
 def selected(self):
     selected = super(EnikshayLocationFilter, self).selected
     choice_provider = LocationChoiceProvider(
         StubReport(domain=self.domain), None)
     choice_provider.configure({'include_descendants': True})
     return [{
         'id': location.value,
         'text': location.display
     } for location in choice_provider.get_choices_for_known_values(
         selected)]
Example #4
0
 def get_value(cls, request, domain):
     selected = super(EnikshayLocationFilter, cls).get_value(request, domain)
     if len(filter(None, selected)) == 0 and not request.couch_user.has_permission(domain, 'access_all_locations'):
         # Force the user to select their assigned locations, otherwise selecting no locations will result in
         # all results being returned.
         selected = request.couch_user.get_location_ids(domain)
     choice_provider = LocationChoiceProvider(StubReport(domain=domain), None)
     choice_provider.configure({'include_descendants': True})
     selected_locations = [
         choice.value
         for choice in choice_provider.get_choices_for_known_values(selected, request.couch_user)
     ]
     return selected_locations
Example #5
0
    def get(self, request, domain, *args, **kwargs):
        user = self.request.couch_user

        query_context = ChoiceQueryContext(
            query=request.GET.get('q', None),
            limit=int(request.GET.get('limit', 20)),
            page=int(request.GET.get('page', 1)) - 1,
            user=user)
        location_choice_provider = LocationChoiceProvider(
            StubReport(domain=domain), None)
        location_choice_provider.configure({'include_descendants': True})
        return JsonResponse({
            'results': [{
                'id': location.value,
                'text': location.display
            } for location in location_choice_provider.query(query_context)],
            'total':
            location_choice_provider.query_count(query_context, user)
        })
Example #6
0
 def selected(self):
     """
     Values returned by this method are displayed in select box
     It should return locations passed in GET parameters without their descendants
     :return: Selected locations without their descendants
     """
     location_ids = self.request.GET.getlist(self.slug)
     choice_provider = LocationChoiceProvider(
         StubReport(domain=self.domain), None)
     # We don't include descendants here because they will show up in select box
     choice_provider.configure({'include_descendants': False})
     choices = choice_provider.get_choices_for_known_values(location_ids)
     if not choices:
         return self.default_options
     else:
         return [{
             'id': choice.value,
             'text': choice.display
         } for choice in choices]