def process(self, entry): ''' Process a single entry and return an item model. ''' feed_contents = entry.get('content') feed_description = entry.get('description') if feed_contents: content_type = feed_contents[0]['type'] content = force_unicode(feed_contents[0]['value']) clean_content = convert_entities(strip_tags(content)) elif feed_description: content_type = "text/html" content = force_unicode(feed_description) clean_content = convert_entities(strip_tags(content)) else: content_type = None content = None clean_content = None # Make sure the title is clean too. title = convert_entities(strip_tags(force_unicode(entry.get('title')))) media_url = None media_content_attrs = entry.get('media_content', []) for content in media_content_attrs: media_url = content.get('url') if media_url: break thumbnail_url = None media_thumbnail_attrs = entry.get('media_thumbnail', []) for thumbnail in media_thumbnail_attrs: thumbnail_url = thumbnail.get('url') if thumbnail_url: break media_description_type = None media_description_content = None media_description = entry.get('media_description') if media_description: media_description_type = media_description.get('type') media_description_content = media_description.get('content') if media_description_content: media_description_content = force_unicode(media_description_content) media_player_url = None media_player_attrs = entry.get('media_player') if media_player_attrs: media_player_url = media_player_attrs.get('url') item = Item( feed = self.feed, date = entry.get('published'), title = title, content = content, content_type = content_type, clean_content = clean_content, author = entry.get('author'), permalink = entry.get('link'), media_url = media_url, media_thumbnail_url = thumbnail_url, media_player_url = media_player_url, media_description = media_description_content, media_description_type = media_description_type, ) return item
def save_model(self, request, obj, form, change): obj.clean_content = convert_entities(strip_tags(obj.content)) obj.save()
def process(self, entry): ''' Process a single entry and return an item model. ''' feed_contents = entry.get('content') feed_description = entry.get('description') if feed_contents: content_type = feed_contents[0]['type'] content = force_unicode(feed_contents[0]['value']) clean_content = convert_entities(strip_tags(content)) elif feed_description: content_type = "text/html" content = force_unicode(feed_description) clean_content = convert_entities(strip_tags(content)) else: content_type = None content = None clean_content = None # Make sure the title is clean too. title = convert_entities(strip_tags(force_unicode(entry.get('title')))) media_url = None media_content_attrs = entry.get('media_content', []) for content in media_content_attrs: media_url = content.get('url') if media_url: break thumbnail_url = None media_thumbnail_attrs = entry.get('media_thumbnail', []) for thumbnail in media_thumbnail_attrs: thumbnail_url = thumbnail.get('url') if thumbnail_url: break media_description_type = None media_description_content = None media_description = entry.get('media_description') if media_description: media_description_type = media_description.get('type') media_description_content = media_description.get('content') if media_description_content: media_description_content = force_unicode( media_description_content) media_player_url = None media_player_attrs = entry.get('media_player') if media_player_attrs: media_player_url = media_player_attrs.get('url') item = Item( feed=self.feed, date=entry.get('published'), title=title, content=content, content_type=content_type, clean_content=clean_content, author=entry.get('author'), permalink=entry.get('link'), media_url=media_url, media_thumbnail_url=thumbnail_url, media_player_url=media_player_url, media_description=media_description_content, media_description_type=media_description_type, ) return item