def getAnnotationsInfo(self): """Get all annotations associated with an object. If no annotations are associated with the object, ``None`` is returned. Otherwise we get a list of dicts, each containing keys ``key``, ``key_string`` (textual representation of key), ``value``, ``value_type`` and ``value_type_link''. """ if not self.isAnnotatable(): return [] naked = removeSecurityProxy(self.obj) annotations = IAnnotations(naked) if not hasattr(annotations, 'items'): return [] elems = [] for key, value in annotations.items(): elems.append({ 'key': key, 'key_string': ` key `, 'value': value, 'value_type': type(value), 'value_type_link': self.getTypeLink(type(value)), 'value_linkable': self.isLinkable(value), 'obj': annotations[key] }) return elems
def traverse(self, path): namespace = 'anno' print "TRAVERSE", path if path.startswith(namespace): name = path[len(namespace):] naked = removeSecurityProxy(self.context) annotations = IAnnotations(naked) print annotations.items() #obj = name and annotations[name] or annotations #obj = path and annotations[name] or annotations obj = ObjectInfo("Hello") if not IPhysicallyLocatable(obj, False): #obj = LocationProxy( # obj, self.context, namespace + name) obj = LocationProxy(obj, self.context, 'anno' + name) return obj return
def __call__(self): query = {'portal_type': 'opengever.meeting.proposal'} for proposal in self.objects(query, 'Fix proposal history'): history = IAnnotations(proposal).get('object_history', OOBTree()) for key, value in history.items(): if value.get('name') and not value.get('history_type'): value.update({'history_type': value.get('name')})
def test_outputfilter_scaled(self, browser): page = browser.login().visit(self.obj) annos = IAnnotations(self.obj) scales = annos.items()[1][1].keys() for scale in scales: if isinstance(scale, str): scale_uid = scale image = page.css('.fileListing img')[1].node self.assertEqual("http://nohost/plone/file/@@images/" + scale_uid + ".jpeg", image.attrib['src'])
def get_options(self): nav_root = self.context.restrictedTraverse(getNavigationRoot(self.context)) options = IAnnotations(nav_root).get('onegov.customstyles', {}) styles = [] for key, value in options.items(): if value and key.startswith('css.'): styles.append('$%s: %s;' % (key.replace('css.',''), value)) if value and key == 'custom_scss': styles.append(value) return '\n'.join(styles)
def get_options(self): nav_root = self.context.restrictedTraverse( getNavigationRoot(self.context)) options = IAnnotations(nav_root).get('onegov.customstyles', {}) styles = [] for key, value in options.items(): if value and key.startswith('css.'): styles.append('$%s: %s;' % (key.replace('css.', ''), value)) if value and key == 'custom_scss': styles.append(value) return '\n'.join(styles)
def _get(kls, obj): data = {} try: annotations = IAnnotations(obj) except TypeError: return {} for key, annotation in annotations.items(): if key.startswith('Archetypes.storage') or \ key in _skipped_annotations or \ key.startswith('plone.portlets'): # skip because this data should be handled elsewhere continue data[key] = annotation return data
def _get(kls, obj): data = {} try: annotations = IAnnotations(obj) except TypeError: return {} for key, annotation in annotations.items(): if key.startswith('Archetypes.storage') or \ key in _skipped_annotations or \ key.startswith('plone.portlets'): # skip because this data should be handled elsewhere continue data[key] = annotation return data
def __call__(self): draftAnnotations = IAnnotations(self.draft) targetAnnotations = IAnnotations(self.target) for key, value in draftAnnotations.items(): if key.startswith(ANNOTATIONS_KEY_PREFIX): targetAnnotations[key] = value annotationsDeleted = getattr( self.draft, '_proxyAnnotationsDeleted', set()) for key in annotationsDeleted: if key.startswith(ANNOTATIONS_KEY_PREFIX) and key in targetAnnotations: # noqa del targetAnnotations[key]
def export(self): """\ Generate and save structure, delete all objects, rebuild. """ if hasattr(self, 'exported'): return self.exported cur = self.export_source() # we need the actual data, now. self.exported = list(self._export(cur)) # delete all existing annotations notes = IAnnotations(cur) for key, obj in notes.items(): if IExposureFileNote.providedBy(obj): del notes[key] return self.exported
def get_recipient_settings(megaphone, recipient_type): data = IAnnotations(megaphone).get(ANNOTATION_KEY, {}).get('recipients', {}) return [(id, settings) for (id, settings) in data.items() if settings.get('recipient_type', 'standard') == recipient_type]