<s> from django . apps import apps <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import Group , UserManager <EOL> from django . contrib . sites . models import Site <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils . encoding import force_text , python_2_unicode_compatible <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from cms . models import Page <EOL> from cms . models . managers import ( PagePermissionManager , <EOL> GlobalPagePermissionManager ) <EOL> from cms . utils . helpers import reversion_register <EOL> user_app_name , user_model_name = settings . AUTH_USER_MODEL . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> User = None <EOL> try : <EOL> User = apps . get_registered_model ( user_app_name , user_model_name ) <EOL> except KeyError : <EOL> pass <EOL> if User is None : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( settings . AUTH_USER_MODEL , user_app_name ) <EOL> ) <EOL> ACCESS_PAGE = <NUM_LIT:1> <EOL> ACCESS_CHILDREN = <NUM_LIT:2> <EOL> ACCESS_PAGE_AND_CHILDREN = <NUM_LIT:3> <EOL> ACCESS_DESCENDANTS = <NUM_LIT:4> <EOL> ACCESS_PAGE_AND_DESCENDANTS = <NUM_LIT:5> <EOL> MASK_PAGE = <NUM_LIT:1> <EOL> MASK_CHILDREN = <NUM_LIT:2> <EOL> MASK_DESCENDANTS = <NUM_LIT:4> <EOL> ACCESS_CHOICES = ( <EOL> ( ACCESS_PAGE , _ ( '<STR_LIT>' ) ) , <EOL> ( ACCESS_CHILDREN , _ ( '<STR_LIT>' ) ) , <EOL> ( ACCESS_PAGE_AND_CHILDREN , _ ( '<STR_LIT>' ) ) , <EOL> ( ACCESS_DESCENDANTS , _ ( '<STR_LIT>' ) ) , <EOL> ( ACCESS_PAGE_AND_DESCENDANTS , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> class AbstractPagePermission ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , verbose_name = _ ( "<STR_LIT:user>" ) , blank = True , null = True ) <EOL> group = models . ForeignKey ( Group , verbose_name = _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> can_change = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> can_add = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> can_delete = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> can_change_advanced_settings = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> can_publish = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> can_change_permissions = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False , help_text = _ ( "<STR_LIT>" ) ) <EOL> can_move_page = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True ) <EOL> can_view = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False , help_text = _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> abstract = True <EOL> app_label = '<STR_LIT>' <EOL> @ property <EOL> def audience ( self ) : <EOL> """<STR_LIT>""" <EOL> targets = filter ( lambda item : item , ( self . user , self . group , ) ) <EOL> return "<STR_LIT:U+002CU+0020>" . join ( [ force_text ( t ) for t in targets ] ) or '<STR_LIT>' <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . user and not self . group : <EOL> return <EOL> return super ( AbstractPagePermission , self ) . save ( * args , ** kwargs ) <EOL> @ python_2_unicode_compatible <EOL> class GlobalPagePermission ( AbstractPagePermission ) : <EOL> """<STR_LIT>""" <EOL> can_recover_page = models . BooleanField ( _ ( "<STR_LIT>" ) , default = True , help_text = _ ( "<STR_LIT>" ) ) <EOL> sites = models . ManyToManyField ( Site , blank = True , help_text = _ ( '<STR_LIT>' ) , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> objects = GlobalPagePermissionManager ( ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> app_label = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . audience <EOL> @ python_2_unicode_compatible <EOL> class PagePermission ( AbstractPagePermission ) : <EOL> """<STR_LIT>""" <EOL> grant_on = models . IntegerField ( _ ( "<STR_LIT>" ) , choices = ACCESS_CHOICES , default = ACCESS_PAGE_AND_DESCENDANTS ) <EOL> page = models . ForeignKey ( Page , null = True , blank = True , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> objects = PagePermissionManager ( ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> app_label = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> page = self . page_id and force_text ( self . page ) or "<STR_LIT:None>" <EOL> return "<STR_LIT>" % ( page , self . audience , force_text ( dict ( ACCESS_CHOICES ) [ self . grant_on ] ) ) <EOL> class PageUserManager ( UserManager ) : <EOL> use_in_migrations = False <EOL> class PageUser ( User ) : <EOL> """<STR_LIT>""" <EOL> created_by = models . ForeignKey ( settings . AUTH_USER_MODEL , related_name = "<STR_LIT>" ) <EOL> objects = PageUserManager ( ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> app_label = '<STR_LIT>' <EOL> class PageUserGroup ( Group ) : <EOL> """<STR_LIT>""" <EOL> created_by = models . ForeignKey ( settings . AUTH_USER_MODEL , related_name = "<STR_LIT>" ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> app_label = '<STR_LIT>' <EOL> reversion_register ( PagePermission ) </s>
