<s> """<STR_LIT>""" <EOL> from django . db . models import Max <EOL> from django . db . models import Count <EOL> from django . contrib . sitemaps import Sitemap <EOL> from django . core . urlresolvers import reverse <EOL> from tagging . models import Tag <EOL> from tagging . models import TaggedItem <EOL> from zinnia . models . entry import Entry <EOL> from zinnia . models . author import Author <EOL> from zinnia . models . category import Category <EOL> from zinnia . settings import PROTOCOL <EOL> class ZinniaSitemap ( Sitemap ) : <EOL> """<STR_LIT>""" <EOL> protocol = PROTOCOL <EOL> class EntrySitemap ( ZinniaSitemap ) : <EOL> """<STR_LIT>""" <EOL> priority = <NUM_LIT:0.5> <EOL> changefreq = '<STR_LIT>' <EOL> def items ( self ) : <EOL> """<STR_LIT>""" <EOL> return Entry . published . all ( ) <EOL> def lastmod ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return obj . last_update <EOL> class EntryRelatedSitemap ( ZinniaSitemap ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> changefreq = '<STR_LIT>' <EOL> def items ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . get_queryset ( ) <EOL> self . cache_infos ( queryset ) <EOL> self . set_max_entries ( ) <EOL> return queryset <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . model . published . annotate ( <EOL> count_entries_published = Count ( '<STR_LIT>' ) ) . annotate ( <EOL> last_update = Max ( '<STR_LIT>' ) ) . order_by ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def cache_infos ( self , queryset ) : <EOL> """<STR_LIT>""" <EOL> self . cache = { } <EOL> for item in queryset : <EOL> self . cache [ item . pk ] = ( item . count_entries_published , <EOL> item . last_update ) <EOL> def set_max_entries ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cache : <EOL> self . max_entries = float ( max ( [ i [ <NUM_LIT:0> ] for i in self . cache . values ( ) ] ) ) <EOL> def lastmod ( self , item ) : <EOL> """<STR_LIT>""" <EOL> return self . cache [ item . pk ] [ <NUM_LIT:1> ] <EOL> def priority ( self , item ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % max ( self . cache [ item . pk ] [ <NUM_LIT:0> ] / self . max_entries , <NUM_LIT:0.1> ) <EOL> class CategorySitemap ( EntryRelatedSitemap ) : <EOL> """<STR_LIT>""" <EOL> model = Category <EOL> class AuthorSitemap ( EntryRelatedSitemap ) : <EOL> """<STR_LIT>""" <EOL> model = Author <EOL> class TagSitemap ( EntryRelatedSitemap ) : <EOL> """<STR_LIT>""" <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . entries_qs = Entry . published . all ( ) <EOL> return Tag . objects . usage_for_queryset ( <EOL> self . entries_qs , counts = True ) <EOL> def cache_infos ( self , queryset ) : <EOL> """<STR_LIT>""" <EOL> self . cache = { } <EOL> for item in queryset : <EOL> self . cache [ item . pk ] = ( <EOL> item . count , TaggedItem . objects . get_by_model ( <EOL> self . entries_qs , item ) [ <NUM_LIT:0> ] . last_update ) <EOL> def location ( self , item ) : <EOL> """<STR_LIT>""" <EOL> return reverse ( '<STR_LIT>' , args = [ item . name ] ) </s>
