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


Python SimplifiedSyncLog.wrap方法代码示例

本文整理汇总了Python中casexml.apps.phone.models.SimplifiedSyncLog.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python SimplifiedSyncLog.wrap方法的具体用法?Python SimplifiedSyncLog.wrap怎么用?Python SimplifiedSyncLog.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在casexml.apps.phone.models.SimplifiedSyncLog的用法示例。


在下文中一共展示了SimplifiedSyncLog.wrap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from casexml.apps.phone.models import SimplifiedSyncLog [as 别名]
# 或者: from casexml.apps.phone.models.SimplifiedSyncLog import wrap [as 别名]
    def handle(self, *args, **options):
        if len(args) != 2:
            raise CommandError("Usage is ./manage.py invalidate_sync_heads %s" % self.args)
        user_id = args[0]
        date = args[1]
        results = synclog_view(
            "phone/sync_logs_by_user",
            startkey=[user_id, {}],
            endkey=[user_id, date],
            descending=True,
            reduce=False,
            include_docs=True,
        )

        logs = []
        for res in results:
            log = SimplifiedSyncLog.wrap(res['doc'])
            log.case_ids_on_phone = {'broken to force 412'}
            logs.append(log)
        SimplifiedSyncLog.bulk_save(logs)
开发者ID:,项目名称:,代码行数:22,代码来源:

示例2: get_payload

# 需要导入模块: from casexml.apps.phone.models import SimplifiedSyncLog [as 别名]
# 或者: from casexml.apps.phone.models.SimplifiedSyncLog import wrap [as 别名]
    def get_payload(self):
        response = self.restore_state.restore_class()
        case_ids_to_sync = set()
        for owner_id in self.restore_state.owner_ids:
            case_ids_to_sync = case_ids_to_sync | set(self.get_case_ids_for_owner(owner_id))

        if (not self.restore_state.is_initial and
                any([not self.is_clean(owner_id) for owner_id in self.restore_state.owner_ids])):
            # if it's a steady state sync and we have any dirty owners, then we also need to
            # include ALL cases on the phone that have been modified since the last sync as
            # possible candidates to sync (since they may have been closed or reassigned by someone else)

            # don't bother checking ones we've already decided to check
            other_ids_to_check = self.restore_state.last_sync_log.case_ids_on_phone - case_ids_to_sync
            case_ids_to_sync = case_ids_to_sync | set(filter_cases_modified_since(
                self.restore_state.domain, list(other_ids_to_check), self.restore_state.last_sync_log.date
            ))

        all_maybe_syncing = copy(case_ids_to_sync)
        all_synced = set()
        all_indices = defaultdict(set)
        all_dependencies_syncing = set()
        while case_ids_to_sync:
            ids = pop_ids(case_ids_to_sync, chunk_size)
            # todo: see if we can avoid wrapping - serialization depends on it heavily for now
            case_batch = filter(
                partial(case_needs_to_sync, last_sync_log=self.restore_state.last_sync_log),
                [CommCareCase.wrap(doc) for doc in get_docs(CommCareCase.get_db(), ids)]
            )
            updates = get_case_sync_updates(
                self.restore_state.domain, case_batch, self.restore_state.last_sync_log
            )
            for update in updates:
                case = update.case
                all_synced.add(case._id)
                append_update_to_response(response, update, self.restore_state)

                # update the indices in the new sync log
                if case.indices:
                    all_indices[case._id] = {index.identifier: index.referenced_id for index in case.indices}
                    # and double check footprint for non-live cases
                    for index in case.indices:
                        if index.referenced_id not in all_maybe_syncing:
                            case_ids_to_sync.add(index.referenced_id)

                if not _is_live(case, self.restore_state):
                    all_dependencies_syncing.add(case._id)

            # commtrack ledger sections for this batch
            commtrack_elements = get_stock_payload(
                self.restore_state.project, self.restore_state.stock_settings,
                [CaseStub(update.case._id, update.case.type) for update in updates]
            )
            response.extend(commtrack_elements)

            # add any new values to all_syncing
            all_maybe_syncing = all_maybe_syncing | case_ids_to_sync

        # update sync token - marking it as the new format
        self.restore_state.current_sync_log = SimplifiedSyncLog.wrap(
            self.restore_state.current_sync_log.to_json()
        )
        self.restore_state.current_sync_log.log_format = LOG_FORMAT_SIMPLIFIED
        index_tree = IndexTree(indices=all_indices)
        case_ids_on_phone = all_synced
        primary_cases_syncing = all_synced - all_dependencies_syncing
        if not self.restore_state.is_initial:
            case_ids_on_phone = case_ids_on_phone | self.restore_state.last_sync_log.case_ids_on_phone
            # subtract primary cases from dependencies since they must be newly primary
            all_dependencies_syncing = all_dependencies_syncing | (
                self.restore_state.last_sync_log.dependent_case_ids_on_phone -
                primary_cases_syncing
            )
            index_tree = self.restore_state.last_sync_log.index_tree.apply_updates(index_tree)

        self.restore_state.current_sync_log.case_ids_on_phone = case_ids_on_phone
        self.restore_state.current_sync_log.dependent_case_ids_on_phone = all_dependencies_syncing
        self.restore_state.current_sync_log.index_tree = index_tree

        return response
开发者ID:ekush,项目名称:commcare-hq,代码行数:82,代码来源:clean_owners.py

示例3: mark_as_new_format

# 需要导入模块: from casexml.apps.phone.models import SimplifiedSyncLog [as 别名]
# 或者: from casexml.apps.phone.models.SimplifiedSyncLog import wrap [as 别名]
 def mark_as_new_format(self):
     self.current_sync_log = SimplifiedSyncLog.wrap(
         self.current_sync_log.to_json()
     )
     self.current_sync_log.log_format = LOG_FORMAT_SIMPLIFIED
     self.current_sync_log.extensions_checked = True
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:8,代码来源:restore.py


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