Example #1
0
    def list(self):
        # if the user doesnt have permissions to list all clinics,
        # redirect to his own clinics
        if not self.request.has_permission(perms.CAN_VIEW_MUNICIPALITY,
                                           self.request.context):
            return HTTPFound(
                self.request.route_url('users',
                                       traverse=(self.request.user.id,
                                                 'clinics')))

        # otherwise, list all clinics
        # TODO: paginate
        # TODO: change renderer only if its an xhr request
        search_term = self.request.GET.get('search')

        if search_term is not None:
            clinics = Clinic.filter_clinics(search_term, True)
            self.request.override_renderer = '_summary_scores_table.jinja2'
        else:
            clinics = self.request.user.clinics

        state = None
        municipality = None

        if clinics:
            municipality = clinics[0].municipality
            state = municipality.parent

        return {
            'locations': clinics,
            'municipality': municipality,
            'national_report': self.national_report(self.period),
            'period': self.period,
            'periods': self.periods,
            'key_indicators_key_labels': self.key_indicators_key_labels,
            'state': state
        }
Example #2
0
    def test_filter_clinics(self):
        self.setup_test_data()

        clinics = Clinic.filter_clinics("Clinic B", True)
        self.assertGreater(len(clinics), 0)