Exemple #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]
Exemple #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)
     ]
Exemple #3
0
def _build_enikshay_location_hierarchy(spec, report):
    wrapped = FilterSpec.wrap(spec)
    choice_provider = LocationChoiceProvider(report, wrapped.slug)
    choice_provider.configure({})
    return EnikshayLocationHiearachyFilter(
        name=wrapped.slug,
        label=wrapped.get_display(),
        choice_provider=choice_provider,
        url_generator=dynamic_choice_list_url,
    )
Exemple #4
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)
     ]
Exemple #5
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)]
Exemple #6
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
Exemple #7
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
         ]
Exemple #8
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)
        })
Exemple #9
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]
Exemple #10
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)
            }
        )