<s> import datetime <EOL> import os <EOL> import re <EOL> import urlparse <EOL> from itertools import groupby <EOL> from django import forms as django_forms <EOL> from django . conf import settings <EOL> from django . core . paginator import Paginator , InvalidPage <EOL> from django . core import urlresolvers <EOL> from django . forms import fields <EOL> from django . http import HttpResponse , HttpResponseNotFound , Http404 , HttpResponseRedirect , HttpResponsePermanentRedirect <EOL> from django . shortcuts import render_to_response <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . template import RequestContext <EOL> from django . template . defaultfilters import filesizeformat <EOL> from django . utils import html <EOL> from django . views . decorators . vary import vary_on_headers <EOL> from chronam . core . utils . url import unpack_url_path <EOL> from chronam . core import models , index <EOL> from chronam . core . rdf import title_to_graph , issue_to_graph , page_to_graph <EOL> from chronam . core . utils . utils import HTMLCalendar , _get_tip , _stream_file , _page_range_short , _rdf_base , get_page , label , create_crumbs <EOL> from chronam . core . decorator import cache_page , rdf_view <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def issues ( request , lccn , year = None ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> issues = title . issues . all ( ) <EOL> if issues . count ( ) > <NUM_LIT:0> : <EOL> if year is None : <EOL> _year = issues [ <NUM_LIT:0> ] . date_issued . year <EOL> else : <EOL> _year = int ( year ) <EOL> else : <EOL> _year = <NUM_LIT> <EOL> year_view = HTMLCalendar ( firstweekday = <NUM_LIT:6> , issues = issues ) . formatyear ( _year ) <EOL> dates = issues . dates ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class SelectYearForm ( django_forms . Form ) : <EOL> year = fields . ChoiceField ( choices = ( ( d . year , d . year ) for d in dates ) , <EOL> initial = _year ) <EOL> select_year_form = SelectYearForm ( ) <EOL> page_title = "<STR_LIT>" % title . display_name <EOL> page_name = "<STR_LIT>" <EOL> crumbs = create_crumbs ( title ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title_holdings ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> page_title = "<STR_LIT>" % label ( title ) <EOL> page_name = "<STR_LIT>" <EOL> crumbs = create_crumbs ( title ) <EOL> holdings = title . holdings . select_related ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title_marc ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> page_title = "<STR_LIT>" % label ( title ) <EOL> page_name = "<STR_LIT>" <EOL> crumbs = create_crumbs ( title ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> @ rdf_view <EOL> def title_rdf ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> graph = title_to_graph ( title ) <EOL> response = HttpResponse ( graph . serialize ( base = _rdf_base ( request ) , <EOL> include_base = True ) , <EOL> mimetype = '<STR_LIT>' ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title_atom ( request , lccn , page_number = <NUM_LIT:1> ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> issues = title . issues . all ( ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> paginator = Paginator ( issues , <NUM_LIT:100> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> raise Http404 ( "<STR_LIT>" % page_number ) <EOL> issues = page . object_list <EOL> num_issues = issues . count ( ) <EOL> if num_issues > <NUM_LIT:0> : <EOL> if issues [ <NUM_LIT:0> ] . batch . released : <EOL> feed_updated = issues [ <NUM_LIT:0> ] . batch . released <EOL> else : <EOL> feed_updated = issues [ <NUM_LIT:0> ] . batch . created <EOL> else : <EOL> feed_updated = title . created <EOL> host = request . get_host ( ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> mimetype = '<STR_LIT>' , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title_marcxml ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> return HttpResponse ( title . marc . xml , mimetype = '<STR_LIT>' ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def issue_pages ( request , lccn , date , edition , page_number = <NUM_LIT:1> ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> _year , _month , _day = date . split ( "<STR_LIT:->" ) <EOL> try : <EOL> _date = datetime . date ( int ( _year ) , int ( _month ) , int ( _day ) ) <EOL> except ValueError , e : <EOL> raise Http404 <EOL> try : <EOL> issue = title . issues . filter ( date_issued = _date , <EOL> edition = edition ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> except IndexError , e : <EOL> raise Http404 <EOL> paginator = Paginator ( issue . pages . all ( ) , <NUM_LIT:20> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> if not page . object_list : <EOL> notes = issue . notes . filter ( type = "<STR_LIT>" ) <EOL> num_notes = notes . count ( ) <EOL> if num_notes >= <NUM_LIT:1> : <EOL> display_label = notes [ <NUM_LIT:0> ] . label <EOL> explanation = notes [ <NUM_LIT:0> ] . text <EOL> page_title = '<STR_LIT>' % ( label ( title ) , label ( issue ) ) <EOL> page_head_heading = "<STR_LIT>" % ( title . display_name , label ( issue ) ) <EOL> page_head_subheading = label ( title ) <EOL> crumbs = create_crumbs ( title , issue , date , edition ) <EOL> profile_uri = '<STR_LIT>' <EOL> response = render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> @ rdf_view <EOL> def issue_pages_rdf ( request , lccn , date , edition ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition ) <EOL> graph = issue_to_graph ( issue ) <EOL> response = HttpResponse ( graph . serialize ( base = _rdf_base ( request ) , <EOL> include_base = True ) , <EOL> mimetype = '<STR_LIT>' ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> @ vary_on_headers ( '<STR_LIT>' ) <EOL> def page ( request , lccn , date , edition , sequence , words = None ) : <EOL> fragments = [ ] <EOL> if words : <EOL> fragments . append ( "<STR_LIT>" + words ) <EOL> qs = request . META . get ( '<STR_LIT>' ) <EOL> if qs : <EOL> fragments . append ( qs ) <EOL> if fragments : <EOL> path_parts = dict ( lccn = lccn , date = date , edition = edition , <EOL> sequence = sequence ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , <EOL> kwargs = path_parts ) <EOL> return HttpResponseRedirect ( url + "<STR_LIT:#>" + "<STR_LIT:&>" . join ( fragments ) ) <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> if not page . jp2_filename : <EOL> notes = page . notes . filter ( type = "<STR_LIT>" ) <EOL> num_notes = notes . count ( ) <EOL> if num_notes >= <NUM_LIT:1> : <EOL> explanation = notes [ <NUM_LIT:0> ] . text <EOL> else : <EOL> explanation = "<STR_LIT>" <EOL> if not words : <EOL> try : <EOL> words = _search_engine_words ( request ) <EOL> words = '<STR_LIT:+>' . join ( words ) <EOL> if len ( words ) > <NUM_LIT:0> : <EOL> path_parts = dict ( lccn = lccn , date = date , edition = edition , <EOL> sequence = sequence , words = words ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , <EOL> kwargs = path_parts ) <EOL> return HttpResponseRedirect ( url ) <EOL> except Exception , e : <EOL> if settings . DEBUG : <EOL> raise e <EOL> _issue = issue <EOL> while True : <EOL> previous_issue_first_page = None <EOL> _issue = _issue . previous <EOL> if not _issue : <EOL> break <EOL> previous_issue_first_page = _issue . first_page <EOL> if previous_issue_first_page : <EOL> break <EOL> _issue = issue <EOL> while True : <EOL> next_issue_first_page = None <EOL> _issue = _issue . next <EOL> if not _issue : <EOL> break <EOL> next_issue_first_page = _issue . first_page <EOL> if next_issue_first_page : <EOL> break <EOL> page_title = "<STR_LIT>" % ( label ( title ) , label ( issue ) , label ( page ) ) <EOL> page_head_heading = "<STR_LIT>" % ( title . display_name , label ( issue ) , label ( page ) ) <EOL> page_head_subheading = label ( title ) <EOL> crumbs = create_crumbs ( title , issue , date , edition , page ) <EOL> filename = page . jp2_abs_filename <EOL> if filename : <EOL> try : <EOL> im = os . path . getsize ( filename ) <EOL> image_size = filesizeformat ( im ) <EOL> except OSError : <EOL> image_size = "<STR_LIT>" <EOL> image_credit = issue . batch . awardee . name <EOL> host = request . get_host ( ) <EOL> profile_uri = '<STR_LIT>' <EOL> template = "<STR_LIT>" <EOL> page_topics = None <EOL> if page . topicpages_set . count ( ) : <EOL> page_topics = map ( lambda tp : { '<STR_LIT:name>' : tp . topic . name , '<STR_LIT:id>' : tp . topic . id } , <EOL> page . topicpages_set . all ( ) ) <EOL> related_pages = index . similar_pages ( page ) <EOL> response = render_to_response ( template , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def titles ( request , start = None , page_number = <NUM_LIT:1> ) : <EOL> page_title = '<STR_LIT>' <EOL> if start : <EOL> page_title += '<STR_LIT>' % start <EOL> titles = models . Title . objects . order_by ( '<STR_LIT>' ) <EOL> titles = titles . filter ( name_normal__istartswith = start . upper ( ) ) <EOL> else : <EOL> titles = models . Title . objects . all ( ) . order_by ( '<STR_LIT>' ) <EOL> paginator = Paginator ( titles , <NUM_LIT:50> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_start = page . start_index ( ) <EOL> page_end = page . end_index ( ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> browse_val = [ chr ( n ) for n in range ( <NUM_LIT> , <NUM_LIT> ) ] <EOL> browse_val . extend ( [ str ( i ) for i in range ( <NUM_LIT:10> ) ] ) <EOL> collapse_search_tab = True <EOL> crumbs = list ( settings . BASE_CRUMBS ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> page_title = "<STR_LIT>" % label ( title ) <EOL> page_name = "<STR_LIT:title>" <EOL> related_titles = title . related_titles ( ) <EOL> succeeding_titles = title . succeeding_titles ( ) <EOL> preceeding_titles = title . preceeding_titles ( ) <EOL> profile_uri = '<STR_LIT>' <EOL> notes = [ ] <EOL> has_external_link = False <EOL> for note in title . notes . all ( ) : <EOL> org_text = html . escape ( note . text ) <EOL> text = re . sub ( '<STR_LIT>' , <EOL> r'<STR_LIT>' , org_text ) <EOL> if text != org_text : <EOL> has_external_link = True <EOL> notes . append ( text ) <EOL> if title . has_issues : <EOL> rep_notes = title . first_issue . notes . filter ( type = "<STR_LIT>" ) <EOL> num_notes = rep_notes . count ( ) <EOL> if num_notes >= <NUM_LIT:1> : <EOL> explanation = rep_notes [ <NUM_LIT:0> ] . text <EOL> first_essay = title . first_essay <EOL> first_issue = title . first_issue <EOL> if first_issue : <EOL> issue_date = first_issue . date_issued <EOL> crumbs = create_crumbs ( title ) <EOL> response = render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def titles_in_city ( request , state , county , city , <EOL> page_number = <NUM_LIT:1> , order = '<STR_LIT>' ) : <EOL> state , county , city = map ( unpack_url_path , ( state , county , city ) ) <EOL> page_title = "<STR_LIT>" % ( city , state ) <EOL> titles = models . Title . objects . all ( ) <EOL> if city : <EOL> titles = titles . filter ( places__city__iexact = city ) <EOL> if county : <EOL> titles = titles . filter ( places__county__iexact = county ) <EOL> if state : <EOL> titles = titles . filter ( places__state__iexact = state ) <EOL> titles = titles . order_by ( order ) <EOL> titles . distinct ( ) <EOL> if titles . count ( ) == <NUM_LIT:0> : <EOL> raise Http404 <EOL> paginator = Paginator ( titles , <NUM_LIT:50> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def titles_in_county ( request , state , county , <EOL> page_number = <NUM_LIT:1> , order = '<STR_LIT>' ) : <EOL> state , county = map ( unpack_url_path , ( state , county ) ) <EOL> page_title = "<STR_LIT>" % ( county , state ) <EOL> titles = models . Title . objects . all ( ) <EOL> if county : <EOL> titles = titles . filter ( places__county__iexact = county ) <EOL> if state : <EOL> titles = titles . filter ( places__state__iexact = state ) <EOL> titles = titles . order_by ( order ) <EOL> titles = titles . distinct ( ) <EOL> if titles . count ( ) == <NUM_LIT:0> : <EOL> raise Http404 <EOL> paginator = Paginator ( titles , <NUM_LIT:50> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def titles_in_state ( request , state , page_number = <NUM_LIT:1> , order = '<STR_LIT>' ) : <EOL> state = unpack_url_path ( state ) <EOL> page_title = "<STR_LIT>" % state <EOL> titles = models . Title . objects . all ( ) <EOL> if state : <EOL> titles = titles . filter ( places__state__iexact = state ) <EOL> titles = titles . order_by ( order ) <EOL> titles = titles . distinct ( ) <EOL> if titles . count ( ) == <NUM_LIT:0> : <EOL> raise Http404 <EOL> paginator = Paginator ( titles , <NUM_LIT:50> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def title_essays ( request , lccn ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> if len ( title . essays . all ( ) ) >= <NUM_LIT:1> : <EOL> url = title . essays . all ( ) [ <NUM_LIT:0> ] . url <EOL> return HttpResponsePermanentRedirect ( url ) <EOL> else : <EOL> return HttpResponseNotFound ( ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def awardees ( request ) : <EOL> page_title = '<STR_LIT>' <EOL> awardees = models . Awardee . objects . all ( ) . order_by ( '<STR_LIT:name>' ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def awardee ( request , institution_code ) : <EOL> awardee = get_object_or_404 ( models . Awardee , org_code = institution_code ) <EOL> page_title = '<STR_LIT>' % awardee . name <EOL> batches = models . Batch . objects . filter ( awardee = awardee ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> def _search_engine_words ( request ) : <EOL> """<STR_LIT>""" <EOL> referer = request . META . get ( '<STR_LIT>' ) <EOL> if not referer : <EOL> return [ ] <EOL> uri = urlparse . urlparse ( referer ) <EOL> qs = urlparse . parse_qs ( uri . query ) <EOL> if '<STR_LIT:q>' in qs : <EOL> words = qs [ '<STR_LIT:q>' ] [ <NUM_LIT:0> ] <EOL> elif '<STR_LIT:p>' in qs : <EOL> words = qs [ '<STR_LIT:p>' ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return [ ] <EOL> words = words . split ( '<STR_LIT:U+0020>' ) <EOL> words = index . word_matches_for_page ( request . path , words ) <EOL> return words <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def page_ocr ( request , lccn , date , edition , sequence ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> page_title = "<STR_LIT>" % ( label ( title ) , label ( issue ) , label ( page ) ) <EOL> crumbs = create_crumbs ( title , issue , date , edition , page ) <EOL> host = request . get_host ( ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> def page_pdf ( request , lccn , date , edition , sequence ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> return _stream_file ( page . pdf_abs_filename , '<STR_LIT>' ) <EOL> def page_jp2 ( request , lccn , date , edition , sequence ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> return _stream_file ( page . jp2_abs_filename , '<STR_LIT>' ) <EOL> def page_ocr_xml ( request , lccn , date , edition , sequence ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> return _stream_file ( page . ocr_abs_filename , '<STR_LIT>' ) <EOL> def page_ocr_txt ( request , lccn , date , edition , sequence ) : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> try : <EOL> text = page . ocr . text <EOL> return HttpResponse ( text , mimetype = '<STR_LIT>' ) <EOL> except models . OCR . DoesNotExist : <EOL> raise Http404 ( "<STR_LIT>" % page ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> @ rdf_view <EOL> def page_rdf ( request , lccn , date , edition , sequence ) : <EOL> page = get_page ( lccn , date , edition , sequence ) <EOL> graph = page_to_graph ( page ) <EOL> response = HttpResponse ( graph . serialize ( base = _rdf_base ( request ) , <EOL> include_base = True ) , <EOL> mimetype = '<STR_LIT>' ) <EOL> return response <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def page_print ( request , lccn , date , edition , sequence , <EOL> width , height , x1 , y1 , x2 , y2 ) : <EOL> page = get_page ( lccn , date , edition , sequence ) <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> issue = page . issue <EOL> page_title = "<STR_LIT>" % ( label ( title ) , label ( issue ) , label ( page ) ) <EOL> crumbs = create_crumbs ( title , issue , date , edition , page ) <EOL> host = request . get_host ( ) <EOL> image_credit = page . issue . batch . awardee . name <EOL> path_parts = dict ( lccn = lccn , date = date , edition = edition , <EOL> sequence = sequence , <EOL> width = width , height = height , <EOL> x1 = x1 , y1 = y1 , x2 = x2 , y2 = y2 ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , <EOL> kwargs = path_parts ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def issues_first_pages ( request , lccn , page_number = <NUM_LIT:1> ) : <EOL> title = get_object_or_404 ( models . Title , lccn = lccn ) <EOL> issues = title . issues . all ( ) <EOL> if not issues . count ( ) > <NUM_LIT:0> : <EOL> raise Http404 ( "<STR_LIT>" % title . display_name ) <EOL> first_pages = [ ] <EOL> for issue in issues : <EOL> first_pages . append ( issue . first_page ) <EOL> paginator = Paginator ( first_pages , <NUM_LIT:20> ) <EOL> try : <EOL> page = paginator . page ( page_number ) <EOL> except InvalidPage : <EOL> page = paginator . page ( <NUM_LIT:1> ) <EOL> page_range_short = list ( _page_range_short ( paginator , page ) ) <EOL> page_title = '<STR_LIT>' % label ( title ) <EOL> page_head_heading = "<STR_LIT>" % title . display_name <EOL> page_head_subheading = label ( title ) <EOL> crumbs = create_crumbs ( title ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> def recommended_topics ( request ) : <EOL> sort_order = request . REQUEST . get ( '<STR_LIT>' , None ) <EOL> page_title = '<STR_LIT>' <EOL> crumbs = list ( settings . BASE_CRUMBS ) <EOL> crumbs . extend ( [ { '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : urlresolvers . reverse ( '<STR_LIT>' ) } ] ) <EOL> category_sort = False <EOL> topics = models . Topic . objects . all ( ) <EOL> if sort_order == '<STR_LIT:date>' : <EOL> topics = topics . order_by ( '<STR_LIT>' ) <EOL> elif sort_order == '<STR_LIT>' : <EOL> category_sort = True <EOL> topics = models . TopicCategory . objects . all ( ) <EOL> else : <EOL> topics = topics . order_by ( '<STR_LIT:name>' ) <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ cache_page ( settings . DEFAULT_TTL_SECONDS ) <EOL> @ vary_on_headers ( '<STR_LIT>' ) <EOL> def chronam_topic ( request , topic_id ) : <EOL> topic = get_object_or_404 ( models . Topic , pk = topic_id ) <EOL> page_title = topic . name <EOL> crumbs = list ( settings . BASE_CRUMBS ) <EOL> if urlresolvers . reverse ( '<STR_LIT>' ) in request . META . get ( '<STR_LIT>' ) : <EOL> crumbs . extend ( [ { '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : urlresolvers . reverse ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:label>' : topic . name , <EOL> '<STR_LIT>' : urlresolvers . reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : topic . pk } ) } ] ) <EOL> else : <EOL> referer = re . sub ( '<STR_LIT>' , '<STR_LIT>' , request . META . get ( '<STR_LIT>' ) ) . split ( '<STR_LIT:/>' ) <EOL> try : <EOL> lccn , date , edition , sequence = referer [ <NUM_LIT:2> ] , referer [ <NUM_LIT:3> ] , referer [ <NUM_LIT:4> ] [ - <NUM_LIT:1> ] , referer [ <NUM_LIT:5> ] [ - <NUM_LIT:1> ] <EOL> page = get_page ( lccn , date , edition , sequence ) <EOL> if page : <EOL> title , issue , page = _get_tip ( lccn , date , edition , sequence ) <EOL> crumbs = create_crumbs ( title , issue , date , edition , page ) <EOL> crumbs . extend ( [ { '<STR_LIT:label>' : topic . name , <EOL> '<STR_LIT>' : urlresolvers . reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : topic . pk } ) } ] ) <EOL> except : <EOL> pass <EOL> important_dates = filter ( lambda s : not s . isspace ( ) , topic . important_dates . split ( '<STR_LIT>' ) ) <EOL> search_suggestions = topic . suggested_search_terms . split ( '<STR_LIT:\t>' ) <EOL> chronam_pages = [ { '<STR_LIT:title>' : t . title , '<STR_LIT:description>' : t . description . lstrip ( t . title ) , <EOL> '<STR_LIT:url>' : t . url } for t in topic . topicpages_set . all ( ) ] <EOL> return render_to_response ( '<STR_LIT>' , dictionary = locals ( ) , <EOL> context_instance = RequestContext ( request ) ) </s>
