<s> from django . http import HttpResponse , Http404 <EOL> from django . template import loader <EOL> from django . contrib . sites . models import Site <EOL> from django . core import urlresolvers <EOL> from django . utils . encoding import smart_str <EOL> from django . core . paginator import EmptyPage , PageNotAnInteger <EOL> def index ( request , sitemaps ) : <EOL> current_site = Site . objects . get_current ( ) <EOL> sites = [ ] <EOL> protocol = request . is_secure ( ) and '<STR_LIT>' or '<STR_LIT:http>' <EOL> for section , site in sitemaps . items ( ) : <EOL> if callable ( site ) : <EOL> pages = site ( ) . paginator . num_pages <EOL> else : <EOL> pages = site . paginator . num_pages <EOL> sitemap_url = urlresolvers . reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : section } ) <EOL> sites . append ( '<STR_LIT>' % ( protocol , current_site . domain , sitemap_url ) ) <EOL> if pages > <NUM_LIT:1> : <EOL> for page in range ( <NUM_LIT:2> , pages + <NUM_LIT:1> ) : <EOL> sites . append ( '<STR_LIT>' % ( protocol , current_site . domain , sitemap_url , page ) ) <EOL> xml = loader . render_to_string ( '<STR_LIT>' , { '<STR_LIT>' : sites } ) <EOL> return HttpResponse ( xml , mimetype = '<STR_LIT>' ) <EOL> def sitemap ( request , sitemaps , section = None ) : <EOL> maps , urls = [ ] , [ ] <EOL> if section is not None : <EOL> if section not in sitemaps : <EOL> raise Http404 ( "<STR_LIT>" % section ) <EOL> maps . append ( sitemaps [ section ] ) <EOL> else : <EOL> maps = sitemaps . values ( ) <EOL> page = request . GET . get ( "<STR_LIT:p>" , <NUM_LIT:1> ) <EOL> for site in maps : <EOL> try : <EOL> if callable ( site ) : <EOL> urls . extend ( site ( ) . get_urls ( page ) ) <EOL> else : <EOL> urls . extend ( site . get_urls ( page ) ) <EOL> except EmptyPage : <EOL> raise Http404 ( "<STR_LIT>" % page ) <EOL> except PageNotAnInteger : <EOL> raise Http404 ( "<STR_LIT>" % page ) <EOL> xml = smart_str ( loader . render_to_string ( '<STR_LIT>' , { '<STR_LIT>' : urls } ) ) <EOL> return HttpResponse ( xml , mimetype = '<STR_LIT>' ) </s>
