<s> from __future__ import unicode_literals <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . syndication . views import Feed , add_domain <EOL> from django . core . urlresolvers import reverse <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . feedgenerator import Atom1Feed <EOL> from django . utils . html import strip_tags <EOL> from mezzanine . blog . models import BlogPost , BlogCategory <EOL> from mezzanine . conf import settings <EOL> from mezzanine . core . templatetags . mezzanine_tags import richtext_filters <EOL> from mezzanine . core . request import current_request <EOL> from mezzanine . generic . models import Keyword <EOL> from mezzanine . utils . html import absolute_urls <EOL> from mezzanine . utils . sites import current_site_id <EOL> User = get_user_model ( ) <EOL> class PostsRSS ( Feed ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . tag = kwargs . pop ( "<STR_LIT>" , None ) <EOL> self . category = kwargs . pop ( "<STR_LIT>" , None ) <EOL> self . username = kwargs . pop ( "<STR_LIT:username>" , None ) <EOL> super ( PostsRSS , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _public = True <EOL> page = None <EOL> if "<STR_LIT>" in settings . INSTALLED_APPS : <EOL> from mezzanine . pages . models import Page <EOL> try : <EOL> page = Page . objects . published ( ) . get ( slug = settings . BLOG_SLUG ) <EOL> except Page . DoesNotExist : <EOL> pass <EOL> else : <EOL> self . _public = not page . login_required <EOL> if self . _public : <EOL> if page is not None : <EOL> self . _title = "<STR_LIT>" % ( page . title , settings . SITE_TITLE ) <EOL> self . _description = strip_tags ( page . description ) <EOL> else : <EOL> self . _title = settings . SITE_TITLE <EOL> self . _description = settings . SITE_TAGLINE <EOL> def __call__ ( self , * args , ** kwarg ) : <EOL> self . _request = current_request ( ) <EOL> self . _site = Site . objects . get ( id = current_site_id ( ) ) <EOL> return super ( PostsRSS , self ) . __call__ ( * args , ** kwarg ) <EOL> def add_domain ( self , link ) : <EOL> return add_domain ( self . _site . domain , link , self . _request . is_secure ( ) ) <EOL> def title ( self ) : <EOL> return self . _title <EOL> def description ( self ) : <EOL> return self . _description <EOL> def link ( self ) : <EOL> return self . add_domain ( reverse ( "<STR_LIT>" ) ) <EOL> def items ( self ) : <EOL> if not self . _public : <EOL> return [ ] <EOL> blog_posts = BlogPost . objects . published ( ) . select_related ( "<STR_LIT:user>" <EOL> ) . prefetch_related ( "<STR_LIT>" ) <EOL> if self . tag : <EOL> tag = get_object_or_404 ( Keyword , slug = self . tag ) <EOL> blog_posts = blog_posts . filter ( keywords__keyword = tag ) <EOL> if self . category : <EOL> category = get_object_or_404 ( BlogCategory , slug = self . category ) <EOL> blog_posts = blog_posts . filter ( categories = category ) <EOL> if self . username : <EOL> author = get_object_or_404 ( User , username = self . username ) <EOL> blog_posts = blog_posts . filter ( user = author ) <EOL> limit = settings . BLOG_RSS_LIMIT <EOL> if limit is not None : <EOL> blog_posts = blog_posts [ : settings . BLOG_RSS_LIMIT ] <EOL> return blog_posts <EOL> def item_description ( self , item ) : <EOL> description = richtext_filters ( item . content ) <EOL> absolute_urls_name = "<STR_LIT>" <EOL> if absolute_urls_name not in settings . RICHTEXT_FILTERS : <EOL> description = absolute_urls ( description ) <EOL> return description <EOL> def categories ( self ) : <EOL> if not self . _public : <EOL> return [ ] <EOL> return BlogCategory . objects . all ( ) <EOL> def feed_url ( self ) : <EOL> return self . add_domain ( self . _request . path ) <EOL> def item_link ( self , item ) : <EOL> return self . add_domain ( super ( PostsRSS , self ) . item_link ( item ) ) <EOL> def item_author_name ( self , item ) : <EOL> return item . user . get_full_name ( ) or item . user . username <EOL> def item_author_link ( self , item ) : <EOL> username = item . user . username <EOL> link = reverse ( "<STR_LIT>" , kwargs = { "<STR_LIT:username>" : username } ) <EOL> return self . add_domain ( link ) <EOL> def item_pubdate ( self , item ) : <EOL> return item . publish_date <EOL> def item_categories ( self , item ) : <EOL> return item . categories . all ( ) <EOL> def item_enclosure_url ( self , item ) : <EOL> if item . featured_image : <EOL> return self . add_domain ( item . featured_image . url ) <EOL> class PostsAtom ( PostsRSS ) : <EOL> """<STR_LIT>""" <EOL> feed_type = Atom1Feed <EOL> def subtitle ( self ) : <EOL> return self . description ( ) </s>
