class NotificationConfiglet(BrowserView): template = ViewPageTemplateFile('configlet.pt') def __call__(self, delete=None): self.storage = IAnnotations(self.context) if delete and self.storage.has_key(STORAGE_KEY) and self.storage[STORAGE_KEY].has_key(delete): del self.storage[STORAGE_KEY][delete] statusmessages = IStatusMessage(self.request) statusmessages.addStatusMessage(_('message_deleted', default='Notification template deleted'), type='info') return self.template() @memoize def templates(self): if not self.storage.has_key(STORAGE_KEY): return [] templates_raw = self.storage.get(STORAGE_KEY) vocabulary = availableWorkflows(self.context) templates = [] for name, template in templates_raw.items(): template = {'name': name, 'template': template} try: term = vocabulary.getTermByToken(name) template.update(dict(title=(term.title or term.token))) except: pass templates.append(template) return templates
def registerPersistentConfig(site, type_): """ Try to get persistent pipeline configuration of given type (export or import) and register it for use with transmogrifier. """ global CONFIGFILE anno = IAnnotations(site) key = '%s.%s' % (ANNOKEY, type_) config = anno.has_key(key) and anno[key] or None # unregister old config name = 'persitent-%s' % type_ if name in configuration_registry._config_ids: configuration_registry._config_ids.remove(name) del configuration_registry._config_info[name] # register new if config is not None: title = description = u'Persistent %s pipeline' tf = tempfile.NamedTemporaryFile('w+t', suffix='.cfg') tf.write(config) tf.seek(0) CONFIGFILE = tf configuration_registry.registerConfiguration(name, title, description, tf.name) return name else: return None
def __init__(self, context): self.context = context self.portal = getToolByName(self.context, 'portal_url').getPortalObject() storage = IAnnotations(self.portal) if not storage.has_key(STORAGE_KEY): storage[STORAGE_KEY] = PersistentDict() self.storage = storage[STORAGE_KEY]
def queue(self): queue = getattr(self, "_queue", None) if queue is None: annotations = IAnnotations(self.context) if not annotations.has_key(self.key): annotations[self.key] = IOBTree() self._queue = annotations[self.key] return self._queue
def getInfoByRevision(self, instance, name, rev): """ Get info about a storage item by a give revision """ annotations = IAnnotations(instance) if not annotations.has_key(LOG_KEY) or \ not annotations[LOG_KEY].has_key(name) or \ not annotations[LOG_KEY][name].has_key(rev): return return annotations[LOG_KEY][name][rev]
def __init__(self, context, request, view, manager=None): super(HeaderViewlet, self).__init__(context, request, view, manager) self.mship = getToolByName(self.context, 'portal_membership') self.catalog = getToolByName(self.context, 'portal_catalog') self.props = getToolByName(self.context, 'portal_properties').site_properties if self.request.get('enable_header', False) or self.request.get('disable_header', False) or self.request.get('inherit_header', False): if not self.mship.checkPermission(permissions.ModifyPortalContent, self.context): return annotations = IAnnotations(context) if self.request.get('enable_header', False): if annotations.has_key(ANNOTATIONS_KEY_DISABLED): del annotations[ANNOTATIONS_KEY_DISABLED] annotations[ANNOTATIONS_KEY_ENABLED] = True elif self.request.get('disable_header', False): if annotations.has_key(ANNOTATIONS_KEY_ENABLED): del annotations[ANNOTATIONS_KEY_ENABLED] annotations[ANNOTATIONS_KEY_DISABLED] = True elif self.request.get('inherit_header', False): if annotations.has_key(ANNOTATIONS_KEY_DISABLED): del annotations[ANNOTATIONS_KEY_DISABLED] if annotations.has_key(ANNOTATIONS_KEY_ENABLED): del annotations[ANNOTATIONS_KEY_ENABLED]
def __call__(self): if not processor_lock.acquire(False): return try: annotations = IAnnotations(self.context) processor_lazy_lock.acquire() try: if not annotations.has_key(QUEUE_KEY): annotations[QUEUE_KEY] = PersistentList() queue = annotations[QUEUE_KEY] if annotations.has_key(QUEUE_LAZY_KEY): queue_lazy = annotations[QUEUE_LAZY_KEY] while len(queue_lazy): queue.append(queue_lazy.pop(0)) finally: processor_lazy_lock.release() if not annotations.has_key(QUEUE_KEY): return queue = annotations[QUEUE_KEY] previous = None while len(queue): sp = transaction.savepoint(optimistic=True) action = queue.pop(0) if action == previous: info('skipping action %s' % action) continue info('starting action %s' % action) try: action.execute(self.context) previous = action info('action finished %s' % action) except Exception, e: sp.rollback() exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() info('action failed %s\n%s' % (action, ''.join(traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback)))) break finally: processor_lock.release()
def __call__(self, name=None): self.name = name storage = IAnnotations(self.context) if not storage.has_key(STORAGE_KEY): storage[STORAGE_KEY] = PersistentDict() self.storage = storage[STORAGE_KEY] self.form_fields.get('name').field = self.form_fields.get('name').field.bind(self.context) self.form_fields.get('template').field = self.form_fields.get('template').field.bind(self.context) self.form_fields.get('template').field.default = None self.form_fields.get('template').field.default = None if self.name and self.storage.has_key(self.name): self.form_fields.get('name').field.default = self.name self.form_fields.get('template').field.default = self.storage.get(self.name) return super(NotificationTemplateForm, self).__call__()
def __call__(self, committed): if committed: processor_lazy_lock.acquire() try: plone = getSite() key = QUEUE_LAZY_KEY annotations = IAnnotations(plone) if not annotations.has_key(key): annotations[key] = PersistentList() if len(annotations[key]) and \ self.action == annotations[key][-1]: info('skipping action %s' % self.action) else: annotations[key].append(self.action) transaction.commit() info('appended action %s' % self.action) finally: processor_lazy_lock.release()
def before_file_remove(obj, event): request = getattr(obj, 'REQUEST', '') if request and hasattr(request, 'ACTUAL_URL') and \ request.ACTUAL_URL.endswith('delete_confirmation') and \ request.get('REQUEST_METHOD') == 'GET': # delete event is fired by link integrity check, skip it. return # skip source remove if we have appropriate flag set in request annotations = IAnnotations(request) if annotations and annotations.has_key(SKIP_SOURCE_REMOVE_FLAG) and \ annotations[SKIP_SOURCE_REMOVE_FLAG]: return try: remove_source(obj) except AWSSourceRemoveError, e: IStatusMessage(request).addStatusMessage(_(e), type='error') utils.abort_transaction(request)
def log(self, name, instance): """ """ if instance.isTemporary(): return annotations = IAnnotations(instance) if not annotations.has_key(LOG_KEY): annotations[LOG_KEY] = PersistentDict() if not annotations[LOG_KEY].has_key(name): annotations[LOG_KEY][name] = PersistentDict() revision = self.getRevision(instance, name) if not revision: return try: data = PersistentDict() data['filepath'] = self.getFilepath(instance, name) data['filename'] = self.getFilename(instance, name) data['mimetype'] = self.getContentType(instance, name) annotations[LOG_KEY][name][revision] = data except AttributeError: pass
def get_storage(context): annotations = IAnnotations(context) if not annotations.has_key(annotation_key): annotations[annotation_key] = PersistentDict() return annotations[annotation_key]
def abort_remove(obj, event): annotations = IAnnotations(obj.REQUEST) if annotations and annotations.has_key(ABORT_TRANSACTION_FLAG) and \ annotations[ABORT_TRANSACTION_FLAG]: transaction.abort()
def get_storage( context ): annotations = IAnnotations( context ) if not annotations.has_key( annotation_key ): annotations[ annotation_key ] = PersistentDict() return annotations[annotation_key]
def __init__(self, context): self.context = context annotations = IAnnotations(context) if not annotations.has_key(ANNOTATIONS_KEY): annotations[ANNOTATIONS_KEY] = PersistentDict() self.storage = annotations[ANNOTATIONS_KEY]