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


Python CommCareImage.get方法代码示例

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


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

示例1: choose_media

# 需要导入模块: from corehq.apps.hqmedia.models import CommCareImage [as 别名]
# 或者: from corehq.apps.hqmedia.models.CommCareImage import get [as 别名]
def choose_media(request, domain, app_id):
    # TODO: Add error handling
    app = get_app(domain, app_id)
    media_type = request.POST['media_type']
    media_id = request.POST['id']
    if media_type == 'Image':
        file = CommCareImage.get(media_id)
    elif media_type == 'Audio':
        file = CommCareImage.get(media_id)
    else:
        raise Http404()

    if file is None or not file.is_shared:
        return HttpResponse(json.dumps({
            'match_found': False
        }))

    file.add_domain(domain)
    app.create_mapping(file, request.POST['path'])
    if media_type == 'Image':
        return HttpResponse(json.dumps({
            'match_found': True,
            'image': {'m_id': file._id, 'url': file.url()},
            'file': True
        }))
    elif media_type == 'Audio':
        return HttpResponse(json.dumps({'match_found': True, 'audio': {'m_id': file._id, 'url': file.url()}}))
    else:
        raise Http404()
开发者ID:ekush,项目名称:commcare-hq,代码行数:31,代码来源:views.py

示例2: choose_media

# 需要导入模块: from corehq.apps.hqmedia.models import CommCareImage [as 别名]
# 或者: from corehq.apps.hqmedia.models.CommCareImage import get [as 别名]
def choose_media(request, domain, app_id):
    # TODO: Add error handling
    app = get_app(domain, app_id)
    media_type = request.POST["media_type"]
    media_id = request.POST["id"]
    if media_type == "Image":
        file = CommCareImage.get(media_id)
    elif media_type == "Audio":
        file = CommCareImage.get(media_id)
    else:
        raise Http404()

    if file is None or not file.is_shared:
        return HttpResponse(json.dumps({"match_found": False}))

    file.add_domain(domain)
    app.create_mapping(file, request.POST["path"])
    if media_type == "Image":
        return HttpResponse(
            json.dumps({"match_found": True, "image": {"m_id": file._id, "url": file.url()}, "file": True})
        )
    elif media_type == "Audio":
        return HttpResponse(json.dumps({"match_found": True, "audio": {"m_id": file._id, "url": file.url()}}))
    else:
        raise Http404()
开发者ID:kkaczmarczyk,项目名称:commcare-hq,代码行数:27,代码来源:views.py

示例3: test_add_domain_to_media

# 需要导入模块: from corehq.apps.hqmedia.models import CommCareImage [as 别名]
# 或者: from corehq.apps.hqmedia.models.CommCareImage import get [as 别名]
    def test_add_domain_to_media(self):
        self.image.valid_domains.remove(self.master_app_with_report_modules.domain)
        self.image.save()

        image = CommCareImage.get(self.image._id)
        self.assertNotIn(self.master_app_with_report_modules.domain, image.valid_domains)

        image_path = 'jr://file/commcare/case_list_image.jpg'
        self.master_app_with_report_modules.get_module(0).set_icon('en', image_path)
        self.master_app_with_report_modules.create_mapping(self.image, image_path, save=False)

        missing_media = _get_missing_multimedia(self.master_app_with_report_modules)
        self.assertEqual(missing_media, [])

        image = CommCareImage.get(self.image._id)
        self.assertIn(self.master_app_with_report_modules.domain, image.valid_domains)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:18,代码来源:test_linked_apps.py


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