<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . conf . urls import include , url <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . admin . sites import ( AdminSite , site as default_site , <EOL> NotRegistered , AlreadyRegistered ) <EOL> from django . shortcuts import redirect <EOL> from mezzanine . utils . importing import import_dotted_path <EOL> class LazyAdminSite ( AdminSite ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _deferred = [ ] <EOL> super ( LazyAdminSite , self ) . __init__ ( * args , ** kwargs ) <EOL> def register ( self , * args , ** kwargs ) : <EOL> for name , deferred_args , deferred_kwargs in self . _deferred : <EOL> if name == "<STR_LIT>" and deferred_args [ <NUM_LIT:0> ] == args [ <NUM_LIT:0> ] : <EOL> self . _deferred . append ( ( "<STR_LIT>" , args , kwargs ) ) <EOL> break <EOL> else : <EOL> super ( LazyAdminSite , self ) . register ( * args , ** kwargs ) <EOL> def unregister ( self , * args , ** kwargs ) : <EOL> self . _deferred . append ( ( "<STR_LIT>" , args , kwargs ) ) <EOL> def lazy_registration ( self ) : <EOL> for model in getattr ( settings , "<STR_LIT>" , [ ] ) : <EOL> try : <EOL> model = tuple ( model . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) ) <EOL> exec ( "<STR_LIT>" % model ) <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> try : <EOL> AdminSite . unregister ( self , eval ( model [ <NUM_LIT:1> ] ) ) <EOL> except NotRegistered : <EOL> pass <EOL> for model , admin in default_site . _registry . items ( ) : <EOL> self . _deferred . append ( ( "<STR_LIT>" , ( model , admin . __class__ ) , { } ) ) <EOL> for name , args , kwargs in self . _deferred : <EOL> try : <EOL> getattr ( AdminSite , name ) ( self , * args , ** kwargs ) <EOL> except ( AlreadyRegistered , NotRegistered ) : <EOL> pass <EOL> @ property <EOL> def urls ( self ) : <EOL> urls = [ url ( "<STR_LIT>" , super ( LazyAdminSite , self ) . urls ) ] <EOL> fb_name = getattr ( settings , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if fb_name in settings . INSTALLED_APPS : <EOL> try : <EOL> fb_urls = import_dotted_path ( "<STR_LIT>" % fb_name ) . urls <EOL> except ImportError : <EOL> fb_urls = "<STR_LIT>" % fb_name <EOL> urls = [ <EOL> url ( "<STR_LIT>" , lambda r : redirect ( "<STR_LIT>" ) , <EOL> name = "<STR_LIT>" ) , <EOL> url ( "<STR_LIT>" , include ( fb_urls ) ) , <EOL> ] + urls <EOL> User = get_user_model ( ) <EOL> for admin in self . _registry . values ( ) : <EOL> user_change_password = getattr ( admin , "<STR_LIT>" , None ) <EOL> if user_change_password : <EOL> bits = ( User . _meta . app_label , User . _meta . object_name . lower ( ) ) <EOL> urls = [ <EOL> url ( "<STR_LIT>" % bits , <EOL> self . admin_view ( user_change_password ) , <EOL> name = "<STR_LIT>" ) , <EOL> ] + urls <EOL> break <EOL> from mezzanine . core . views import displayable_links_js , static_proxy <EOL> from mezzanine . generic . views import admin_keywords_submit <EOL> urls += [ <EOL> url ( "<STR_LIT>" , admin_keywords_submit , <EOL> name = "<STR_LIT>" ) , <EOL> url ( "<STR_LIT>" , static_proxy , name = "<STR_LIT>" ) , <EOL> url ( "<STR_LIT>" , displayable_links_js , <EOL> name = "<STR_LIT>" ) , <EOL> ] <EOL> if "<STR_LIT>" in settings . INSTALLED_APPS : <EOL> from mezzanine . pages . views import admin_page_ordering <EOL> urls . append ( url ( "<STR_LIT>" , admin_page_ordering , <EOL> name = "<STR_LIT>" ) ) <EOL> return urls </s>
