Ejemplo n.º 1
0
 def _bulk_get_forms_from_elasticsearch(form_ids):
     forms = mget_query('forms', form_ids)
     return list(
         filter(None, [
             FormsInDateExpressionSpec.
             _transform_time_end_and_filter_bad_data(f) for f in forms
         ]))
Ejemplo n.º 2
0
    def _get_filtered_forms_from_es(self, case_id, xform_ids, context):
        cache_key = (self.__class__.__name__, 'es_helper', case_id,
                     tuple(xform_ids))
        if context.get_cache_value(cache_key) is not None:
            return context.get_cache_value(cache_key)

        def _transform_time_end(xform):
            xform = xform.get('_source', {})
            if not xform.get('xmlns', None):
                return None
            try:
                time = xform['form']['meta']['timeEnd']
            except KeyError:
                return None

            xform['timeEnd'] = datetime.strptime(
                time, '%Y-%m-%dT%H:%M:%S.%fZ').date()
            return xform

        forms = mget_query('forms', xform_ids,
                           ['form.meta.timeEnd', 'xmlns', '_id'])
        forms = filter(None, map(_transform_time_end, forms))
        context.set_cache_value(cache_key, forms)
        return forms