misc/migration/postcreate.py
changeset 10473 23a2fa8cb725
parent 8544 3d049071957e
child 10589 7c23b7de2b8d
equal deleted inserted replaced
10472:7dd84b69c7d4 10473:23a2fa8cb725
    36 # user workflow
    36 # user workflow
    37 userwf = add_workflow(_('default user workflow'), 'CWUser')
    37 userwf = add_workflow(_('default user workflow'), 'CWUser')
    38 activated = userwf.add_state(_('activated'), initial=True)
    38 activated = userwf.add_state(_('activated'), initial=True)
    39 deactivated = userwf.add_state(_('deactivated'))
    39 deactivated = userwf.add_state(_('deactivated'))
    40 userwf.add_transition(_('deactivate'), (activated,), deactivated,
    40 userwf.add_transition(_('deactivate'), (activated,), deactivated,
    41                       requiredgroups=('managers',))
    41                       requiredgroups=(u'managers',))
    42 userwf.add_transition(_('activate'), (deactivated,), activated,
    42 userwf.add_transition(_('activate'), (deactivated,), activated,
    43                       requiredgroups=('managers',))
    43                       requiredgroups=(u'managers',))
    44 
    44 
    45 # create anonymous user if all-in-one config and anonymous user has been specified
    45 # create anonymous user if all-in-one config and anonymous user has been specified
    46 if hasattr(config, 'anonymous_user'):
    46 if hasattr(config, 'anonymous_user'):
    47     anonlogin, anonpwd = config.anonymous_user()
    47     anonlogin, anonpwd = config.anonymous_user()
    48     if anonlogin == session.user.login:
    48     if anonlogin == session.user.login:
    49         print 'you are using a manager account as anonymous user.'
    49         print 'you are using a manager account as anonymous user.'
    50         print 'Hopefully this is not a production instance...'
    50         print 'Hopefully this is not a production instance...'
    51     elif anonlogin:
    51     elif anonlogin:
    52         from cubicweb.server import create_user
    52         from cubicweb.server import create_user
    53         create_user(session, unicode(anonlogin), anonpwd, 'guests')
    53         create_user(session, unicode(anonlogin), anonpwd, u'guests')
    54 
    54 
    55 # need this since we already have at least one user in the database (the default admin)
    55 # need this since we already have at least one user in the database (the default admin)
    56 for user in rql('Any X WHERE X is CWUser').entities():
    56 for user in rql('Any X WHERE X is CWUser').entities():
    57     rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
    57     rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
    58         {'x': user.eid, 's': activated.eid})
    58         {'x': user.eid, 's': activated.eid})
    61 if interactive_mode:
    61 if interactive_mode:
    62     cfg = config.persistent_options_configuration()
    62     cfg = config.persistent_options_configuration()
    63     cfg.input_config(inputlevel=0)
    63     cfg.input_config(inputlevel=0)
    64     for section, options in cfg.options_by_section():
    64     for section, options in cfg.options_by_section():
    65         for optname, optdict, value in options:
    65         for optname, optdict, value in options:
    66             key = '%s.%s' % (section, optname)
    66             key = u'%s.%s' % (section, optname)
    67             default = cfg.option_default(optname, optdict)
    67             default = cfg.option_default(optname, optdict)
    68             # only record values differing from default
    68             # only record values differing from default
    69             if value != default:
    69             if value != default:
    70                 rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s',
    70                 rql('INSERT CWProperty X: X pkey %(k)s, X value %(v)s',
    71                     {'k': key, 'v': value})
    71                     {'k': key, 'v': value})