<s> from cms . utils . urlutils import admin_reverse <EOL> from cms . api import get_page_draft <EOL> from cms . toolbar_base import CMSToolbar <EOL> from cms . utils import get_cms_setting , get_language_list <EOL> from cms . utils . permissions import has_page_change_permission <EOL> from django . core . urlresolvers import NoReverseMatch <EOL> class ExtensionToolbar ( CMSToolbar ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> page = None <EOL> def _setup_extension_toolbar ( self ) : <EOL> """<STR_LIT>""" <EOL> page = self . _get_page ( ) <EOL> if not page : <EOL> return <EOL> if get_cms_setting ( '<STR_LIT>' ) : <EOL> has_global_current_page_change_permission = has_page_change_permission ( self . request ) <EOL> else : <EOL> has_global_current_page_change_permission = True <EOL> can_change = ( self . request . current_page and <EOL> self . request . current_page . has_change_permission ( self . request ) ) <EOL> current_page_menu = self . toolbar . get_or_create_menu ( '<STR_LIT>' ) <EOL> if can_change and has_global_current_page_change_permission : <EOL> return current_page_menu <EOL> else : <EOL> return <EOL> def _get_page ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . page : <EOL> self . page = get_page_draft ( self . request . current_page ) <EOL> return self . page <EOL> def get_page_extension_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> page = self . _get_page ( ) <EOL> try : <EOL> page_extension = self . model . objects . get ( extended_object_id = page . pk ) <EOL> except self . model . DoesNotExist : <EOL> page_extension = None <EOL> try : <EOL> model_name = self . model . __name__ . lower ( ) <EOL> if page_extension : <EOL> admin_url = admin_reverse ( <EOL> '<STR_LIT>' % ( self . model . _meta . app_label , model_name ) , <EOL> args = ( page_extension . pk , ) ) <EOL> else : <EOL> admin_url = "<STR_LIT>" % ( <EOL> admin_reverse ( '<STR_LIT>' % ( self . model . _meta . app_label , model_name ) ) , <EOL> self . page . pk ) <EOL> except NoReverseMatch : <EOL> admin_url = None <EOL> return page_extension , admin_url <EOL> def get_title_extension_admin ( self , language = None ) : <EOL> """<STR_LIT>""" <EOL> page = self . _get_page ( ) <EOL> urls = [ ] <EOL> if language : <EOL> titles = page . get_title_obj ( language ) , <EOL> else : <EOL> titles = page . title_set . filter ( language__in = get_language_list ( page . site_id ) ) <EOL> for title in titles : <EOL> try : <EOL> title_extension = self . model . objects . get ( extended_object_id = title . pk ) <EOL> except self . model . DoesNotExist : <EOL> title_extension = None <EOL> try : <EOL> model_name = self . model . __name__ . lower ( ) <EOL> if title_extension : <EOL> admin_url = admin_reverse ( <EOL> '<STR_LIT>' % ( self . model . _meta . app_label , model_name ) , <EOL> args = ( title_extension . pk , ) ) <EOL> else : <EOL> admin_url = "<STR_LIT>" % ( <EOL> admin_reverse ( '<STR_LIT>' % ( self . model . _meta . app_label , model_name ) ) , <EOL> title . pk ) <EOL> except NoReverseMatch : <EOL> admin_url = None <EOL> if admin_url : <EOL> urls . append ( ( title_extension , admin_url ) ) <EOL> return urls <EOL> def _get_sub_menu ( self , current_menu , key , label , position = None ) : <EOL> """<STR_LIT>""" <EOL> extension_menu = current_menu . get_or_create_menu ( <EOL> key , label , position = position ) <EOL> return extension_menu </s>
