def handleRepair(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return query = Indexed('chimpfeeds') brains = self.context.portal_catalog.evalAdvancedQuery(query) context = self.getContent() vocabulary = feeds_factory(context) all_feeds = set(term.value for term in vocabulary) count = 0 bad = set() changed = [] for i, brain in enumerate(brains): try: feeds = set(brain.chimpfeeds) except TypeError: continue missing = feeds - all_feeds bad |= missing if missing: count += 1 obj = brain.getObject() try: field = obj.getField('feeds') except AttributeError: feeds = obj.feeds field = None else: feeds = set(field.get(obj)) fixed = feeds - missing if field is None: obj.feeds = fixed else: field.set(obj, fixed) changed.append(obj) for obj in changed: modified(obj) obj.reindexObject() logger.info("Repair complete; %d items updated." % count) if bad: logger.info("Feeds removed: %s." % (", ".join(bad).encode('utf-8'))) IStatusMessage(self.request).addStatusMessage( _(u"Repaired ${count} items.", mapping={'count': count}), "info" )
def handleRepair(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return query = Indexed('chimpfeeds') brains = self.context.portal_catalog.evalAdvancedQuery(query) context = self.getContent() vocabulary = feeds_factory(context) all_feeds = set(term.value for term in vocabulary) count = 0 bad = set() changed = [] for i, brain in enumerate(brains): try: feeds = set(brain.chimpfeeds) except TypeError: continue missing = feeds - all_feeds bad |= missing if missing: count += 1 obj = brain.getObject() try: field = obj.getField('feeds') except AttributeError: feeds = obj.feeds field = None else: feeds = set(field.get(obj)) fixed = feeds - missing if field is None: obj.feeds = fixed else: field.set(obj, fixed) changed.append(obj) for obj in changed: modified(obj) obj.reindexObject() logger.info("Repair complete; %d items updated." % count) if bad: logger.info("Feeds removed: %s." % (", ".join(bad).encode('utf-8'))) IStatusMessage(self.request).addStatusMessage( _(u"Repaired ${count} items.", mapping={'count': count}), "info")
def urls(self): portal_url = getToolByName(self.settings, 'portal_url')() vocabulary = feeds_factory(self.settings) # Use term's titles as the basis for the feed URLs. urls = make_urls(vocabulary) return tuple(("%s/++chimpfeeds++/%s" % (portal_url, url), title) for url, value, title in urls)
def __getitem__(self, name): settings = IFeedSettings(self) vocabulary = feeds_factory(settings) # Use term's titles as the basis for the feed URLs. for url, value, title in make_urls(vocabulary): if url == name: break else: return KeyError(name) return Feed(self, self.REQUEST, value)
def urls(self): portal_url = getToolByName(self.settings, 'portal_url')() vocabulary = feeds_factory(self.settings) # Use term's titles as the basis for the feed URLs. urls = make_urls(vocabulary) return tuple( ("%s/++chimpfeeds++/%s" % (portal_url, url), title) for url, value, title in urls )