<s> from datetime import datetime <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import HttpResponse , Http404 <EOL> from django . shortcuts import render_to_response , get_object_or_404 <EOL> from django . template import RequestContext <EOL> from django . template . loader import render_to_string <EOL> from django . utils import simplejson as json <EOL> from django . core . paginator import Paginator , EmptyPage , InvalidPage <EOL> from django . contrib . sites . models import Site <EOL> from biblion . exceptions import InvalidSection <EOL> from biblion . models import Post , FeedHit <EOL> from biblion . settings import ALL_SECTION_NAME <EOL> from threadedcomments . forms import RichCommentForm <EOL> def blog_list ( request , section = None ) : <EOL> posts = Post . objects . current ( ) <EOL> section_name = None <EOL> if section : <EOL> try : <EOL> section_name = dict ( Post . SECTION_CHOICES ) [ Post . section_idx ( section ) ] <EOL> except KeyError : <EOL> raise Http404 ( ) <EOL> try : <EOL> posts = Post . objects . section ( section ) <EOL> except InvalidSection : <EOL> raise Http404 ( ) <EOL> return render_to_response ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : section , <EOL> "<STR_LIT>" : section_name , <EOL> "<STR_LIT>" : posts , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> def blog_post_detail ( request , ** kwargs ) : <EOL> if "<STR_LIT>" in kwargs : <EOL> if request . user . is_authenticated ( ) and request . user . is_staff : <EOL> queryset = Post . objects . all ( ) <EOL> post = get_object_or_404 ( queryset , pk = kwargs [ "<STR_LIT>" ] ) <EOL> else : <EOL> raise Http404 ( ) <EOL> else : <EOL> queryset = Post . objects . current ( ) <EOL> queryset = queryset . filter ( <EOL> published__year = int ( kwargs [ "<STR_LIT>" ] ) , <EOL> published__month = int ( kwargs [ "<STR_LIT>" ] ) , <EOL> published__day = int ( kwargs [ "<STR_LIT>" ] ) , <EOL> ) <EOL> post = get_object_or_404 ( queryset , slug = kwargs [ "<STR_LIT>" ] ) <EOL> post . inc_views ( ) <EOL> comment_form = RichCommentForm ( auto_id = '<STR_LIT>' ) <EOL> return render_to_response ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : post , <EOL> "<STR_LIT>" : comment_form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> def serialize_request ( request ) : <EOL> data = { <EOL> "<STR_LIT:path>" : request . path , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : request . META . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : request . META . get ( "<STR_LIT>" ) , <EOL> } <EOL> } <EOL> for key in request . META : <EOL> if key . startswith ( "<STR_LIT>" ) : <EOL> data [ "<STR_LIT>" ] [ key ] = request . META [ key ] <EOL> return json . dumps ( data ) <EOL> def blog_feed ( request , section = None ) : <EOL> try : <EOL> posts = Post . objects . section ( section ) <EOL> except InvalidSection : <EOL> raise Http404 ( ) <EOL> if section is None : <EOL> section = ALL_SECTION_NAME <EOL> current_site = Site . objects . get_current ( ) <EOL> feed_title = "<STR_LIT>" % ( current_site . name , section [ <NUM_LIT:0> ] . upper ( ) + section [ <NUM_LIT:1> : ] ) <EOL> blog_url = "<STR_LIT>" % ( current_site . domain , reverse ( "<STR_LIT>" ) ) <EOL> url_name , kwargs = "<STR_LIT>" , { "<STR_LIT>" : section } <EOL> feed_url = "<STR_LIT>" % ( current_site . domain , reverse ( url_name , kwargs = kwargs ) ) <EOL> if posts : <EOL> feed_updated = posts [ <NUM_LIT:0> ] . published <EOL> else : <EOL> feed_updated = datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> hit = FeedHit ( ) <EOL> hit . request_data = serialize_request ( request ) <EOL> hit . save ( ) <EOL> atom = render_to_string ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : feed_url , <EOL> "<STR_LIT>" : feed_title , <EOL> "<STR_LIT>" : blog_url , <EOL> "<STR_LIT>" : feed_url , <EOL> "<STR_LIT>" : feed_updated , <EOL> "<STR_LIT>" : posts , <EOL> "<STR_LIT>" : current_site , <EOL> } ) <EOL> return HttpResponse ( atom , mimetype = "<STR_LIT>" ) </s>
