def edit_feed(feed, data_dict): """ Edits the specified feed with the dictionary of data provided, validating both the data and the request URL (as with create_feed) """ data, errors = df.validate(data_dict, fs.feed_schema()) if errors: raise logic.ValidationError(errors, error_summary(errors)) ok,format, content = util.validate_feed(data.get('url')) if not ok: raise feedmodels.FeedException(_("Unable to fetch feed")) # If URL is different use new content, but if using existing # content replace it if still empty if feed.url != data.get('url'): feed.content = content else: feed.content = data.get('content', None) or content feed.title = data.get('title') feed.url = data.get('url') feed.template = data.get('template') feed.format = format feed.updated = data.get('updated') feed.html_entries = data.get('html_entries') feed.save() return feed
def create_feed(data_dict): """ Creates a new feed after validating the information provided, and then validates the data held at the specified URL is in fact a feed """ data, errors = df.validate(data_dict, fs.feed_schema()) if errors: raise logic.ValidationError(errors, action.error_summary(errors)) ok,format,content = util.validate_feed(data.get('url')) if not ok: raise feedmodels.FeedException(_("Unable to fetch feed")) feed = feedmodels.Feed( name = _generate_name(data.get('title')), title = data.get('title'), url = data.get('url'), format = format, updated = data.get('updated'), content = content, template = data.get('template'), html_entries = data.get('html_entries') ) feed.save() return feed