Exemplo n.º 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]
Exemplo n.º 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)
     ]
Exemplo n.º 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,
    )
Exemplo n.º 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)
     ]
Exemplo n.º 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)]
Exemplo n.º 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
Exemplo n.º 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
         ]
Exemplo n.º 8
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]
Exemplo n.º 9
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)
            }
        )
Exemplo n.º 10
0
 def setUpClass(cls):
     delete_all_locations()
     delete_all_users()
     super(LocationChoiceProviderTest, cls).setUpClass()
     report = ReportConfiguration(domain=cls.domain)
     choices = [
         SearchableChoice(
             location.location_id,
             location.display_name,
             searchable_text=[location.site_code, location.name])
         for location in cls.locations.itervalues()
     ]
     choices.sort(key=lambda choice: choice.display)
     cls.web_user = WebUser.create(cls.domain, 'blah', 'password')
     cls.choice_provider = LocationChoiceProvider(report, None)
     cls.static_choice_provider = StaticChoiceProvider(choices)
     cls.choice_query_context = partial(ChoiceQueryContext,
                                        user=cls.web_user)
Exemplo n.º 11
0
 def setUpClass(cls):
     super(LocationChoiceProviderTest, cls).setUpClass()
     report = ReportConfiguration(domain=cls.domain)
     choice_tuples = [
         (location.name, SearchableChoice(
             location.location_id,
             location.display_name,
             searchable_text=[location.site_code, location.name]
         ))
         for location in six.itervalues(cls.locations)
     ]
     choice_tuples.sort()
     choices = [choice for name, choice in choice_tuples]
     cls.web_user = WebUser.create(cls.domain, 'blah', 'password')
     cls.choice_provider = LocationChoiceProvider(report, None)
     cls.choice_provider.configure({
         "include_descendants": False,
         "show_full_path": False,
     })
     cls.static_choice_provider = StaticChoiceProvider(choices)
     cls.choice_query_context = partial(ChoiceQueryContext, user=cls.web_user)
Exemplo n.º 12
0
    def setUpClass(cls):
        cls.domain_obj = create_domain(cls.domain)
        report = ReportConfiguration(domain=cls.domain)
        bootstrap_location_types(cls.domain)

        location_code_name_pairs = (
            ('cambridge_ma', 'Cambridge'),
            ('somerville_ma', 'Somerville'),
            ('boston_ma', 'Boston'),
        )
        cls.locations = []
        choices = []

        for location_code, location_name in location_code_name_pairs:
            location = cls.make_location(location_code, location_name)
            cls.locations.append(location)
            choices.append(SearchableChoice(location.location_id, location.sql_location.display_name,
                                            searchable_text=[location_code, location_name]))
        choices.sort(key=lambda choice: choice.display)
        cls.choice_provider = LocationChoiceProvider(report, None)
        cls.static_choice_provider = StaticChoiceProvider(choices)
Exemplo n.º 13
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)
        })