cubicweb/misc/migration/postcreate.py
changeset 12567 26744ad37953
parent 11129 97095348b3ee
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """cubicweb post creation script, set user's workflow"""
    18 """cubicweb post creation script, set user's workflow"""
    19 from __future__ import print_function
       
    20 
       
    21 from six import text_type
       
    22 
       
    23 from cubicweb import _
    19 from cubicweb import _
    24 
    20 
    25 
    21 
    26 # insert versions
    22 # insert versions
    27 create_entity('CWProperty', pkey=u'system.version.cubicweb',
    23 create_entity('CWProperty', pkey=u'system.version.cubicweb',
    28               value=text_type(config.cubicweb_version()))
    24               value=str(config.cubicweb_version()))
    29 for cube in config.cubes():
    25 for cube in config.cubes():
    30     create_entity('CWProperty', pkey=u'system.version.%s' % cube.lower(),
    26     create_entity('CWProperty', pkey=u'system.version.%s' % cube.lower(),
    31                   value=text_type(config.cube_version(cube)))
    27                   value=str(config.cube_version(cube)))
    32 
    28 
    33 # some entities have been added before schema entities, add their missing 'is' and
    29 # some entities have been added before schema entities, add their missing 'is' and
    34 # 'is_instance_of' relations
    30 # 'is_instance_of' relations
    35 for rtype in ('is', 'is_instance_of'):
    31 for rtype in ('is', 'is_instance_of'):
    36     sql('INSERT INTO %s_relation '
    32     sql('INSERT INTO %s_relation '
    54     if anonlogin == session.user.login:
    50     if anonlogin == session.user.login:
    55         print('you are using a manager account as anonymous user.')
    51         print('you are using a manager account as anonymous user.')
    56         print('Hopefully this is not a production instance...')
    52         print('Hopefully this is not a production instance...')
    57     elif anonlogin:
    53     elif anonlogin:
    58         from cubicweb.server import create_user
    54         from cubicweb.server import create_user
    59         create_user(session, text_type(anonlogin), anonpwd, u'guests')
    55         create_user(session, anonlogin, anonpwd, u'guests')
    60 
    56 
    61 # need this since we already have at least one user in the database (the default admin)
    57 # need this since we already have at least one user in the database (the default admin)
    62 for user in rql('Any X WHERE X is CWUser').entities():
    58 for user in rql('Any X WHERE X is CWUser').entities():
    63     rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
    59     rql('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
    64         {'x': user.eid, 's': activated.eid})
    60         {'x': user.eid, 's': activated.eid})