本文整理汇总了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()
示例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()
示例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)