#NEWLINE# def update_site_and_page_choices( lang = None ) : #NEWLINE# #INDENT# lang = ( lang or i18n . get_current_language ( ) ) #NEWLINE# SITE_CHOICES_KEY = _site_cache_key ( lang ) #NEWLINE# PAGE_CHOICES_KEY = _page_cache_key ( lang ) #NEWLINE# title_queryset = Title . objects . drafts ( ) . select_related ( 'page' , 'page__site' ) . order_by ( 'page__path' ) #NEWLINE# pages = defaultdict ( OrderedDict ) #NEWLINE# sites = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for title in title_queryset : #NEWLINE# #INDENT# page = pages [ title . page . site . pk ] . get ( title . page . pk , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# page [ title . language ] = title #NEWLINE# pages [ title . page . site . pk ] [ title . page . pk ] = page #NEWLINE# sites [ title . page . site . pk ] = title . page . site . name #NEWLINE# #UNINDENT# site_choices = [ ] #NEWLINE# page_choices = [ ( '' , '----' ) ] #NEWLINE# try : #NEWLINE# #INDENT# fallbacks = i18n . get_fallback_languages ( lang ) #NEWLINE# #UNINDENT# except LanguageError : #NEWLINE# #INDENT# fallbacks = [ ] #NEWLINE# #UNINDENT# language_order = ( [ lang ] + titles ) #NEWLINE# for ( sitepk , sitename ) in sites . items ( ) : #NEWLINE# #INDENT# site_choices . append ( ( sitepk , sitename ) ) #NEWLINE# site_page_choices = [ ] #NEWLINE# for titles in pages [ sitepk ] . values ( ) : #NEWLINE# #INDENT# title = None #NEWLINE# for language in language_order : #NEWLINE# #INDENT# title = titles . get ( language ) #NEWLINE# if title : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not title ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# indent = ( '&nbsp;&nbsp;' * ( title . page . depth - 1 ) ) #NEWLINE# page_title = mark_safe ( ( '%s%s' % ( indent , escape ( title . title ) ) ) ) #NEWLINE# site_page_choices . append ( ( title . page . pk , page_title ) ) #NEWLINE# #UNINDENT# page_choices . append ( ( sitename , site_page_choices ) ) #NEWLINE# #UNINDENT# from django.core.cache import cache #NEWLINE# cache . set ( SITE_CHOICES_KEY , site_choices , 86400 ) #NEWLINE# cache . set ( PAGE_CHOICES_KEY , page_choices , 86400 ) #NEWLINE# return ( site_choices , page_choices )