<s> """<STR_LIT>""" <EOL> from django . db . models import get_models , signals <EOL> from django . contrib . auth import models as auth_app <EOL> def _get_permission_codename ( action , opts ) : <EOL> return u'<STR_LIT>' % ( action , opts . object_name . lower ( ) ) <EOL> def _get_all_permissions ( opts ) : <EOL> "<STR_LIT>" <EOL> perms = [ ] <EOL> for action in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> perms . append ( ( _get_permission_codename ( action , opts ) , u'<STR_LIT>' % ( action , opts . verbose_name_raw ) ) ) <EOL> return perms + list ( opts . permissions ) <EOL> def create_permissions ( app , created_models , verbosity , ** kwargs ) : <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . auth . models import Permission <EOL> app_models = get_models ( app ) <EOL> if not app_models : <EOL> return <EOL> for klass in app_models : <EOL> ctype = ContentType . objects . get_for_model ( klass ) <EOL> for codename , name in _get_all_permissions ( klass . _meta ) : <EOL> p , created = Permission . objects . get_or_create ( codename = codename , content_type__pk = ctype . id , <EOL> defaults = { '<STR_LIT:name>' : name , '<STR_LIT>' : ctype } ) <EOL> if created and verbosity >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" % p <EOL> def create_superuser ( app , created_models , verbosity , ** kwargs ) : <EOL> from django . contrib . auth . models import User <EOL> from django . core . management import call_command <EOL> if User in created_models and kwargs . get ( '<STR_LIT>' , True ) : <EOL> msg = "<STR_LIT>" "<STR_LIT>" <EOL> confirm = raw_input ( msg ) <EOL> while <NUM_LIT:1> : <EOL> if confirm not in ( '<STR_LIT:yes>' , '<STR_LIT>' ) : <EOL> confirm = raw_input ( '<STR_LIT>' ) <EOL> continue <EOL> if confirm == '<STR_LIT:yes>' : <EOL> call_command ( "<STR_LIT>" , interactive = True ) <EOL> break <EOL> signals . post_syncdb . connect ( create_permissions , <EOL> dispatch_uid = "<STR_LIT>" ) <EOL> signals . post_syncdb . connect ( create_superuser , <EOL> sender = auth_app , dispatch_uid = "<STR_LIT>" ) </s>
