當前位置: 首頁>>代碼示例>>Python>>正文


Python SavedBasicExport.get方法代碼示例

本文整理匯總了Python中couchexport.models.SavedBasicExport.get方法的典型用法代碼示例。如果您正苦於以下問題:Python SavedBasicExport.get方法的具體用法?Python SavedBasicExport.get怎麽用?Python SavedBasicExport.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在couchexport.models.SavedBasicExport的用法示例。


在下文中一共展示了SavedBasicExport.get方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: download_saved_export

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
def download_saved_export(request, export_id):
    export = SavedBasicExport.get(export_id)
    attach = export._attachments[export.configuration.filename]
    response = HttpResponse(mimetype=attach["content_type"])
    response.write(export.fetch_attachment(export.configuration.filename))
    response['Content-Disposition'] = 'attachment; filename=%s' % export.configuration.filename
    return response
開發者ID:wbnigeria,項目名稱:couchexport,代碼行數:9,代碼來源:views.py

示例2: modify_doc_and_print_status

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
 def modify_doc_and_print_status(num, total):
     if not modified:
         # do concurrent modification
         doc = SavedBasicExport.get(saved._id)
         doc.set_payload(new_payload)
         doc.save()
         modified.append(True)
     print_status(num, total)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:10,代碼來源:test_migrate.py

示例3: download_saved_export

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
def download_saved_export(request, export_id):
    export = SavedBasicExport.get(export_id)
    attach = export._attachments[export.get_attachment_name()]
    response = HttpResponse(mimetype=attach["content_type"])
    response.write(export.get_payload())
    # ht: http://stackoverflow.com/questions/1207457/convert-unicode-to-string-in-python-containing-extra-symbols
    normalized_filename = unicodedata.normalize(
        'NFKD', unicode(export.configuration.filename),
    ).encode('ascii','ignore')
    response['Content-Disposition'] = 'attachment; filename=%s' % normalized_filename

    return response
開發者ID:kennknowles,項目名稱:couchexport,代碼行數:14,代碼來源:views.py

示例4: download_saved_export

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
def download_saved_export(request, export_id):
    export = SavedBasicExport.get(export_id)
    content_type = Format.from_format(export.configuration.format).mimetype
    payload = export.get_payload(stream=True)
    response = StreamingHttpResponse(FileWrapper(payload), content_type=content_type)
    if export.configuration.format != 'html':
        # ht: http://stackoverflow.com/questions/1207457/convert-unicode-to-string-in-python-containing-extra-symbols
        normalized_filename = unicodedata.normalize(
            'NFKD', unicode(export.configuration.filename),
        ).encode('ascii', 'ignore')
        response['Content-Disposition'] = 'attachment; filename="%s"' % normalized_filename
    return response
開發者ID:dimagi,項目名稱:couchexport,代碼行數:14,代碼來源:views.py

示例5: test_migrate_with_concurrent_modification

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
    def test_migrate_with_concurrent_modification(self):
        # setup data
        saved = SavedBasicExport(configuration=_mk_config())
        saved.save()
        name = saved.get_attachment_name()
        new_payload = 'something new'
        old_payload = 'something old'
        super(BlobMixin, saved).put_attachment(old_payload, name)
        super(BlobMixin, saved).put_attachment(old_payload, "other")
        saved.save()

        # verify: attachments are in couch
        self.assertEqual(len(saved._attachments), 2)
        self.assertEqual(len(saved.external_blobs), 0)

        modified = []
        print_status = mod.print_status

        # setup concurrent modification
        def modify_doc_and_print_status(num, total):
            if not modified:
                # do concurrent modification
                doc = SavedBasicExport.get(saved._id)
                doc.set_payload(new_payload)
                doc.save()
                modified.append(True)
            print_status(num, total)

        # hook print_status() call to simulate concurrent modification
        with replattr(mod, "print_status", modify_doc_and_print_status):
            # do migration
            migrated, skipped = mod.MIGRATIONS[self.slug].migrate()
            self.assertGreaterEqual(skipped, 1)

        # verify: migration state not set when docs are skipped
        with self.assertRaises(mod.BlobMigrationState.DoesNotExist):
            mod.BlobMigrationState.objects.get(slug=self.slug)

        # verify: attachments were not migrated
        exp = SavedBasicExport.get(saved._id)
        self.assertEqual(len(exp._attachments), 1, exp._attachments)
        self.assertEqual(len(exp.external_blobs), 1, exp.external_blobs)
        self.assertEqual(exp.get_payload(), new_payload)
        self.assertEqual(exp.fetch_attachment("other"), old_payload)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:46,代碼來源:test_migrate.py

示例6: test_migrate_saved_exports

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
    def test_migrate_saved_exports(self):
        # setup data
        saved = SavedBasicExport(configuration=_mk_config())
        saved.save()
        payload = 'something small and simple'
        name = saved.get_attachment_name()
        super(BlobMixin, saved).put_attachment(payload, name)
        saved.save()

        # verify: attachment is in couch and migration not complete
        self.assertEqual(len(saved._attachments), 1)
        self.assertEqual(len(saved.external_blobs), 0)

        with tempdir() as tmp, replattr(SavedBasicExport, "migrating_blobs_from_couch", True):
            filename = join(tmp, "file.txt")

            # do migration
            migrated, skipped = mod.MIGRATIONS[self.slug].migrate(filename)
            self.assertGreaterEqual(migrated, 1)

            # verify: migration state recorded
            mod.BlobMigrationState.objects.get(slug=self.slug)

            # verify: migrated data was written to the file
            with open(filename) as fh:
                lines = list(fh)
            doc = {d["_id"]: d for d in (json.loads(x) for x in lines)}[saved._id]
            self.assertEqual(doc["_rev"], saved._rev)
            self.assertEqual(len(lines), migrated, lines)

        # verify: attachment was moved to blob db
        exp = SavedBasicExport.get(saved._id)
        self.assertNotEqual(exp._rev, saved._rev)
        self.assertEqual(len(exp.blobs), 1, repr(exp.blobs))
        self.assertFalse(exp._attachments, exp._attachments)
        self.assertEqual(len(exp.external_blobs), 1)
        self.assertEqual(exp.get_payload(), payload)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:39,代碼來源:test_migrate.py

示例7: hq_download_saved_export

# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import get [as 別名]
def hq_download_saved_export(req, domain, export_id):
    export = SavedBasicExport.get(export_id)
    # quasi-security hack: the first key of the index is always assumed
    # to be the domain
    assert domain == export.configuration.index[0]
    return couchexport_views.download_saved_export(req, export_id)
開發者ID:SEL-Columbia,項目名稱:commcare-hq,代碼行數:8,代碼來源:views.py


注:本文中的couchexport.models.SavedBasicExport.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。