當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。