本文整理汇总了Python中couchexport.models.ExportSchema类的典型用法代码示例。如果您正苦于以下问题:Python ExportSchema类的具体用法?Python ExportSchema怎么用?Python ExportSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExportSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wrap_datetime_min
def test_wrap_datetime_min(self):
schema_bad = ExportSchema(
schema={},
timestamp=datetime.min,
index='index',
)
schema_good = ExportSchema.wrap(schema_bad.to_json())
self.assertEqual(schema_good.timestamp, datetime(1970, 1, 1))
示例2: create_new_checkpoint
def create_new_checkpoint(self):
checkpoint = ExportSchema(
schema=self.get_latest_schema(),
timestamp=self.timestamp,
index=self.schema_index,
)
checkpoint.save()
return checkpoint
示例3: test_wrap_datetime_hippy
def test_wrap_datetime_hippy(self):
schema1 = ExportSchema(
schema={},
timestamp=datetime(1970, 1, 2),
index='index',
)
schema2 = ExportSchema.wrap(schema1.to_json())
self.assertEqual(schema2.timestamp, datetime(1970, 1, 2))
示例4: create_basic_form_checkpoint
def create_basic_form_checkpoint(index):
checkpoint = ExportSchema(
schema=BASIC_FORM_SCHEMA,
timestamp=datetime(1970, 1, 1),
index=index,
)
checkpoint.save()
return checkpoint
示例5: handle
def handle(self, *args, **options):
db = ExportSchema.get_db()
for index in ExportSchema.get_all_indices():
last = ExportSchema.last(index)
if not last.timestamp:
config = ExportConfiguration(db, index, disable_checkpoints=True)
config.create_new_checkpoint()
assert ExportSchema.last(index).timestamp
print "set timestamp for %s" % index
else:
print "%s all set" % index
示例6: testSaveAndLoad
def testSaveAndLoad(self):
index = ["foo", 2]
schema = ExportSchema(seq=5, index=index)
inner = {"dict": {"bar": 1, "baz": [2,3]},
"list": ["foo", "bar"],
"dictlist": [{"bip": 1, "bop": "blah"},
{"bip": 2, "bop": "blah2"}],
"item": "yoyoyo"}
schema.schema = inner
schema.save()
back = ExportSchema.get(schema.get_id)
self.assertEqual(inner, back.schema)
self.assertEqual(index, back.index)
示例7: rebuild_schemas
def rebuild_schemas(index):
"""
Resets the schema for all checkpoints to the latest version based off the
current document structure. Returns the number of checkpoints updated.
"""
db = ExportSchema.get_db()
all_checkpoints = ExportSchema.get_all_checkpoints(index)
config = ExportConfiguration(db, index, disable_checkpoints=True)
latest = config.create_new_checkpoint()
for cp in all_checkpoints:
cp.schema = latest.schema
cp.save()
return len(all_checkpoints)
示例8: build_latest_schema
def build_latest_schema(schema_index):
"""
Build a schema, directly from the index. Also creates a saved checkpoint.
"""
from couchexport.export import ExportConfiguration
db = Database(settings.COUCH_DATABASE)
previous_export = ExportSchema.last(schema_index)
try:
current_seq = int(db.info()["update_seq"])
except ValueError:
pass # we must be on bigcouch, so comparing seqs is useless
else:
if previous_export and not previous_export.is_bigcouch \
and int(previous_export.seq) > current_seq:
# something weird happened (like the couch database changing)
# better rebuild from scratch
previous_export = None
config = ExportConfiguration(db, schema_index,
previous_export=previous_export)
schema = config.get_latest_schema()
if not schema:
return None
updated_checkpoint = config.create_new_checkpoint()
return updated_checkpoint
示例9: test_get_all_checkpoints
def test_get_all_checkpoints(self):
index = ["mydomain", "myxmlns"]
self.addCleanup(lambda: [cp.delete() for cp in ExportSchema.get_all_checkpoints(index)])
schema1 = ExportSchema(index=index, timestamp=datetime.utcnow())
schema1.save()
schema1_prime, = list(ExportSchema.get_all_checkpoints(index))
self.assert_docs_equal(schema1_prime, schema1)
schema2 = ExportSchema(index=index, timestamp=datetime.utcnow())
schema2.save()
schema1_prime, schema2_prime = list(ExportSchema.get_all_checkpoints(index))
self.assert_docs_equal(schema1_prime, schema1)
self.assert_docs_equal(schema2_prime, schema2)
示例10: build_latest_schema
def build_latest_schema(schema_index):
"""
Build a schema, directly from the index. Also creates a saved checkpoint.
"""
from couchexport.export import ExportConfiguration
db = Database(settings.COUCH_DATABASE)
current_seq = db.info()["update_seq"]
previous_export = ExportSchema.last(schema_index)
config = ExportConfiguration(get_db(), schema_index,
previous_export=previous_export)
schema = get_schema_new(config)
if not schema:
return None
updated_checkpoint = ExportSchema(seq=current_seq, schema=schema,
index=schema_index)
updated_checkpoint.save()
return updated_checkpoint
示例11: handle
def handle(self, *args, **options):
if len(args) < 1: raise CommandError('Please specify %s.' % self.label)
index_in = args[0]
if index_in == "all":
to_update = ExportSchema.get_all_indices()
else:
to_update = [json.loads(index_in)]
for index in to_update:
processed = rebuild_schemas(index)
print "processed %s checkpoints matching %s" % (processed, index)
示例12: export
def export(
schema_index,
file,
format=Format.XLS_2007,
previous_export_id=None,
filter=None,
max_column_size=2000,
separator="|",
):
"""
Exports data from couch documents matching a given tag to a file.
Returns true if it finds data, otherwise nothing
"""
previous_export = ExportSchema.get(previous_export_id) if previous_export_id else None
database = get_db()
config = ExportConfiguration(database, schema_index, previous_export, filter)
# handle empty case
if not config.potentially_relevant_ids:
return None
# get and checkpoint the latest schema
updated_schema = get_schema_new(config)
export_schema_checkpoint = ExportSchema(seq=config.current_seq, schema=updated_schema, index=config.schema_index)
export_schema_checkpoint.save()
# transform docs onto output and save
writer = get_writer(format)
# open the doc and the headers
formatted_headers = get_headers(updated_schema, separator=separator)
writer.open(formatted_headers, file)
for doc in config.get_docs():
writer.write(
format_tables(create_intermediate_tables(doc, updated_schema), include_headers=False, separator=separator)
)
writer.close()
return export_schema_checkpoint
示例13: build_latest_schema
def build_latest_schema(schema_index):
"""
Build a schema, directly from the index. Also creates a saved checkpoint.
"""
from couchexport.export import ExportConfiguration
db = Database(settings.COUCH_DATABASE)
previous_export = ExportSchema.last(schema_index)
config = ExportConfiguration(db, schema_index,
previous_export=previous_export)
schema = config.get_latest_schema()
if not schema:
return None
updated_checkpoint = config.create_new_checkpoint()
return updated_checkpoint
示例14: update_custom_export
def update_custom_export(self):
"""
Updates custom_export object from the request
and saves to the db
"""
post_data = self.post_data
custom_export_json = post_data['custom_export']
SAFE_KEYS = ('default_format', 'is_safe', 'name', 'schema_id', 'transform_dates')
for key in SAFE_KEYS:
self.custom_export[key] = custom_export_json[key]
# update the custom export index (to stay in sync)
schema_id = self.custom_export.schema_id
schema = ExportSchema.get(schema_id)
self.custom_export.index = schema.index
self.presave = post_data['presave']
self.export_stock = post_data['export_stock']
self.custom_export.tables = [
ExportTable.wrap(table)
for table in custom_export_json['tables']
]
table_dict = dict((t.index, t) for t in self.custom_export.tables)
for table in self.custom_export.tables:
if table.index in table_dict:
table_dict[table.index].columns = table.columns
else:
self.custom_export.tables.append(
ExportTable(
index=table.index,
display=self.custom_export.name,
columns=table.columns
)
)
self.update_custom_params()
self.custom_export.custom_validate()
self.custom_export.save()
touch_exports(self.domain)
if self.presave:
HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id)
else:
HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id)
return self.custom_export.get_id
示例15: testExportTokenMigration
def testExportTokenMigration(self):
c = Client()
c.login(**{'username': 'test', 'password': 'foobar'})
_submit_form()
time.sleep(1)
resp = get_export_response(c)
self.assertEqual(200, resp.status_code)
self.assertTrue(_content(resp) is not None)
self.assertTrue("X-CommCareHQ-Export-Token" in resp)
# blow away the timestamp property to ensure we're testing the
# migration case
prev_token = resp["X-CommCareHQ-Export-Token"]
prev_checkpoint = ExportSchema.get(prev_token)
assert prev_checkpoint.timestamp