当前位置: 首页>>代码示例>>Python>>正文


Python models.ExportSchema类代码示例

本文整理汇总了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))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:8,代码来源:test_schema.py

示例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
开发者ID:nnestle,项目名称:commcare-hq,代码行数:8,代码来源:export.py

示例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))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:8,代码来源:test_schema.py

示例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
开发者ID:puttarajubr,项目名称:commcare-hq,代码行数:8,代码来源:views.py

示例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
开发者ID:dimagi,项目名称:couchexport,代码行数:11,代码来源:update_schema_checkpoints.py

示例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)
开发者ID:wbnigeria,项目名称:couchexport,代码行数:13,代码来源:tests.py

示例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)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:13,代码来源:tasks.py

示例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
开发者ID:kennknowles,项目名称:couchexport,代码行数:25,代码来源:schema.py

示例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)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:13,代码来源:test_schema.py

示例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
开发者ID:wbnigeria,项目名称:couchexport,代码行数:17,代码来源:schema.py

示例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)
开发者ID:dimagi,项目名称:couchexport,代码行数:11,代码来源:force_update_schemas.py

示例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
开发者ID:wbnigeria,项目名称:couchexport,代码行数:40,代码来源:export.py

示例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
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:14,代码来源:schema.py

示例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
开发者ID:nnestle,项目名称:commcare-hq,代码行数:49,代码来源:custom_export_helpers.py

示例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
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:16,代码来源:test_export_api.py


注:本文中的couchexport.models.ExportSchema类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。