本文整理匯總了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)