<s> from django . contrib . flatpages . models import FlatPage <EOL> from django . http import Http404 <EOL> from . breadcrumbs import Breadcrumbs , BreadcrumbsNotSet <EOL> from django . conf import settings <EOL> from django . core . cache import cache <EOL> def make_flatpages_cache_key ( ) : <EOL> """<STR_LIT>""" <EOL> key = "<STR_LIT>" % ( hash ( settings . SITE_ID ) , <EOL> hash ( settings . SECRET_KEY ) ) <EOL> return key <EOL> def get_flapage_from_cache ( url ) : <EOL> """<STR_LIT>""" <EOL> site_id = settings . SITE_ID <EOL> cache_key = make_flatpages_cache_key ( ) <EOL> flatpages = cache . get ( cache_key ) <EOL> if flatpages and url in flatpages : <EOL> return flatpages [ url ] <EOL> flatpages = dict ( [ ( f . url , f ) for f in <EOL> FlatPage . objects . filter ( sites__id__exact = site_id ) . order_by ( '<STR_LIT:url>' ) ] ) <EOL> if url not in flatpages : <EOL> raise Http404 <EOL> cache . delete ( cache_key ) <EOL> cache . add ( cache_key , flatpages ) <EOL> return flatpages [ url ] <EOL> def breadcrumbs_for_flatpages ( request , flatpage ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( request , '<STR_LIT>' ) or not isinstance ( request . breadcrumbs , Breadcrumbs ) : <EOL> raise BreadcrumbsNotSet ( u"<STR_LIT>" <EOL> u"<STR_LIT>" ) <EOL> if not isinstance ( flatpage , FlatPage ) or not hasattr ( flatpage , '<STR_LIT:id>' ) : <EOL> raise TypeError ( u"<STR_LIT>" <EOL> u"<STR_LIT>" ) <EOL> paths = [ ] <EOL> for part in request . path_info . split ( u"<STR_LIT:/>" ) : <EOL> if len ( part ) == <NUM_LIT:0> : <EOL> continue <EOL> if not part . startswith ( u"<STR_LIT:/>" ) : <EOL> part = u"<STR_LIT:/>" + part <EOL> if not part . endswith ( u"<STR_LIT:/>" ) : <EOL> part = part + u"<STR_LIT:/>" <EOL> if len ( paths ) > <NUM_LIT:0> : <EOL> url = u"<STR_LIT>" . join ( paths + [ part ] ) <EOL> else : <EOL> url = part <EOL> if url == flatpage . url : <EOL> request . breadcrumbs ( flatpage . title , flatpage . url ) <EOL> else : <EOL> try : <EOL> f = FlatPage . objects . get ( url = url , sites = settings . SITE_ID ) <EOL> except FlatPage . DoesNotExist : <EOL> continue <EOL> else : <EOL> request . breadcrumbs ( f . title , f . url ) <EOL> paths . append ( u"<STR_LIT:/>" + url [ <NUM_LIT:1> : - <NUM_LIT:1> ] . rpartition ( u"<STR_LIT:/>" ) [ - <NUM_LIT:1> ] ) </s>
