当前位置: 首页>>代码示例>>Python>>正文


Python CommCareCase.wrap方法代码示例

本文整理汇总了Python中casexml.apps.case.models.CommCareCase.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase.wrap方法的具体用法?Python CommCareCase.wrap怎么用?Python CommCareCase.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在casexml.apps.case.models.CommCareCase的用法示例。


在下文中一共展示了CommCareCase.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_all_rows

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
    def get_all_rows(self):
        """
        Rows to appear in the "Subjects" sheet of export_table().

        CdiscOdmExportWriter will render this using the odm_export.xml template to combine subjects into a single
        ODM XML document.

        The values are also used to register new subjects if the web service is enabled.
        """
        audit_log_id_ref = {'id': 0}  # To exclude audit logs, set `custom.openclinica.const.AUDIT_LOGS = False`
        query = self._build_query().case_type(CC_SUBJECT_CASE_TYPE).start(0).size(SIZE_LIMIT)
        rows = []
        for result in query.scroll():
            case = CommCareCase.wrap(result)
            if not self.is_subject_selected(case):
                continue
            subject = Subject.wrap(case, audit_log_id_ref)
            row = [
                'SS_' + subject.subject_key,  # OpenClinica prefixes subject key with "SS_" to make the OID
                subject.study_subject_id,
                subject.enrollment_date,
                subject.sex,
                subject.dob,
                subject.get_export_data(),
            ]
            rows.append(row)
        return rows
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:29,代码来源:reports.py

示例2: cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
    def cases(self):
        if "debug_case" in self.request.GET:
            case = CommCareCase.get(self.request.GET["debug_case"])
            if case.domain != DOMAIN:
                raise Http404()
            return [case]

        query = (
            case_es.CaseES()
            .domain(self.domain)
            .exclude_source()
            .opened_range(lte=self.datespan.enddate_utc)
            .case_type(self.default_case_type)
        )
        query.index = "report_cases"

        if self.case_status == "open":
            query = query.filter(
                es_filters.OR(case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc))
            )
        elif self.case_status == "closed":
            query = query.filter(case_es.closed_range(lte=self.datespan.enddate_utc))

        query = query.owner([user["doc_id"] for user in self.users_matching_filter])

        result = query.run()

        return [CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), result.doc_ids)]
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: dynamic_case_properties

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
 def dynamic_case_properties(self):
     from casexml.apps.case.models import CommCareCase
     if self.case_json is not None:
         dynamic_props = self.case_json
     else:
         dynamic_props = CommCareCase.wrap(self._data).dynamic_case_properties()
     return dynamic_props
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:models.py

示例4: get_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
 def get_cases(case_ids, ordered=False):
     return [
         CommCareCase.wrap(doc) for doc in iter_docs(
             CommCareCase.get_db(),
             case_ids
         )
     ]
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:9,代码来源:dbaccessors.py

示例5: handle

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
    def handle(self, *args, **options):
        if len(args) < 2:
            raise CommandError('Usage is copy_case, %s' % self.args)

        sourcedb = Database(args[0])
        case_id = args[1]
        domain = args[2] if len(args) > 2 else None

        print 'getting case'
        case = CommCareCase.wrap(sourcedb.get(case_id))
        if domain is not None:
            case.domain = domain
        case.save(force_update=True)

        print 'copying %s xforms' % len(case.xform_ids)

        def form_wrapper(row):
            doc = row['doc']
            doc.pop('_attachments', None)
            return XFormInstance.wrap(doc)

        xforms = sourcedb.all_docs(
            keys=case.xform_ids,
            include_docs=True,
            wrapper=form_wrapper,
        ).all()
        for form in xforms:
            if domain is not None:
                form.domain = domain
            form.save(force_update=True)
            print 'saved %s' % form._id
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:33,代码来源:copy_case.py

示例6: get_indexed_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
def get_indexed_cases(domain, case_ids):
    """
    Given a base list of cases, gets all wrapped cases that they reference
    (parent cases).
    """
    from casexml.apps.case.models import CommCareCase
    return [CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(),
                                                        get_indexed_case_ids(domain, case_ids))]
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:10,代码来源:util.py

示例7: iter_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
def iter_cases(case_ids, strip_history=False, wrap=True):
    from casexml.apps.case.models import CommCareCase
    if not strip_history:
        for doc in iter_docs(CommCareCase.get_db(), case_ids):
            yield CommCareCase.wrap(doc) if wrap else doc
    else:
        for case in CommCareCase.bulk_get_lite(case_ids, wrap=wrap):
            yield case
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:10,代码来源:util.py

示例8: get_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
 def get_cases(case_ids, ordered=False, prefetched_indices=None):
     # prefetched_indices is ignored sinces cases already have them
     return [
         CommCareCase.wrap(doc) for doc in iter_docs(
             CommCareCase.get_db(),
             case_ids
         )
     ]
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:10,代码来源:dbaccessors.py

示例9: _migrate_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
 def _migrate_case(case_id):
     print 'getting case %s' % case_id
     case = CommCareCase.wrap(source_couch.get_db_for_class(CommCareCase).get(case_id))
     original_domain = case.domain
     if domain is not None:
         case.domain = domain
     case.save(force_update=True)
     return case, original_domain
开发者ID:,项目名称:,代码行数:10,代码来源:

示例10: _actual_owned_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
    def _actual_owned_cases(self):
        def _case_domain_match(case):
            return not self.domain or self.domain == case.get('domain')

        return [
            CommCareCase.wrap(result['value']) for result in self._view_results()
            if _case_domain_match(result['value'])
        ]
