예제 #1
0
 def _get_case_ids(self):
     case_rule_id = DuplicateCaseRuleFilter.get_value(
         self.request, self.domain)
     if not case_rule_id:
         raise BadRequestError(
             _("Please select a duplicate case rule to filter by above."))
     return CaseDuplicate.get_case_ids(case_rule_id)
 def __init__(self, *args, **kwargs):
     super(HistoricalAdherenceReport, self).__init__(*args, **kwargs)
     try:
         self.episode = CaseAccessors(self.domain).get_case(self.episode_case_id)
     except CaseNotFound:
         raise BadRequestError()
     self.episode_properties = self.episode.dynamic_case_properties()
     self.person = get_person_case_from_episode(self.domain, self.episode_case_id)
예제 #3
0
파일: basic.py 프로젝트: mekete/commcare-hq
 def es_results(self):
     try:
         return self._build_query().run().raw
     except ESError as e:
         original_exception = e.args[0]
         if isinstance(original_exception, TransportError):
             if hasattr(original_exception.info, "get"):
                 if original_exception.info.get('status') == 400:
                     raise BadRequestError()
         raise e
예제 #4
0
 def datespan(self):
     if self._datespan is None:
         datespan = self.default_datespan
         if self.request.datespan.is_valid() and not self.request.datespan.is_default:
             datespan.enddate = self.request.datespan.enddate
             datespan.startdate = self.request.datespan.startdate
             datespan.is_default = False
         elif self.request.datespan.get_validation_reason() == "You can't use dates earlier than the year 1900":
             raise BadRequestError()
         self.request.datespan = datespan
         # todo: don't update self.context here. find a better place! AGH! Sorry, sorry.
         self.context.update(dict(datespan=datespan))
         self._datespan = datespan
     return self._datespan
예제 #5
0
 def _build_query(self):
     query = super(CaseListExplorer, self)._build_query()
     query = self._populate_sort(query)
     xpath = XpathCaseSearchFilter.get_value(self.request, self.domain)
     if xpath:
         try:
             query = query.xpath_query(self.domain, xpath)
         except CaseFilterError as e:
             error = "<p>{}.</p>".format(escape(e))
             bad_part = "<p>{} <strong>{}</strong></p>".format(
                 _("The part of your search query we didn't understand is: "
                   ), escape(e.filter_part)) if e.filter_part else ""
             raise BadRequestError("{}{}".format(error, bad_part))
     return query
예제 #6
0
    def _build_query(self, sort=True):
        query = super(CaseListExplorer, self)._build_query()
        query = self._populate_sort(query, sort)
        xpath = XpathCaseSearchFilter.get_value(self.request, self.domain)
        if xpath:
            try:
                query = query.xpath_query(self.domain, xpath)
            except CaseFilterError as e:
                track_workflow(self.request.couch_user.username, "Case List Explorer: Query Error")

                error = "<p>{}.</p>".format(escape(e))
                bad_part = "<p>{} <strong>{}</strong></p>".format(
                    _("The part of your search query that caused this error is: "),
                    escape(e.filter_part)
                ) if e.filter_part else ""
                raise BadRequestError("{}{}".format(error, bad_part))

            if '/' in xpath:
                track_workflow(self.request.couch_user.username, "Case List Explorer: Related case search")

        return query
예제 #7
0
 def get_sql_sort(self):
     res = None
     #the NUMBER of cols sorting
     sort_cols = int(self.request.GET.get('iSortingCols', 0))
     if sort_cols > 0:
         for x in range(sort_cols):
             col_key = 'iSortCol_%d' % x
             sort_dir = self.request.GET['sSortDir_%d' % x]
             col_id = int(self.request.GET[col_key])
             col = self.headers.header[col_id]
             if col.sql_col is not None:
                 res = col.sql_col
                 if sort_dir not in ('desc', 'asc'):
                     raise BadRequestError(
                         ('unexcpected sort direction: {}. '
                          'sort direction must be asc or desc'.format(
                              sort_dir)))
                 if sort_dir == 'desc':
                     res = '-{}'.format(res)
                 break
     if res is None:
         res = '-last_form_submission_date'
     return res
예제 #8
0
 def es_results(self):
     try:
         return self._build_query().run().raw
     except ESError as e:
         if e.args[0].info.get('status') == 400:
             raise BadRequestError()
예제 #9
0
    def rows(self):
        rows = []

        if is_query_too_big(self.domain, self.request.GET.getlist(ExpandedMobileWorkerFilter.slug)):
            raise BadRequestError(
                _('Query selects too many users. Please modify your filters to select fewer users')
            )

        user_ids = map(lambda user: user.user_id, self.users)
        user_xform_dicts_map = get_last_form_submissions_by_user(self.domain, user_ids, self.selected_app_id)

        for user in self.users:
            xform_dict = last_seen = last_sync = app_name = None
            app_version_info_from_form = app_version_info_from_sync = None
            if user_xform_dicts_map.get(user.user_id):
                xform_dict = user_xform_dicts_map[user.user_id][0]

            if xform_dict:
                last_seen = string_to_utc_datetime(xform_dict.get('received_on'))

                if xform_dict.get('app_id'):
                    try:
                        app = get_app(self.domain, xform_dict.get('app_id'))
                    except ResourceNotFound:
                        pass
                    else:
                        app_name = app.name
                else:
                    app_name = get_meta_appversion_text(xform_dict['form']['meta'])

                app_version_info_from_form = get_app_version_info(
                    self.domain,
                    xform_dict.get('build_id'),
                    xform_dict.get('version'),
                    xform_dict['form']['meta'],
                )

            if app_name is None and self.selected_app_id:
                continue

            last_sync_log = SyncLog.last_for_user(user.user_id)
            if last_sync_log:
                last_sync = last_sync_log.date
                if last_sync_log.build_id:
                    build_version = get_version_from_build_id(self.domain, last_sync_log.build_id)
                    app_version_info_from_sync = AppVersionInfo(
                        build_version,
                        app_version_info_from_form.commcare_version if app_version_info_from_form else None,
                        BuildVersionSource.BUILD_ID
                    )

            app_version_info_to_use = _choose_latest_version(
                app_version_info_from_sync, app_version_info_from_form,
            )

            commcare_version = _get_commcare_version(app_version_info_to_use)
            build_version = _get_build_version(app_version_info_to_use)

            rows.append([
                user.username_in_report, _fmt_date(last_seen), _fmt_date(last_sync),
                app_name or "---", build_version, commcare_version
            ])
        return rows