<s> from datetime import datetime , timedelta <EOL> from xml . sax . saxutils import escape <EOL> from django . core . paginator import Paginator , EmptyPage , InvalidPage <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . translation import get_language <EOL> from django . db . models import Q <EOL> from molly . utils . views import BaseView <EOL> from molly . utils . breadcrumbs import * <EOL> from . . models import Feed , Item <EOL> class IndexView ( BaseView ) : <EOL> def get_metadata ( self , request ) : <EOL> return { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> @ BreadcrumbFactory <EOL> def breadcrumb ( self , request , context ) : <EOL> return Breadcrumb ( <EOL> self . conf . local_name , None , _ ( '<STR_LIT>' ) , lazy_reverse ( '<STR_LIT:index>' ) <EOL> ) <EOL> def handle_GET ( self , request , context ) : <EOL> feeds = Feed . events . all ( ) <EOL> lang_code = get_language ( ) <EOL> if '<STR_LIT:->' in lang_code : <EOL> lang_code = lang_code . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> all_feeds = feeds . count ( ) <EOL> if '<STR_LIT:all>' not in request . GET : <EOL> feeds = feeds . filter ( <EOL> Q ( language__startswith = lang_code ) | Q ( language = None ) <EOL> ) <EOL> lang_feeds = feeds . count ( ) <EOL> context = { <EOL> '<STR_LIT>' : feeds , <EOL> '<STR_LIT>' : lang_feeds != all_feeds , <EOL> } <EOL> return self . render ( request , context , '<STR_LIT>' , <EOL> expires = timedelta ( days = <NUM_LIT:7> ) ) <EOL> class ItemListView ( BaseView ) : <EOL> def get_metadata ( self , request , slug ) : <EOL> feed = get_object_or_404 ( Feed . events , slug = slug ) <EOL> last_modified = feed . last_modified . strftime ( '<STR_LIT>' ) if feed . last_modified else _ ( '<STR_LIT>' ) <EOL> return { <EOL> '<STR_LIT>' : feed . last_modified , <EOL> '<STR_LIT:title>' : feed . title , <EOL> '<STR_LIT>' : '<STR_LIT>' % last_modified , <EOL> } <EOL> @ BreadcrumbFactory <EOL> def breadcrumb ( self , request , context , slug ) : <EOL> return Breadcrumb ( <EOL> self . conf . local_name , <EOL> lazy_parent ( '<STR_LIT:index>' ) , <EOL> _ ( '<STR_LIT>' ) , <EOL> lazy_reverse ( '<STR_LIT>' , args = [ slug ] ) <EOL> ) <EOL> def handle_GET ( self , request , context , slug ) : <EOL> feed = get_object_or_404 ( Feed . events , slug = slug ) <EOL> context [ '<STR_LIT>' ] = feed <EOL> context [ '<STR_LIT>' ] = feed . item_set . filter ( dt_start__gte = datetime . today ( ) ) . order_by ( '<STR_LIT>' ) <EOL> return self . render ( request , context , '<STR_LIT>' ) <EOL> class ItemDetailView ( BaseView ) : <EOL> def get_metadata ( self , request , slug , id ) : <EOL> item = get_object_or_404 ( Item , feed__slug = slug , id = id ) <EOL> last_modified = item . last_modified . strftime ( '<STR_LIT>' ) if item . last_modified else _ ( '<STR_LIT>' ) <EOL> return { <EOL> '<STR_LIT>' : item . last_modified , <EOL> '<STR_LIT:title>' : item . title , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( escape ( item . feed . title ) , last_modified ) , <EOL> '<STR_LIT>' : escape ( item . feed . title ) , <EOL> } <EOL> @ BreadcrumbFactory <EOL> def breadcrumb ( self , request , context , slug , id ) : <EOL> return Breadcrumb ( <EOL> self . conf . local_name , <EOL> lazy_parent ( '<STR_LIT>' , slug = slug ) , <EOL> _ ( '<STR_LIT>' ) , <EOL> lazy_reverse ( '<STR_LIT>' , args = [ slug , id ] ) <EOL> ) <EOL> def handle_GET ( self , request , context , slug , id ) : <EOL> item = get_object_or_404 ( Item , feed__slug = slug , id = id ) <EOL> context . update ( { <EOL> '<STR_LIT>' : item , <EOL> '<STR_LIT:description>' : item . get_description_display ( request . device ) <EOL> } ) <EOL> return self . render ( request , context , '<STR_LIT>' ) </s>