开发者ID:bradmerlin,项目名称:commcare-hq,代码行数:10,代码来源:caselogic.py

示例11: deidentify_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
def deidentify_case(doc):
    assert(doc.doc["doc_type"] == "CommCareCase")
    case = CommCareCase.wrap(doc.doc)
    case.name = arbitrary_fullname()
    for action in case.actions:
        deidentify_case_action(action)
    doc.doc = case._doc
    return doc
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:transforms.py

示例12: _get_data_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
    def _get_data_case(self, params, filters):
        MAX_RESULTS = 200 # TODO vary by domain (cc-plus gets a higher limit?)
        # bleh
        _get = self.request.GET.copy()
        _get['iDisplayStart'] = '0'
        _get['iDisplayLength'] = str(MAX_RESULTS)
        self.request.GET = _get

        source = CaseListReport(self.request, domain=self.domain)

        total_count = source.es_results['hits']['total']
        if total_count > MAX_RESULTS:
            # can't really think of a better way to return out-of-band
            # metadata from a generator
            yield {'_meta': {
                    'total_rows': total_count,
                    'capped_rows': MAX_RESULTS,
                }}

        # TODO ideally we'd want access to all the data shown on the
        # case detail report. certain case types can override this via
        # case.to_full_dict(). however, there is currently no efficient
        # way to call this over a large block of cases. so now we (via the
        # CaseListReport/DataSource) limit ourselves only to that which
        # can be queried in bulk

        for data in source.get_data():
            case = CommCareCase.wrap(data['_case']).get_json()
            del data['_case']

            data['num_forms'] = len(case['xform_ids'])
            standard_props = (
                'case_name',
                'case_type',
                'date_opened',
                'external_id',
                'owner_id',
             )
            data.update(('prop_%s' % k, v) for k, v in case['properties'].iteritems() if k not in standard_props)

            GEO_DEFAULT = 'gps' # case property
            geo = None
            geo_directive = params['geo_fetch'].get(data['case_type'], GEO_DEFAULT)
            if geo_directive.startswith('link:'):
                # TODO use linked case
                pass
            elif geo_directive == '_random':
                # for testing -- just map the case to a random point
                import random
                import math
                geo = '%s %s' % (math.degrees(math.asin(random.uniform(-1, 1))), random.uniform(-180, 180))
            elif geo_directive:
                # case property
                geo = data.get('prop_%s' % geo_directive)

            if geo:
                data['geo'] = geo
                yield data
开发者ID:sheelio,项目名称:commcare-hq,代码行数:60,代码来源:maps.py

示例13: iter_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
 def iter_cases(self, ids):
     database = CommCareCase.get_db()
     if not self.strip_history:
         for doc in iter_docs(database, ids):
             yield CommCareCase.wrap(doc)
     else:
         for doc_ids in chunked(ids, 100):
             for case in CommCareCase.bulk_get_lite(doc_ids):
                 yield case
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:11,代码来源:api.py

示例14: _save_form_and_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
def _save_form_and_case(test):
    form = XFormInstance.wrap(_get_doc_data('bug_form.json'))
    form.save()
    test.addCleanup(form.delete)

    case = CommCareCase.wrap(_get_doc_data('bug_case.json'))
    case.save()
    test.addCleanup(case.delete)
    return form, case
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:11,代码来源:test_pillows.py

示例15: filter_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import wrap [as 别名]
def filter_cases(request, domain, app_id, module_id):
    app = Application.get(app_id)
    module = app.get_module(module_id)
    delegation = request.GET.get('task-list') == 'true'
    auth_cookie = request.COOKIES.get('sessionid')

    suite_gen = SuiteGenerator(app)
    xpath = suite_gen.get_filter_xpath(module, delegation=delegation)
    extra_instances = [{'id': inst.id, 'src': inst.src}
                       for inst in suite_gen.get_instances_for_module(module, additional_xpaths=[xpath])]

    # touchforms doesn't like this to be escaped
    xpath = HTMLParser.HTMLParser().unescape(xpath)
    if delegation:
        case_type = DELEGATION_STUB_CASE_TYPE
    else:
        case_type = module.case_type

    if xpath:
        # if we need to do a custom filter, send it to touchforms for processing
        additional_filters = {
            "properties/case_type": case_type,
            "footprint": True
        }

        helper = SessionDataHelper(domain, request.couch_user)
        result = helper.filter_cases(xpath, additional_filters, DjangoAuth(auth_cookie),
                                     extra_instances=extra_instances)
        if result.get('status', None) == 'error':
            return HttpResponseServerError(
                result.get("message", _("Something went wrong filtering your cases.")))

        case_ids = result.get("cases", [])
    else:
        # otherwise just use our built in api with the defaults
        case_ids = [res.id for res in get_filtered_cases(
            domain, status=CASE_STATUS_OPEN, case_type=case_type,
            user_id=request.couch_user._id, ids_only=True
        )]

    cases = [CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), case_ids)]
    # refilter these because we might have accidentally included footprint cases
    # in the results from touchforms. this is a little hacky but the easiest
    # (quick) workaround. should be revisted when we optimize the case list.
    cases = filter(lambda c: c.type == case_type, cases)
    cases = [c.get_json(lite=True) for c in cases if c]
    parents = []
    if delegation:
        for case in cases:
            parent_id = case['indices']['parent']['case_id']
            parents.append(CommCareCase.get(parent_id))
        return json_response({
            'cases': cases,
            'parents': parents
        })
    else:
        return json_response(cases)
开发者ID:thedevelopermw,项目名称:commcare-hq,代码行数:59,代码来源:views.py


注:本文中的casexml.apps.case.models.CommCareCase.wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。