#NEWLINE# def details( request , slug ) : #NEWLINE# #INDENT# '\n    The main view of the Django-CMS! Takes a request and a slug, renders the\n    page.\n    ' #NEWLINE# response_timestamp = now ( ) #NEWLINE# if ( get_cms_setting ( 'PAGE_CACHE' ) and ( ( not hasattr ( request , 'toolbar' ) ) or ( ( not request . toolbar . edit_mode ) and ( not request . toolbar . show_toolbar ) and ( not request . user . is_authenticated ( ) ) ) ) ) : #NEWLINE# #INDENT# cache_content = get_page_cache ( request ) #NEWLINE# if ( cache_content is not None ) : #NEWLINE# #INDENT# ( content , headers , expires_datetime ) = cache_content #NEWLINE# response = HttpResponse ( content ) #NEWLINE# response . _headers = headers #NEWLINE# max_age = int ( ( ( expires_datetime - response_timestamp ) . total_seconds ( ) + 0.5 ) ) #NEWLINE# patch_cache_control ( response , max_age = max_age ) #NEWLINE# return response #NEWLINE# #UNINDENT# #UNINDENT# page = get_page_from_request ( request , use_path = slug ) #NEWLINE# if ( not page ) : #NEWLINE# #INDENT# return _handle_no_page ( request , slug ) #NEWLINE# #UNINDENT# current_language = request . GET . get ( 'language' , None ) #NEWLINE# if ( not current_language ) : #NEWLINE# #INDENT# current_language = request . POST . get ( 'language' , None ) #NEWLINE# #UNINDENT# if current_language : #NEWLINE# #INDENT# current_language = get_language_code ( current_language ) #NEWLINE# if ( current_language not in get_language_list ( page . site_id ) ) : #NEWLINE# #INDENT# current_language = None #NEWLINE# #UNINDENT# #UNINDENT# if ( current_language is None ) : #NEWLINE# #INDENT# current_language = get_language_code ( getattr ( request , 'LANGUAGE_CODE' , None ) ) #NEWLINE# if current_language : #NEWLINE# #INDENT# current_language = get_language_code ( current_language ) #NEWLINE# if ( current_language not in get_language_list ( page . site_id ) ) : #NEWLINE# #INDENT# current_language = None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( current_language is None ) : #NEWLINE# #INDENT# current_language = get_language_code ( get_language ( ) ) #NEWLINE# #UNINDENT# available_languages = [ ] #NEWLINE# page_languages = list ( page . get_published_languages ( ) ) #NEWLINE# if ( hasattr ( request , 'user' ) and request . user . is_staff ) : #NEWLINE# #INDENT# user_languages = get_language_list ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user_languages = get_public_languages ( ) #NEWLINE# #UNINDENT# for frontend_lang in user_languages : #NEWLINE# #INDENT# if ( frontend_lang in page_languages ) : #NEWLINE# #INDENT# available_languages . append ( frontend_lang ) #NEWLINE# #UNINDENT# #UNINDENT# own_urls = [ ( 'http%s://%s%s' % ( ( 's' if request . is_secure ( ) else '' ) , request . get_host ( ) , request . path ) ) , ( '/%s' % request . path ) , request . path ] #NEWLINE# if ( current_language not in user_languages ) : #NEWLINE# #INDENT# if ( not slug ) : #NEWLINE# #INDENT# languages = [ ] #NEWLINE# for language in available_languages : #NEWLINE# #INDENT# languages . append ( ( language , language ) ) #NEWLINE# #UNINDENT# if languages : #NEWLINE# #INDENT# new_language = get_language_from_request ( request ) #NEWLINE# if ( new_language in get_public_languages ( ) ) : #NEWLINE# #INDENT# with force_language ( new_language ) : #NEWLINE# #INDENT# pages_root = reverse ( 'pages-root' ) #NEWLINE# if ( hasattr ( request , 'toolbar' ) and request . user . is_staff and request . toolbar . edit_mode ) : #NEWLINE# #INDENT# request . toolbar . redirect_url = pages_root #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( pages_root not in own_urls ) : #NEWLINE# #INDENT# return HttpResponseRedirect ( pages_root ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not hasattr ( request , 'toolbar' ) ) or ( not request . toolbar . redirect_url ) ) : #NEWLINE# #INDENT# _handle_no_page ( request , slug ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return _handle_no_page ( request , slug ) #NEWLINE# #UNINDENT# #UNINDENT# if ( current_language not in available_languages ) : #NEWLINE# #INDENT# found = False #NEWLINE# for alt_lang in get_fallback_languages ( current_language ) : #NEWLINE# #INDENT# if ( alt_lang in available_languages ) : #NEWLINE# #INDENT# if ( get_redirect_on_fallback ( current_language ) or ( slug == '' ) ) : #NEWLINE# #INDENT# with force_language ( alt_lang ) : #NEWLINE# #INDENT# path = page . get_absolute_url ( language = alt_lang , fallback = True ) #NEWLINE# #UNINDENT# if ( hasattr ( request , 'toolbar' ) and request . user . is_staff and request . toolbar . edit_mode ) : #NEWLINE# #INDENT# request . toolbar . redirect_url = path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( path not in own_urls ) : #NEWLINE# #INDENT# return HttpResponseRedirect ( path ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# found = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( not found ) and ( ( not hasattr ( request , 'toolbar' ) ) or ( not request . toolbar . redirect_url ) ) ) : #NEWLINE# #INDENT# _handle_no_page ( request , slug ) #NEWLINE# #UNINDENT# #UNINDENT# if apphook_pool . get_apphooks ( ) : #NEWLINE# #INDENT# app_urls = page . get_application_urls ( current_language , False ) #NEWLINE# skip_app = False #NEWLINE# if ( ( not page . is_published ( current_language ) ) and hasattr ( request , 'toolbar' ) and request . toolbar . edit_mode ) : #NEWLINE# #INDENT# skip_app = True #NEWLINE# #UNINDENT# if ( app_urls and ( not skip_app ) ) : #NEWLINE# #INDENT# app = apphook_pool . get_apphook ( app_urls ) #NEWLINE# pattern_list = [ ] #NEWLINE# for urlpatterns in get_app_urls ( app . urls ) : #NEWLINE# #INDENT# pattern_list += urlpatterns #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( view , args , kwargs ) = resolve ( '/' , tuple ( pattern_list ) ) #NEWLINE# return view ( request , * args , ** kwargs ) #NEWLINE# #UNINDENT# except Resolver404 : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# redirect_url = page . get_redirect ( language = current_language ) #NEWLINE# if redirect_url : #NEWLINE# #INDENT# if ( is_language_prefix_patterns_used ( ) and ( redirect_url [ 0 ] == '/' ) and ( not redirect_url . startswith ( ( '/%s/' % current_language ) ) ) ) : #NEWLINE# #INDENT# redirect_url = ( '/%s/%s' % ( current_language , redirect_url . lstrip ( '/' ) ) ) #NEWLINE# #UNINDENT# if ( hasattr ( request , 'toolbar' ) and request . user . is_staff and request . toolbar . edit_mode ) : #NEWLINE# #INDENT# request . toolbar . redirect_url = redirect_url #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( redirect_url not in own_urls ) : #NEWLINE# #INDENT# return HttpResponseRedirect ( redirect_url ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( page . login_required and ( not request . user . is_authenticated ( ) ) ) : #NEWLINE# #INDENT# return redirect_to_login ( urlquote ( request . get_full_path ( ) ) , settings . LOGIN_URL ) #NEWLINE# #UNINDENT# if hasattr ( request , 'toolbar' ) : #NEWLINE# #INDENT# request . toolbar . set_object ( page ) #NEWLINE# #UNINDENT# response = render_page ( request , page , current_language = alt_lang , slug = slug ) #NEWLINE# return response