def ensure_log_initialized(self, user_id): ann = unprotected_write(IAnnotations(self.portal)) if RECENTLY_TOUCHED_KEY not in ann: ann[RECENTLY_TOUCHED_KEY] = unprotected_write(OOBTree()) if user_id not in ann[RECENTLY_TOUCHED_KEY]: ann[RECENTLY_TOUCHED_KEY][user_id] = unprotected_write(PersistentList())
def ensure_log_initialized(self, user_id): ann = unprotected_write(IAnnotations(self.portal)) if RECENTLY_TOUCHED_KEY not in ann: ann[RECENTLY_TOUCHED_KEY] = unprotected_write(OOBTree()) if user_id not in ann[RECENTLY_TOUCHED_KEY]: ann[RECENTLY_TOUCHED_KEY][user_id] = unprotected_write( PersistentList())
def _retrieve_version(self, context, version_id): try: # CMFEditions causes writes to the parent when retrieving versions unprotected_write(aq_parent(context)) return Versioner(context).retrieve(version_id) except ArchivistRetrieveError: # Version does not exists. raise NotFound
def annotations(self): annotations = unprotected_write(IAnnotations(self.context)) if ANNOTATION_KEY not in annotations: annotations[ANNOTATION_KEY] = OOBTree() unprotected_write(annotations[ANNOTATION_KEY]) if self.username not in annotations[ANNOTATION_KEY]: annotations[ANNOTATION_KEY][self.username] = PersistentList() return unprotected_write(annotations[ANNOTATION_KEY][self.username])
def _retrieve_version(self, context, version_id): prtool = api.portal.get_tool("portal_repository") try: # CMFEditions causes writes to the parent when retrieving versions unprotected_write(aq_parent(context)) return prtool.retrieve(context, version_id).object except ArchivistRetrieveError: # Version does not exists. raise NotFound
def _retrieve_version(self, context, version_id): prtool = api.portal.get_tool('portal_repository') try: # CMFEditions causes writes to the parent when retrieving versions unprotected_write(aq_parent(context)) return prtool.retrieve(context, version_id).object except ArchivistRetrieveError: # Version does not exists. raise NotFound
def _increment_number(self, portal, key): ann = unprotected_write(IAnnotations(portal)) if SEQUENCE_NUMBER_ANNOTATION_KEY not in ann: ann[SEQUENCE_NUMBER_ANNOTATION_KEY] = unprotected_write( PersistentDict()) mapping = unprotected_write(ann.get(SEQUENCE_NUMBER_ANNOTATION_KEY)) if key not in mapping: mapping[key] = 0 mapping[key] += 1 return mapping[key]
def rotate(self, user_id): """Rotate recently touched log. We basically truncate it to the RECENTLY_TOUCHED_LIMIT. However, because the display limit only applies to recently touched items (not checked out docs), we need to take care to calculate the correct cutoff by "ignoring" checked out docs (adding them to the cutoff limit). """ num_checked_out = len(self.catalog(checked_out=user_id)) limit = get_registry_record('limit', IRecentlyTouchedSettings) cutoff = limit + num_checked_out truncated = unprotected_write(self.get_recently_touched_log(user_id)[:cutoff]) unprotected_write(IAnnotations(self.portal)[RECENTLY_TOUCHED_KEY])[user_id] = truncated
def get_number(self, obj): ann = unprotected_write(IAnnotations(obj)) if SEQUENCE_NUMBER_ANNOTATION_KEY not in ann.keys(): generator = getAdapter(obj, ISequenceNumberGenerator) value = generator.generate() ann[SEQUENCE_NUMBER_ANNOTATION_KEY] = value return ann.get(SEQUENCE_NUMBER_ANNOTATION_KEY)
def set_sync_stamp(self, stamp, context=None): """Update sync stamp with the given value. """ context = self.get_context(context) self.annotations = unprotected_write(IAnnotations(context)) self.annotations['sync_stamp'] = stamp logger.info("Stored sync_stamp %s in annotations" % stamp)
def set_sync_stamp(self, stamp, context=None): """update the stamp with the given value""" context = self.get_context(context) self.annotations = unprotected_write(IAnnotations(context)) self.annotations['sync_stamp'] = stamp logger.info("Stored sync_stamp %s in annotations" % stamp)
def get_reference_mapping(self, obj=None): type_key = self.get_type_key(obj) annotations = unprotected_write(IAnnotations(self.context)) if not type_key in annotations: annotations[type_key] = PersistentDict() return annotations[type_key]
def _get_history_for_writing(self): """Return the history for writing and make sure a default is also initialized if it is the first time the history is accessed. """ return unprotected_write( IAnnotations(self.context).setdefault(self.annotation_key, OOBTree()))
def __init__(self, context): self.context = context annotations = unprotected_write(IAnnotations(self.context)) self.__mapping = annotations.get(self.ANNO_KEY, None) if self.__mapping is None: self.__mapping = PersistentList() annotations[self.ANNO_KEY] = self.__mapping
def search_results(self, query): # `query` , as generated by `VersionsTab.get_base_query()`, is # actually the object we're displaying the version history for obj = query # CMFEditions causes writes to the parent when retrieving versions unprotected_write(aq_parent(obj)) shadow_history = Versioner(obj).get_history_metadata() manager = getMultiAdapter((obj, self.request), ICheckinCheckoutManager) if not shadow_history: return NoVersionHistoryMetadataProxy(obj) return LazyHistoryMetadataProxy( shadow_history, obj.absolute_url(), obj, is_revert_allowed=manager.is_revert_allowed())
def rotate(self, user_id): """Rotate recently touched log. We basically truncate it to the RECENTLY_TOUCHED_LIMIT. However, because the display limit only applies to recently touched items (not checked out docs), we need to take care to calculate the correct cutoff by "ignoring" checked out docs (adding them to the cutoff limit). """ num_checked_out = len(self.catalog(checked_out=user_id)) limit = get_registry_record('limit', IRecentlyTouchedSettings) cutoff = limit + num_checked_out truncated = unprotected_write( self.get_recently_touched_log(user_id)[:cutoff]) unprotected_write(IAnnotations( self.portal)[RECENTLY_TOUCHED_KEY])[user_id] = truncated
def search_results(self, query): # `query` , as generated by `VersionsTab.get_base_query()`, is # actually the object we're displaying the version history for obj = query # CMFEditions causes writes to the parent when retrieving versions unprotected_write(aq_parent(obj)) repo_tool = api.portal.get_tool('portal_repository') shadow_history = repo_tool.getHistoryMetadata(obj) manager = getMultiAdapter((obj, self.request), ICheckinCheckoutManager) return LazyHistoryMetadataProxy( shadow_history, obj.absolute_url(), obj, is_revert_allowed=manager.is_revert_allowed())
def purge_mappings(self): """Purge all child/prefix-mappings for context. This is potentially dangerous and should only be used carefully! """ annotations = unprotected_write(IAnnotations(self.context)) annotations.pop(REPOSITORY_FOLDER_KEY, None) annotations.pop(DOSSIER_KEY, None)
def get_recently_touched_log(self, user_id): return unprotected_write(IAnnotations(self.portal)[RECENTLY_TOUCHED_KEY][user_id])
def _get_history_for_writing(self): """Return the history for writing and make sure a default is also initialized if it is the first time the history is accessed. """ return unprotected_write(IAnnotations(self.context).setdefault( self.annotation_key, OOBTree()))
def remove_number(self, obj): ann = unprotected_write(IAnnotations(obj)) if SEQUENCE_NUMBER_ANNOTATION_KEY in ann.keys(): del ann[SEQUENCE_NUMBER_ANNOTATION_KEY]
def get_recently_touched_log(self, user_id): return unprotected_write( IAnnotations(self.portal)[RECENTLY_TOUCHED_KEY][user_id])