def replaceMetadata(self, obj, dom): """ We replace the module metadata with the values from the request. We use METADATA_DEFAULTS to reset those values we don't have on the request back to what they would be for a new module. This effictive 'clears' all metadata fields that were not supplied on the request. We delete all collaboration requests that are 'pending', but don't have equivalent data on the request. We add all new roles. TODO: Checkout the _reset method in ModuleEditor. It might be better to use that than do our own thing here. """ self.update_semantics = 'replace' # create a metadata dict that has all the defaults, overridden by the # current dom values. This way we will 'clear' the properties not in # the dom. metadata = copy(METADATA_DEFAULTS) metadata.update(self.getMetadata(dom, METADATA_MAPPING)) if metadata: self.validate_metadata(metadata) metadata = self.fixEntities(metadata, ATTRIBUTES_TO_FIX) if ICollection.providedBy(obj): obj.collection_metadata(**metadata) elif IModule.providedBy(obj): obj.update_metadata(**metadata) # we set GoogleAnalyticsTrackingCode explicitly, since the script # 'update_metadata' ignores empty strings. obj.GoogleAnalyticsTrackingCode = metadata.get('GoogleAnalyticsTrackingCode') self.updateRoles(obj, dom) obj.reindexObject(idxs=metadata.keys())
def updateMetadata(self, obj, dom): """ Metadata as described in: SWORD V2 Spec for Publishing Modules in Connexions Section: Metadata """ self.update_semantics = 'merge' metadata = {} metadata.update(self.getMetadata(dom, METADATA_MAPPING)) for oerdc_name, cnx_name in METADATA_MAPPING.items(): if cnx_name in ['keywords', 'subject',]: current_values = getattr(obj, cnx_name) if current_values: if type(current_values) == TupleType: current_values = list(current_values) new_values = metadata.get(cnx_name, []) if type(new_values) == StringType: new_values = [new_values,] for value in new_values: if value not in current_values: current_values.extend(value) metadata[cnx_name] = new_values if metadata: self.validate_metadata(metadata) metadata = self.fixEntities(metadata, ATTRIBUTES_TO_FIX) if ICollection.providedBy(obj): obj.collection_metadata(**metadata) elif IModule.providedBy(obj): obj.update_metadata(**metadata) self.updateRoles(obj, dom) obj.reindexObject(idxs=metadata.keys())
def purgeContent(ob, stool): content = getToolByName(ob, 'content') try: content = content.getRhaptosObject(ob.getId(), 'latest').getTarget() except: return paths = ['content/%s/'%content.aq_parent.getId()] if ICollection.providedBy(content): paths.extend(['content/%s/'%m for m in content.containedModuleIds()]) print content, paths stool.pruneUrls(paths, 'PURGE_REGEXP')
def purgeContent(ob, stool): content = getToolByName(ob, 'content') try: content = content.getRhaptosObject(ob.getId(), 'latest').getTarget() except: return paths = ['content/%s/' % content.aq_parent.getId()] if ICollection.providedBy(content): paths.extend(['content/%s/' % m for m in content.containedModuleIds()]) print content, paths stool.pruneUrls(paths, 'PURGE_REGEXP')
def publishRevision(self, object, message): stool = getToolByName(self, 'portal_squid', None) if stool is None: orig_publishRevision(self, object, message) return ctool = getToolByName(self, 'content').catalog portal_url = getToolByName(self, 'portal_url') oldversion = None try: oldversion = object.getPublishedObject().latest.version except: pass orig_publishRevision(self, object, message) ob = object.getPublishedObject() # purge rss stool.pruneUrls(['content/recent.rss', 'content/collections.rss']) # always purge latest and previous version path = portal_url.getRelativeUrl(ob) paths = ['%s/latest/' % path] if oldversion: paths.append('%s/%s/' % (path, oldversion)) if object.meta_type == "Module Editor": # purge all collection that reference this module cs = ctool({'containedModuleIds': ob.id, 'portal_type': 'Collection'}) for c in cs: p = c.getPath()[1:].split('/', 1)[-1] paths.append('%s/' % p.rsplit('/latest')[0]) elif ICollection.providedBy(object): # purge all latest modules that are part of this collection paths.extend( ['content/%s/latest/' % m for m in object.containedModuleIds()]) stool.pruneUrls(paths, 'PURGE_REGEXP')
def publishRevision(self, object, message): stool = getToolByName(self, 'portal_squid', None) if stool is None: orig_publishRevision(self, object, message) return ctool = getToolByName(self, 'content').catalog portal_url = getToolByName(self, 'portal_url') oldversion = None try: oldversion = object.getPublishedObject().latest.version except: pass orig_publishRevision(self, object, message) ob = object.getPublishedObject() # purge rss stool.pruneUrls(['content/recent.rss','content/collections.rss']) # always purge latest and previous version path = portal_url.getRelativeUrl(ob) paths = ['%s/latest/'%path] if oldversion: paths.append('%s/%s/'%(path, oldversion)) if object.meta_type == "Module Editor": # purge all collection that reference this module cs = ctool({'containedModuleIds':ob.id,'portal_type':'Collection'}) for c in cs: p = c.getPath()[1:].split('/', 1)[-1] paths.append('%s/'%p.rsplit('/latest')[0]) elif ICollection.providedBy(object): # purge all latest modules that are part of this collection paths.extend(['content/%s/latest/'%m for m in object.containedModuleIds()]) stool.pruneUrls(paths, 'PURGE_REGEXP')
def mergeMetadata(self, obj, dom): """ Merge the metadata on the obj (module) with whatever is in the dom parameter. From the spec. what should be replaced and what we should just add to. - title (dcterms:title) : Replace - abstract/summary (dcterms:abstract) : Replace - language (dcterms:language) : Replace - keyword (dcterms:subject) : Add - subject (dcterms:subject xsi:type="oerdc:Subjects") : Replace - contributor roles : Add - descriptionOfChanges : Replace - analyticsCode : Replace For more current info see: - Google doc: SWORD V2 Spec for Publishing Modules in Connexions """ self.update_semantics = 'merge' # create a metadata dict that has all the values from obj, overridden # by the current dom values. metadata = self.getModuleMetadata(obj, {}) metadata.update(self.getMetadata(dom, METADATA_MAPPING)) for oerdc_name, cnx_name in METADATA_MAPPING.items(): if cnx_name in ['keywords',]: old_value = getattr(obj, cnx_name) if old_value: current_value = list(metadata.get(cnx_name, [])) current_value.extend(old_value) metadata[cnx_name] = current_value if metadata: self.validate_metadata(metadata) metadata = self.fixEntities(metadata, ATTRIBUTES_TO_FIX) if ICollection.providedBy(obj): obj.collection_metadata(**metadata) elif IModule.providedBy(obj): obj.update_metadata(**metadata) self.updateRoles(obj, dom) obj.reindexObject(idxs=metadata.keys())