<s> import calendar as pycal <EOL> from datetime import date , datetime , time , timedelta <EOL> import random <EOL> import itertools <EOL> import operator <EOL> from django . conf import settings <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . markup . templatetags . markup import markdown <EOL> from django . contrib . sites . models import Site <EOL> from django . core . paginator import EmptyPage , InvalidPage , Paginator <EOL> from django . core . urlresolvers import reverse <EOL> from django . db . models import Q <EOL> from django . http import Http404 , HttpResponseRedirect , HttpResponsePermanentRedirect <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . template import RequestContext <EOL> from django . utils . html import urlize <EOL> from django . utils . http import urlencode <EOL> from django . utils . safestring import mark_safe <EOL> from django . views . decorators . cache import cache_page <EOL> from brubeck . articles . models import Article <EOL> from brubeck . blogs . models import Blog , Entry <EOL> from brubeck . core import imaging <EOL> from brubeck . design . models import Graphic , Layout <EOL> from brubeck . events . models import Calendar , Event <EOL> from brubeck . management . models import NewsBurst , WebFront <EOL> from brubeck . mapping . models import Map <EOL> from brubeck . multimedia . models import AudioClip , Slideshow , Video <EOL> from brubeck . photography . models import Photo <EOL> from brubeck . podcasts . models import Channel , Episode <EOL> from brubeck . publishing . models import Issue , Section <EOL> from brubeck . tagging . models import Tag <EOL> from brubeck . voxpopuli . models import Poll <EOL> @ cache_page ( <NUM_LIT> * <NUM_LIT:1> ) <EOL> def render_frontpage ( request ) : <EOL> """<STR_LIT>""" <EOL> site = Site . objects . get_current ( ) <EOL> front = WebFront . objects . select_related ( depth = <NUM_LIT:1> ) . filter ( site = site , type = '<STR_LIT>' ) . latest ( ) <EOL> issue = front . issue <EOL> articles = Article . get_published . select_related ( depth = <NUM_LIT:1> ) . filter ( section__publication__site = site ) . filter ( issue__pub_date__gte = issue . pub_date ) . filter ( issue__pub_date__lte = datetime . now ( ) ) . order_by ( '<STR_LIT>' ) <EOL> rotating_items = front . item_set . all ( ) <EOL> rotating_item_list = front . item_set . all ( ) <EOL> top_articles = articles [ : <NUM_LIT:4> ] <EOL> sections = Section . objects . all ( ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:5> ] <EOL> section_list = [ ] <EOL> for section in sections : <EOL> sec_obj = section <EOL> sec_articles = articles . filter ( section = section ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:5> ] <EOL> section_dict = { '<STR_LIT>' : sec_obj , '<STR_LIT>' : sec_articles } <EOL> section_list . append ( section_dict ) <EOL> all_blogs = Blog . current . filter ( section__publication__site = site ) . all ( ) <EOL> latest_blog_posts = Entry . get_published . filter ( blog__section__publication__site = site ) [ : <NUM_LIT:3> ] <EOL> latest_podcast_episodes = Episode . objects . all ( ) [ : <NUM_LIT:4> ] <EOL> latest_online_exclusives = Article . get_published . filter ( issue__pub_date__lte = datetime . now ( ) ) . filter ( type = '<STR_LIT>' ) <EOL> latest_online_exclusives = latest_online_exclusives [ : <NUM_LIT:3> ] <EOL> try : <EOL> latest_video = Video . objects . filter ( publication__site = site ) . latest ( ) <EOL> except : <EOL> latest_video = "<STR_LIT>" <EOL> try : <EOL> latest_slideshow = Slideshow . objects . filter ( publication__site = site ) . latest ( ) <EOL> except : <EOL> latest_slideshow = "<STR_LIT>" <EOL> try : <EOL> latest_audio = AudioClip . objects . filter ( publication__site = site ) . latest ( ) <EOL> except : <EOL> latest_audio = "<STR_LIT>" <EOL> if latest_slideshow != "<STR_LIT>" and latest_video != "<STR_LIT>" and latest_slideshow . pub_date > latest_video . pub_date : <EOL> latest_multimedia = latest_slideshow <EOL> else : <EOL> latest_multimedia = latest_video <EOL> if latest_audio != "<STR_LIT>" and latest_multimedia != "<STR_LIT>" and latest_audio . pub_date > latest_multimedia . pub_date : <EOL> latest_multimedia = latest_audio <EOL> other_info = None <EOL> if front . other_info : <EOL> other_info = markdown ( front . other_info ) <EOL> events = Event . not_past . filter ( calendars = front . calendar ) [ : <NUM_LIT:5> ] <EOL> news_bursts = NewsBurst . get_published . all ( ) <EOL> try : <EOL> issue_front = issue . layout_set . filter ( type = '<STR_LIT>' ) . filter ( section__publication__site = site ) . latest ( ) <EOL> except : <EOL> issue_front = None <EOL> issue_other_layouts = issue . layout_set . exclude ( type = '<STR_LIT>' ) . filter ( section__publication__site = site ) <EOL> year = datetime . now ( ) . year <EOL> month = datetime . now ( ) . month <EOL> calendar = None <EOL> calendar_list = Calendar . objects . all ( ) . order_by ( '<STR_LIT:name>' ) <EOL> events = Event . objects . all ( ) <EOL> month_formatted = pycal . monthcalendar ( year , month ) <EOL> month_minus = month - <NUM_LIT:1> <EOL> month_plus = month + <NUM_LIT:1> <EOL> month_name = pycal . month_name [ month ] <EOL> weekday_header = pycal . weekheader ( <NUM_LIT:3> ) . strip ( ) . split ( "<STR_LIT:U+0020>" ) <EOL> year_minus = year - <NUM_LIT:1> <EOL> year_plus = year + <NUM_LIT:1> <EOL> today = datetime . now ( ) . day <EOL> this_month = month <EOL> this_year = year <EOL> event_list = events . filter ( Q ( start__year = year , start__month = month ) | Q ( end__year = year , end__month = month ) ) <EOL> events = Event . not_past . filter ( calendars = front . calendar ) [ : <NUM_LIT:5> ] <EOL> page = { <EOL> '<STR_LIT>' : all_blogs , <EOL> '<STR_LIT>' : calendar , <EOL> '<STR_LIT>' : calendar_list , <EOL> '<STR_LIT>' : events , <EOL> '<STR_LIT>' : event_list , <EOL> '<STR_LIT>' : issue , <EOL> '<STR_LIT>' : issue_front , <EOL> '<STR_LIT>' : issue_other_layouts , <EOL> '<STR_LIT>' : latest_audio , <EOL> '<STR_LIT>' : latest_blog_posts , <EOL> '<STR_LIT>' : latest_multimedia , <EOL> '<STR_LIT>' : latest_online_exclusives , <EOL> '<STR_LIT>' : latest_podcast_episodes , <EOL> '<STR_LIT>' : latest_slideshow , <EOL> '<STR_LIT>' : latest_video , <EOL> '<STR_LIT>' : month , <EOL> '<STR_LIT>' : month_formatted , <EOL> '<STR_LIT>' : month_minus , <EOL> '<STR_LIT>' : month_name , <EOL> '<STR_LIT>' : month_plus , <EOL> '<STR_LIT>' : news_bursts , <EOL> '<STR_LIT>' : other_info , <EOL> '<STR_LIT>' : rotating_item_list , <EOL> '<STR_LIT>' : rotating_items , <EOL> '<STR_LIT>' : section_list , <EOL> '<STR_LIT>' : this_month , <EOL> '<STR_LIT>' : this_year , <EOL> '<STR_LIT>' : today , <EOL> '<STR_LIT>' : top_articles , <EOL> '<STR_LIT>' : weekday_header , <EOL> '<STR_LIT>' : year , <EOL> '<STR_LIT>' : year_minus , <EOL> '<STR_LIT>' : year_plus , <EOL> } <EOL> return render_to_response ( '<STR_LIT>' , page , context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( <NUM_LIT> * <NUM_LIT:10> ) <EOL> def section_front ( request , slug = None , page = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> site = Site . objects . get_current ( ) <EOL> try : <EOL> section = Section . objects . filter ( publication__site = site ) . get ( slug = slug ) <EOL> except Section . DoesNotExist : <EOL> raise Http404 <EOL> try : <EOL> section_front = WebFront . objects . filter ( site = site , type = '<STR_LIT>' ) . get ( top_sections = section ) <EOL> lead_item = section_front . item_set . all ( ) [ : <NUM_LIT:1> ] <EOL> priority_items = section_front . item_set . all ( ) [ <NUM_LIT:1> : <NUM_LIT:5> ] <EOL> except WebFront . DoesNotExist : <EOL> raise Http404 <EOL> archive_name = section . name <EOL> try : <EOL> page = int ( page ) <EOL> except ValueError : <EOL> raise Http404 <EOL> articles = Article . get_published . filter ( section = section ) . exclude ( webfrontitem__webfront = section_front ) [ : <NUM_LIT:10> ] <EOL> blog_posts = Entry . get_published . filter ( blog__section = section ) [ : <NUM_LIT:5> ] <EOL> recent_articles = Article . get_published . filter ( section = section ) [ : <NUM_LIT:50> ] <EOL> related_blogs = Blog . current . filter ( section = section ) <EOL> related_podcasts = Episode . objects . filter ( channel__section = section ) [ : <NUM_LIT:5> ] <EOL> tag_dict = { } <EOL> for article in recent_articles : <EOL> for tag in article . tags . all ( ) : <EOL> if tag . title in tag_dict : <EOL> tag_dict [ tag . title ] = tag_dict [ tag . title ] + <NUM_LIT:1> <EOL> else : <EOL> tag_dict [ tag . title ] = <NUM_LIT:1> <EOL> featured_tags = tag_dict . items ( ) <EOL> ordered_tags = sorted ( featured_tags , key = lambda tag : tag [ <NUM_LIT:1> ] , reverse = True ) [ : <NUM_LIT:30> ] <EOL> tag_objects = [ ] <EOL> for tag in ordered_tags : <EOL> tag_obj = Tag . objects . get ( title = tag [ <NUM_LIT:0> ] ) <EOL> tag_objects . append ( ( tag_obj , tag [ <NUM_LIT:1> ] ) ) <EOL> random . shuffle ( tag_objects ) <EOL> tag_cloud = [ ] <EOL> for tag in tag_objects : <EOL> if tag [ <NUM_LIT:1> ] > <NUM_LIT:15> : <EOL> new_size = <NUM_LIT> <EOL> else : <EOL> new_size = <NUM_LIT:9> + tag [ <NUM_LIT:1> ] <EOL> tag_cloud . append ( ( tag [ <NUM_LIT:0> ] , new_size ) ) <EOL> page = { <EOL> '<STR_LIT>' : archive_name , <EOL> '<STR_LIT>' : articles , <EOL> '<STR_LIT>' : blog_posts , <EOL> '<STR_LIT>' : lead_item , <EOL> '<STR_LIT>' : ordered_tags , <EOL> '<STR_LIT>' : priority_items , <EOL> '<STR_LIT>' : related_blogs , <EOL> '<STR_LIT>' : related_podcasts , <EOL> '<STR_LIT>' : section , <EOL> '<STR_LIT>' : section_front , <EOL> '<STR_LIT>' : tag_cloud , <EOL> } <EOL> return render_to_response ( '<STR_LIT>' , page , RequestContext ( request ) ) </s>
