本文整理汇总了Python中couchexport.models.SavedExportSchema类的典型用法代码示例。如果您正苦于以下问题:Python SavedExportSchema类的具体用法?Python SavedExportSchema怎么用?Python SavedExportSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SavedExportSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_revert_new_exports_restore_old
def test_revert_new_exports_restore_old(self):
saved_export_schema = SavedExportSchema(index=['my-domain', 'xmlns'])
saved_export_schema.doc_type += DELETED_SUFFIX
saved_export_schema.save()
self.new_exports[0].legacy_saved_export_schema_id = saved_export_schema._id
reverted = revert_new_exports(self.new_exports)
self.assertEqual(len(reverted), 1)
self.assertFalse(reverted[0].doc_type.endswith(DELETED_SUFFIX))
saved_export_schema.delete()
示例2: export_data_shared
def export_data_shared(export_tag, format=None, filename=None,
previous_export_id=None, filter=None,
use_cache=True, max_column_size=2000,
separator='|'):
"""
Shared method for export. If there is data, return an HTTPResponse
with the appropriate data. If there is not data returns None.
"""
if previous_export_id and not SavedExportSchema.get_db().doc_exist(previous_export_id):
return HttpResponseNotFound(
_('No previous export with id "{id}" found'.format(id=previous_export_id)))
if not filename:
filename = export_tag
files = DefaultExportSchema(index=export_tag).get_export_files(
format=format,
previous_export_id=previous_export_id,
filter=filter,
use_cache=use_cache,
max_column_size=max_column_size,
separator=separator
)
if files and files.checkpoint:
return export_response(files.file, format, filename, files.checkpoint)
else:
return None
示例3: test_system_property_conversion
def test_system_property_conversion(self, _):
saved_export_schema = SavedExportSchema.wrap(self.get_json('system_properties'))
with mock.patch(
'corehq.apps.export.models.new.FormExportDataSchema.generate_schema_from_builds',
return_value=self.schema):
instance = convert_saved_export_to_export_instance(self.domain, saved_export_schema)
self.assertEqual(instance.name, 'System Properties')
# Check for first repeat table
table = instance.get_table(MAIN_TABLE)
self.assertEqual(table.label, 'Forms')
expected_paths = [
([PathNode(name='xmlns')], None, True),
([PathNode(name='form'), PathNode(name='meta'), PathNode(name='userID')], None, True),
([PathNode(name='form'), PathNode(name='case'), PathNode(name='@case_id')], None, True),
(
[PathNode(name='form'), PathNode(name='case'), PathNode(name='@case_id')],
CASE_NAME_TRANSFORM,
True
),
]
for path, transform, selected in expected_paths:
index, column = table.get_column(path, 'ExportItem', transform)
self.assertEqual(column.selected, selected, '{} selected is not {}'.format(path, selected))
示例4: test_repeat_conversion
def test_repeat_conversion(self, _):
saved_export_schema = SavedExportSchema.wrap(self.get_json('repeat'))
with mock.patch(
'corehq.apps.export.models.new.FormExportDataSchema.generate_schema_from_builds',
return_value=self.schema):
instance = convert_saved_export_to_export_instance(self.domain, saved_export_schema)
self.assertEqual(instance.name, 'Repeat Tester')
table = instance.get_table([PathNode(name='form'), PathNode(name='repeat', is_repeat=True)])
self.assertEqual(table.label, 'Repeat: question1')
self.assertTrue(table.selected)
index, column = table.get_column(
[PathNode(name='form'),
PathNode(name='repeat', is_repeat=True),
PathNode(name='question2')],
'ExportItem',
None
)
self.assertEqual(column.label, 'Question Two')
self.assertEqual(column.selected, True)
index, column = table.get_column(
[PathNode(name='number')],
'ExportItem',
None
)
self.assertEqual(column.selected, True)
示例5: test_basic_conversion
def test_basic_conversion(self, _):
saved_export_schema = SavedExportSchema.wrap(self.get_json('basic'))
with mock.patch(
'corehq.apps.export.models.new.FormExportDataSchema.generate_schema_from_builds',
return_value=self.schema):
instance = convert_saved_export_to_export_instance(self.domain, saved_export_schema)
self.assertEqual(instance.split_multiselects, False)
self.assertEqual(instance.transform_dates, True)
self.assertEqual(instance.name, 'Tester')
self.assertEqual(instance.export_format, 'csv')
self.assertEqual(instance.is_deidentified, False)
self.assertEqual(instance.include_errors, False)
table = instance.get_table(MAIN_TABLE)
self.assertEqual(table.label, 'My Forms')
index, column = table.get_column(
[PathNode(name='form'), PathNode(name='question1')],
'ExportItem',
None,
)
self.assertEqual(column.label, 'Question One')
self.assertEqual(column.selected, True)
示例6: commit
def commit(self, request):
try:
saved_export = SavedExportSchema.get(self.export_id)
except ResourceNotFound:
raise ExportNotFound()
self.export_type = saved_export.type
saved_export.delete()
messages.success(request, _("Custom export was deleted."))
示例7: get_saved_exports
def get_saved_exports(self):
startkey = json.dumps([self.domain, ""])[:-3]
endkey = "%s{" % startkey
exports = SavedExportSchema.view("couchexport/saved_export_schemas",
startkey=startkey, endkey=endkey,
include_docs=True).all()
exports = filter(lambda x: x.type == "case", exports)
return exports
示例8: show_in_navigation
def show_in_navigation(cls, domain=None, project=None, user=None):
startkey = json.dumps([domain, ""])[:-3]
return SavedExportSchema.view("couchexport/saved_export_schemas",
startkey=startkey,
limit=1,
include_docs=False,
stale=settings.COUCH_STALE_QUERY,
).count() > 0
示例9: commit
def commit(self, request):
try:
saved_export = SavedExportSchema.get(self.export_id)
except ResourceNotFound:
raise ExportNotFound()
self.export_type = saved_export.type
saved_export.delete()
touch_exports(self.domain)
messages.success(request, mark_safe(_("Export <strong>{}</strong> " "was deleted.").format(saved_export.name)))
示例10: post
def post(self, request, *args, **kwargs):
try:
saved_export = SavedExportSchema.get(self.export_id)
except ResourceNotFound:
return HttpResponseRedirect(request.META['HTTP_REFERER'])
self.export_type = saved_export.type
saved_export.delete()
messages.success(request, _("Custom export was deleted."))
return super(DeleteCustomExportView, self).post(request, *args, **kwargs)
示例11: show_in_navigation
def show_in_navigation(cls, request, *args, **kwargs):
domain = kwargs.get("domain")
startkey = json.dumps([domain, ""])[:-3]
return (
SavedExportSchema.view(
"couchexport/saved_export_schemas", startkey=startkey, limit=1, include_docs=False
).all()
> 0
)
示例12: test_stock_conversion
def test_stock_conversion(self, _):
saved_export_schema = SavedExportSchema.wrap(self.get_json('stock'))
with mock.patch(
'corehq.apps.export.models.new.CaseExportDataSchema.generate_schema_from_builds',
return_value=self.schema):
instance = convert_saved_export_to_export_instance(self.domain, saved_export_schema)
table = instance.get_table(MAIN_TABLE)
path = [PathNode(name='stock')]
index, column = table.get_column(path, 'ExportItem', None)
self.assertTrue(column.selected)
示例13: _convert_export
def _convert_export(self, mock_path, export_file_name, force=False):
saved_export_schema = SavedExportSchema.wrap(self.get_json(export_file_name))
with mock.patch.object(SavedExportSchema, "save", return_value="False Save"):
with mock.patch(mock_path, return_value=self.schema):
instance, meta = convert_saved_export_to_export_instance(
self.domain, saved_export_schema, force_convert_columns=force
)
return instance, meta
示例14: delete_custom_export
def delete_custom_export(req, domain, export_id):
"""
Delete a custom export
"""
try:
saved_export = SavedExportSchema.get(export_id)
except ResourceNotFound:
return HttpResponseRedirect(req.META['HTTP_REFERER'])
saved_export.delete()
messages.success(req, "Custom export was deleted.")
return _redirect_to_export_home(saved_export.type, domain)
示例15: handle
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Syntax: ./manage.py migrate_export_types [default type]!")
default_type = args[0]
for export in SavedExportSchema.view("couchexport/saved_export_schemas", include_docs=True):
if not export.type:
print "migrating %s" % export
export.type = default_type
if not options["dryrun"]:
export.save()
print "Done!"