<s> from django . conf import settings <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ugettext_noop , ugettext <EOL> from django . dispatch import receiver <EOL> from zorna . acl . models import get_acl_for_model , get_acl_by_object <EOL> from zorna . models import ZornaEntity <EOL> from zorna . site . signals import site_options_called <EOL> from zorna . account . models import UserGroup <EOL> class SiteAlert ( ZornaEntity ) : <EOL> text = models . TextField ( _ ( '<STR_LIT>' ) ) <EOL> start = models . DateTimeField ( _ ( '<STR_LIT>' ) ) <EOL> end = models . DateTimeField ( _ ( '<STR_LIT>' ) ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:start>' ] <EOL> db_table = settings . TABLE_PREFIX + "<STR_LIT>" <EOL> def __unicode__ ( self ) : <EOL> return self . text <EOL> def get_acl_permissions ( ) : <EOL> return { <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> } <EOL> get_acl_permissions = staticmethod ( get_acl_permissions ) <EOL> REGISTRATION_EMAIL_VALIDATION = <NUM_LIT:0> <EOL> REGISTRATION_ADMIN_VALIDATION = <NUM_LIT:1> <EOL> REGISTRATION_NO_VALIDATION = <NUM_LIT:2> <EOL> REGISTRATION_VALIDATION_TYPES = ( <EOL> ( REGISTRATION_EMAIL_VALIDATION , _ ( <EOL> '<STR_LIT>' ) ) , <EOL> ( REGISTRATION_ADMIN_VALIDATION , _ ( <EOL> '<STR_LIT>' ) ) , <EOL> ( REGISTRATION_NO_VALIDATION , _ ( <EOL> '<STR_LIT>' ) ) , <EOL> ) <EOL> class SiteRegistration ( ZornaEntity ) : <EOL> allow_registration = models . BooleanField ( <EOL> _ ( '<STR_LIT>' ) , default = False , editable = True , <EOL> help_text = _ ( '<STR_LIT>' ) ) <EOL> validation_type = models . IntegerField ( _ ( <EOL> '<STR_LIT>' ) , max_length = <NUM_LIT:1> , choices = REGISTRATION_VALIDATION_TYPES , default = <NUM_LIT:0> ) <EOL> groups = models . ManyToManyField ( UserGroup , verbose_name = _ ( <EOL> '<STR_LIT>' ) , blank = True , editable = False ) <EOL> class Meta : <EOL> db_table = settings . TABLE_PREFIX + "<STR_LIT>" <EOL> def __unicode__ ( self ) : <EOL> return self . text <EOL> class SiteOptionsManager ( models . Manager ) : <EOL> def is_access_valid ( self , user , key_option ) : <EOL> try : <EOL> so = self . get ( key = key_option ) <EOL> if so : <EOL> check = get_acl_for_model ( SiteOptions ) <EOL> return check . access_siteoptions ( so , user ) <EOL> else : <EOL> return False <EOL> except Exception as e : <EOL> return False <EOL> def get_authorized_user ( self , key_option ) : <EOL> try : <EOL> so = self . get ( key = key_option ) <EOL> if so : <EOL> return get_acl_by_object ( so , '<STR_LIT>' ) <EOL> else : <EOL> return [ ] <EOL> except Exception as e : <EOL> return [ ] <EOL> def get_ckeditor_config ( self , request ) : <EOL> baccess = self . is_access_valid ( request . user , '<STR_LIT>' ) <EOL> if baccess : <EOL> return '<STR_LIT:default>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> class SiteOptions ( ZornaEntity ) : <EOL> option = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:255> ) <EOL> key = models . CharField ( _ ( '<STR_LIT:key>' ) , max_length = <NUM_LIT:255> , unique = True ) <EOL> objects = SiteOptionsManager ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:key>' ] <EOL> db_table = settings . TABLE_PREFIX + "<STR_LIT>" <EOL> def __unicode__ ( self ) : <EOL> return ugettext ( self . option ) <EOL> def get_acl_permissions ( ) : <EOL> return { <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> } <EOL> get_acl_permissions = staticmethod ( get_acl_permissions ) <EOL> SITES_OPTIONS = { <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : ugettext_noop ( u'<STR_LIT>' ) , <EOL> } <EOL> @ receiver ( site_options_called , sender = None ) <EOL> def handler_views_was_called ( ** kwargs ) : <EOL> options = { } <EOL> opts = SiteOptions . objects . filter ( key__startswith = '<STR_LIT>' ) <EOL> for opt in opts : <EOL> options [ opt . key ] = opt <EOL> for k , o in SITES_OPTIONS . iteritems ( ) : <EOL> if k in options : <EOL> if options [ k ] . option != o : <EOL> options [ k ] . option = o <EOL> options [ k ] . save ( ) <EOL> del options [ k ] <EOL> else : <EOL> opt = SiteOptions ( option = o , key = k ) <EOL> opt . save ( ) <EOL> if len ( options ) : <EOL> SiteOptions . objects . filter ( pk__in = [ <EOL> opt . pk for opt in options . values ( ) ] ) . delete ( ) </s>
