<s> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> SITE_CACHE = { } <EOL> class SiteManager ( models . Manager ) : <EOL> def get_current ( self ) : <EOL> """<STR_LIT>""" <EOL> from django . conf import settings <EOL> try : <EOL> sid = settings . SITE_ID <EOL> except AttributeError : <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> raise ImproperlyConfigured ( "<STR_LIT>" ) <EOL> try : <EOL> current_site = SITE_CACHE [ sid ] <EOL> except KeyError : <EOL> current_site = self . get ( pk = sid ) <EOL> SITE_CACHE [ sid ] = current_site <EOL> return current_site <EOL> def clear_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> global SITE_CACHE <EOL> SITE_CACHE = { } <EOL> @ python_2_unicode_compatible <EOL> class Site ( models . Model ) : <EOL> domain = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:100> ) <EOL> name = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:50> ) <EOL> objects = SiteManager ( ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT>' , ) <EOL> def __str__ ( self ) : <EOL> return self . domain <EOL> def save ( self , * args , ** kwargs ) : <EOL> super ( Site , self ) . save ( * args , ** kwargs ) <EOL> if self . id in SITE_CACHE : <EOL> del SITE_CACHE [ self . id ] <EOL> def delete ( self ) : <EOL> pk = self . pk <EOL> super ( Site , self ) . delete ( ) <EOL> try : <EOL> del SITE_CACHE [ pk ] <EOL> except KeyError : <EOL> pass <EOL> @ python_2_unicode_compatible <EOL> class RequestSite ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , request ) : <EOL> self . domain = self . name = request . get_host ( ) <EOL> def __str__ ( self ) : <EOL> return self . domain <EOL> def save ( self , force_insert = False , force_update = False ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def delete ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def get_current_site ( request ) : <EOL> """<STR_LIT>""" <EOL> if Site . _meta . installed : <EOL> current_site = Site . objects . get_current ( ) <EOL> else : <EOL> current_site = RequestSite ( request ) <EOL> return current_site </s>
