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


Python CommCareCase.view方法代码示例

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


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

示例1: testOTARestore

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def testOTARestore(self):
     self.assertEqual(0, len(CommCareCase.view("case/by_user", reduce=False).all()))
     file_path = os.path.join(os.path.dirname(__file__), "data", "multicase", "parallel_cases.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     form = post_xform_to_couch(xml_data)
     process_cases(sender="testharness", xform=form)
     self.assertEqual(4, len(CommCareCase.view("case/by_user", reduce=False).all()))
开发者ID:kennknowles,项目名称:casexml,代码行数:10,代码来源:test_ota_restore.py

示例2: testTopLevelExclusion

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def testTopLevelExclusion(self):
     """
     Entire forms tagged as device logs should be excluded
     """
     self.assertEqual(0, len(CommCareCase.view("case/by_user", include_docs=True, reduce=False).all()))
     file_path = os.path.join(os.path.dirname(__file__), "data", "exclusion", "device_report.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     form = post_xform_to_couch(xml_data)
     process_cases(form)
     self.assertEqual(0, len(CommCareCase.view("case/by_user", include_docs=True, reduce=False).all()))
开发者ID:bradmerlin,项目名称:commcare-hq,代码行数:13,代码来源:test_exclusion.py

示例3: testLotsOfSubcases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def testLotsOfSubcases(self):
     """
     How do we do when submitting a form with multiple blocks for the same case?
     """
     self.assertEqual(0, len(CommCareCase.view("case/by_user", reduce=False).all()))
     file_path = os.path.join(os.path.dirname(__file__), "data", "bugs", "lots_of_subcases.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     form = post_xform_to_couch(xml_data)
     # before the bug was fixed this call failed
     process_cases(form)
     self.assertEqual(11, len(CommCareCase.view("case/by_user", reduce=False).all()))
开发者ID:aristide,项目名称:commcare-hq,代码行数:14,代码来源:test_bugs.py

示例4: testNestedExclusion

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def testNestedExclusion(self):
     """
     Blocks inside forms tagged as device logs should be excluded
     """
     self.assertEqual(0, len(CommCareCase.view("case/by_user", include_docs=True, reduce=False).all()))
     file_path = os.path.join(os.path.dirname(__file__), "data", "exclusion", "nested_device_report.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     form = post_xform_to_couch(xml_data)
     process_cases(form)
     self.assertEqual(1, len(CommCareCase.view("case/by_user", include_docs=True, reduce=False).all()))
     case = CommCareCase.get("case_in_form")
     self.assertEqual("form case", case.name)
开发者ID:bradmerlin,项目名称:commcare-hq,代码行数:15,代码来源:test_exclusion.py

示例5: _get_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def _get_cases(self):
     case_ids = get_case_ids_in_domain(self.domain)
     return CommCareCase.view(
         '_all_docs',
         keys=case_ids,
         include_docs=True,
     )
开发者ID:puttarajubr,项目名称:commcare-hq,代码行数:9,代码来源:test_multi_case_submits.py

示例6: product_subcases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def product_subcases(supply_point):
    """given a supply point, return all the sub-cases for each product stocked at that supply point
    actually returns a mapping: product doc id => sub-case id
    ACTUALLY returns a dict that will create non-existent product sub-cases on demand
    """
    product_subcase_uuids = [ix.referenced_id for ix in supply_point.reverse_indices if ix.identifier == const.PARENT_CASE_REF]
    product_subcases = CommCareCase.view('_all_docs', keys=product_subcase_uuids, include_docs=True)
    product_subcase_mapping = dict((subcase.dynamic_properties().get('product'), subcase._id) for subcase in product_subcases)

    def create_product_subcase(product_uuid):
        return make_supply_point_product(supply_point, product_uuid)._id

    class DefaultDict(dict):
        """similar to collections.defaultdict(), but factory function has access
        to 'key'
        """
        def __init__(self, factory, *args, **kwargs):
            super(DefaultDict, self).__init__(*args, **kwargs)
            self.factory = factory

        def __getitem__(self, key):
            if key in self:
                val = self.get(key)
            else:
                val = self.factory(key)
                self[key] = val
            return val

    return DefaultDict(create_product_subcase, product_subcase_mapping)
开发者ID:nikhilvarma22,项目名称:commcare-hq,代码行数:31,代码来源:sms.py

示例7: testAttachInCreate

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
 def testAttachInCreate(self):
     self.assertEqual(0, len(CommCareCase.view("case/by_user", reduce=False).all()))
     
     file_path = os.path.join(os.path.dirname(__file__), "data", "attachments", "create_with_attach.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     
     attach_name = "fruity.jpg"
     attachment_path = os.path.join(os.path.dirname(__file__), "data", "attachments", attach_name)
     with open(attachment_path, "rb") as attachment:
         uf = UploadedFile(attachment, attach_name)
         form = post_xform_to_couch(xml_data, {attach_name: uf})
         self.assertEqual(1, len(form.attachments))
         fileback = form.fetch_attachment(attach_name)
         # rewind the pointer before comparing
         attachment.seek(0) 
         self.assertEqual(hashlib.md5(fileback).hexdigest(), 
                          hashlib.md5(attachment.read()).hexdigest())
         
     
     process_cases(sender="testharness", xform=form)
     case = CommCareCase.get(form.xpath("form/case/case_id"))
     self.assertEqual(1, len(case.attachments))
     self.assertEqual(form.get_id, case.attachments[0][0])
     self.assertEqual(attach_name, case.attachments[0][1])
开发者ID:kennknowles,项目名称:casexml,代码行数:27,代码来源:test_attachments.py

示例8: explode_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def explode_cases(request, domain, template="hqcase/explode_cases.html"):
    if request.method == 'POST':
        user_id = request.POST['user_id']
        user = CommCareUser.get_by_user_id(user_id, domain)
        factor = request.POST.get('factor', '2')
        try:
            factor = int(factor)
        except ValueError:
            messages.error(request, 'factor must be an int; was: %s' % factor)
        else:
            keys = [[domain, owner_id, False] for owner_id in user.get_owner_ids()]
            for case in CommCareCase.view('hqcase/by_owner',
                keys=keys,
                include_docs=True,
                reduce=False
            ):
                # we'll be screwing with this guy, so make him unsaveable
                case.save = None
                for i in range(factor - 1):

                    case._id = uuid.uuid4().hex
                    case_block = get_case_xml(case, (const.CASE_ACTION_CREATE, const.CASE_ACTION_UPDATE), version='2.0')
                    submit_case_blocks(case_block, domain)
            messages.success(request, "All of %s's cases were exploded by a factor of %d" % (user.raw_username, factor))

    return render(request, template, {
        'domain': domain,
        'users': CommCareUser.by_domain(domain),
    })
开发者ID:birdsarah,项目名称:core-hq,代码行数:31,代码来源:views.py

示例9: handle

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
    def handle(self, *args, **options):
        domain, group_name = args
        group = Group.by_name(domain, name=group_name)
        owner_ids = get_all_owner_ids_from_group(group)
        pillow = CareBiharFluffPillow()
        db = CommCareCase.get_db()

        greenlets = []

        def process_case(case):
            pillow.change_transport(pillow.change_transform(case))


        for i, owner_id in enumerate(owner_ids):
            print '{0}/{1} owner_ids'.format(i, len(owner_ids))
            rows = CommCareCase.view(
                'hqcase/by_owner',
                startkey=[domain, owner_id],
                endkey=[domain, owner_id, {}],
                reduce=False,
            ).all()
            case_ids = [row['id'] for row in rows]
            print '{0} case_ids'.format(len(case_ids))
            for case in iter_docs(db, case_ids):
                g = gevent.Greenlet.spawn(process_case, case)
                greenlets.append(g)
        gevent.joinall(greenlets)
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:29,代码来源:bihar_run_calcs.py

示例10: get_case_ids_in_domain_by_owner

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def get_case_ids_in_domain_by_owner(domain, owner_id=None, owner_id__in=None,
                                    closed=None):
    """
    get case_ids for open, closed, or all cases in a domain
    that belong to an owner_id or list of owner_ids

    domain: required
    owner_id: a single owner_id to filter on
    owner_id__in: a list of owner ids to filter on.
        A case matches if it belongs to any of them.
        You cannot specify both this and owner_id
    closed: True (only closed cases), False (only open cases), or None (all)
    returns a list of case_ids

    """
    assert not (owner_id__in and owner_id)
    assert closed in (True, False, None)
    if closed is None:
        closed_flags = [True, False]
    else:
        closed_flags = [closed]
    if owner_id:
        owner_id__in = [owner_id]
    return [res["id"] for res in CommCareCase.view(
        'cases_by_owner/view',
        keys=[[domain, owner_id, closed_flag]
              for owner_id in owner_id__in
              for closed_flag in closed_flags],
        include_docs=False,
        reduce=False,
    )]
开发者ID:,项目名称:,代码行数:33,代码来源:

示例11: download_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def download_cases(request, domain):
    include_closed = json.loads(request.GET.get('include_closed', 'false'))
    format = Format.from_format(request.GET.get('format') or Format.XLS_2007)

    view_name = 'hqcase/all_cases' if include_closed else 'hqcase/open_cases'

    key = [domain, {}, {}]
    cases = CommCareCase.view(view_name, startkey=key, endkey=key + [{}], reduce=False, include_docs=True)
#    group, users = util.get_group_params(domain, **json_request(request.GET))
    group = request.GET.get('group', None)
    user_filter, _ = FilterUsersField.get_user_filter(request)
    # todo deal with cached user dict here
    users = get_all_users_by_domain(domain, group=group, user_filter=user_filter)
    groups = Group.get_case_sharing_groups(domain)
    
#    if not group:
#        users.extend(CommCareUser.by_domain(domain, is_active=False))

    workbook = WorkBook()
    export_cases_and_referrals(cases, workbook, users=users, groups=groups)
    export_users(users, workbook)
    response = HttpResponse(workbook.format(format.slug))
    response['Content-Type'] = "%s" % format.mimetype
    response['Content-Disposition'] = "attachment; filename={domain}_data.{ext}".format(domain=domain, ext=format.extension)
    return response
开发者ID:mchampanis,项目名称:core-hq,代码行数:27,代码来源:views.py

示例12: delete_all_data

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def delete_all_data(request, domain, template="cleanup/delete_all_data.html"):
    if request.method == 'GET':
        return render(request, template, {
            'domain': domain
        })
    key = make_form_couch_key(domain)
    xforms = XFormInstance.view('reports_forms/all_forms',
        startkey=key,
        endkey=key+[{}],
        include_docs=True,
        reduce=False
    )
    cases = CommCareCase.view('case/by_date_modified',
        startkey=[domain, {}, {}],
        endkey=[domain, {}, {}, {}],
        include_docs=True,
        reduce=False
    )
    suffix = DELETED_SUFFIX
    deletion_id = random_hex()
    for thing_list in (xforms, cases):
        for thing in thing_list:
            thing.doc_type += suffix
            thing['-deletion_id'] = deletion_id
            thing.save()
    return HttpResponseRedirect(reverse('homepage'))
开发者ID:birdsarah,项目名称:core-hq,代码行数:28,代码来源:views.py

示例13: form_data

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def form_data(request, domain, instance_id):
    timezone = util.get_timezone(request.couch_user.user_id, domain)
    try:
        instance = XFormInstance.get(instance_id)
    except Exception:
        raise Http404()
    try:
        assert(domain == instance.domain)
    except AssertionError:
        raise Http404()
    cases = CommCareCase.view("case/by_xform_id", key=instance_id, reduce=False, include_docs=True).all()
    try:
        form_name = instance.get_form["@name"]
    except KeyError:
        form_name = "Untitled Form"
    is_archived = instance.doc_type == "XFormArchived"
    if is_archived:
        messages.info(request, _("This form is archived. To restore it, click 'Restore this form' at the bottom of the page."))
    return render(request, "reports/reportdata/form_data.html",
                              dict(domain=domain,
                                   instance=instance,
                                   cases=cases,
                                   timezone=timezone,
                                   slug=inspect.SubmitHistory.slug,
                                   is_archived=is_archived,
                                   form_data=dict(name=form_name,
                                                  modified=instance.received_on)))
开发者ID:,项目名称:,代码行数:29,代码来源:

示例14: open_cases_json

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def open_cases_json(request, domain):
    delete_ids = json.loads(request.GET.get("delete_ids", "false"))

    cases = CommCareCase.view(
        "hqcase/open_cases", startkey=[domain], endkey=[domain, {}], reduce=False, include_docs=True
    )

    user_id_to_type_to_cases = defaultdict(lambda: defaultdict(list))
    for case in cases:
        case_json = deepcopy(case.to_json())
        user_id_to_type_to_cases[case.user_id][case.type].append(case_json)
        del case_json["domain"]

        if delete_ids:
            del case_json["_id"]
            del case_json["_rev"]
            del case_json["user_id"]
            #            del case_json['type']
            del case_json["doc_type"]
            case_json["actions"] = [action.action_type for action in case.actions]
            case_json["referrals"] = [referral.type for referral in case.referrals]

    usercases = [
        {
            "username": user_id_to_username(user_id),
            "cases": [{"type": type, "cases": cases} for (type, cases) in type_to_cases.items()],
        }
        for (user_id, type_to_cases) in user_id_to_type_to_cases.items()
    ]
    usercases.sort(key=lambda x: x["username"])
    return HttpResponse(json.dumps(usercases))
开发者ID:nikhilvarma22,项目名称:commcare-hq,代码行数:33,代码来源:views.py

示例15: _get_cases_by_domain_hq_user_id

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import view [as 别名]
def _get_cases_by_domain_hq_user_id(domain, user_id, case_type, include_docs):
    return CommCareCase.view(
        'case_by_domain_hq_user_id_type/view',
        key=[domain, user_id, case_type],
        reduce=False,
        include_docs=include_docs
    ).all()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:9,代码来源:utils.py


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