<s> import re <EOL> from django . contrib . sites . models import SITE_CACHE , Site <EOL> from . compat . dj import is_installed <EOL> SITE_VAR = "<STR_LIT>" <EOL> def reversion_register ( model_class , fields = None , follow = ( ) , format = "<STR_LIT>" , exclude_fields = None ) : <EOL> """<STR_LIT>""" <EOL> if not is_installed ( '<STR_LIT>' ) : <EOL> return <EOL> if fields and exclude_fields : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> opts = model_class . _meta <EOL> local_fields = opts . local_fields + opts . local_many_to_many <EOL> if fields is None : <EOL> fields = [ field . name for field in local_fields ] <EOL> exclude_fields = exclude_fields or [ ] <EOL> fields = filter ( lambda name : not name in exclude_fields , fields ) <EOL> from cms . utils import reversion_hacks <EOL> reversion_hacks . register_draft_only ( model_class , fields , follow , format ) <EOL> def make_revision_with_plugins ( obj , user = None , message = None ) : <EOL> """<STR_LIT>""" <EOL> from cms . models . pluginmodel import CMSPlugin <EOL> from cms . utils . reversion_hacks import revision_context , revision_manager <EOL> cls = obj . __class__ <EOL> if hasattr ( revision_manager , '<STR_LIT>' ) : <EOL> model_key = revision_manager . _registration_key_for_model ( cls ) <EOL> else : <EOL> model_key = cls <EOL> if model_key in revision_manager . _registered_models : <EOL> placeholder_relation = find_placeholder_relation ( obj ) <EOL> if revision_context . is_active ( ) : <EOL> if user : <EOL> revision_context . set_user ( user ) <EOL> if message : <EOL> revision_context . set_comment ( message ) <EOL> adapter = revision_manager . get_adapter ( obj . __class__ ) <EOL> revision_context . add_to_context ( revision_manager , obj , adapter . get_version_data ( obj ) ) <EOL> for ph in obj . get_placeholders ( ) : <EOL> phadapter = revision_manager . get_adapter ( ph . __class__ ) <EOL> revision_context . add_to_context ( revision_manager , ph , phadapter . get_version_data ( ph ) ) <EOL> filters = { '<STR_LIT>' % placeholder_relation : obj } <EOL> for plugin in CMSPlugin . objects . filter ( ** filters ) : <EOL> plugin_instance , admin = plugin . get_plugin_instance ( ) <EOL> if plugin_instance : <EOL> padapter = revision_manager . get_adapter ( plugin_instance . __class__ ) <EOL> revision_context . add_to_context ( revision_manager , plugin_instance , padapter . get_version_data ( plugin_instance ) ) <EOL> bpadapter = revision_manager . get_adapter ( plugin . __class__ ) <EOL> revision_context . add_to_context ( revision_manager , plugin , bpadapter . get_version_data ( plugin ) ) <EOL> def find_placeholder_relation ( obj ) : <EOL> return '<STR_LIT>' <EOL> class classproperty ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fget ) : <EOL> self . fget = fget <EOL> def __get__ ( self , owner_self , owner_cls ) : <EOL> return self . fget ( owner_cls ) <EOL> def current_site ( request ) : <EOL> site_pk = request . GET . get ( SITE_VAR , None ) if request . GET . get ( SITE_VAR , None ) else request . POST . get ( SITE_VAR , None ) <EOL> if not site_pk : <EOL> site_pk = request . session . get ( '<STR_LIT>' , None ) <EOL> if site_pk : <EOL> try : <EOL> site = SITE_CACHE . get ( site_pk ) or Site . objects . get ( pk = site_pk ) <EOL> SITE_CACHE [ site_pk ] = site <EOL> return site <EOL> except Site . DoesNotExist : <EOL> return None <EOL> else : <EOL> return Site . objects . get_current ( ) <EOL> def normalize_name ( name ) : <EOL> """<STR_LIT>""" <EOL> new = re . sub ( '<STR_LIT>' , '<STR_LIT>' , name ) <EOL> return new . lower ( ) . strip ( '<STR_LIT:_>' ) </s>
