<s> from django . contrib . sites . models import Site <EOL> from django . conf import settings <EOL> class DynamicSiteMiddleware ( object ) : <EOL> def hosting_parse ( self , hosting ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT::>' in hosting : <EOL> return hosting . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> return hosting , None <EOL> def get_hosting ( self , hosting ) : <EOL> domain , port = self . hosting_parse ( hosting ) <EOL> if domain in settings . OPPS_DEFAULT_URLS : <EOL> domain = '<STR_LIT>' <EOL> try : <EOL> return Site . objects . get ( domain = domain ) <EOL> except Site . DoesNotExist : <EOL> return Site . objects . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:0> ] <EOL> def process_request ( self , request ) : <EOL> hosting = request . get_host ( ) . lower ( ) <EOL> site = self . get_hosting ( hosting ) <EOL> request . site = site <EOL> settings . SITE_ID = site . id <EOL> settings . CACHE_MIDDLEWARE_KEY_PREFIX = "<STR_LIT>" . format ( site . id ) </s>
