doc/book/en/annexes/faq.rst
changeset 5924 b218df942dd4
parent 5781 a3e60e0fb0f3
child 6350 74575fb32a4d
equal deleted inserted replaced
5923:d1b374aa5174 5924:b218df942dd4
   113 
   113 
   114 .. sourcecode:: python
   114 .. sourcecode:: python
   115 
   115 
   116     from cubicweb import dbapi
   116     from cubicweb import dbapi
   117 
   117 
   118     cnx = dbapi.connection(database='instance-id', user='admin', password='admin')
   118     cnx = dbapi.connect(database='instance-id', user='admin', password='admin')
   119     cur = cnx.cursor()
   119     cur = cnx.cursor()
   120     for name in ('Personal', 'Professional', 'Computers'):
   120     for name in ('Personal', 'Professional', 'Computers'):
   121         cur.execute('INSERT Blog B: B name %s', name)
   121         cur.execute('INSERT Blog B: B name %s', name)
   122     cnx.commit()
   122     cnx.commit()
   123 
   123 
   300 
   300 
   301     import os
   301     import os
   302     import pwd
   302     import pwd
   303     import sys
   303     import sys
   304 
   304 
   305     from logilab.common.db import get_connection
   305     from logilab.database import get_connection
   306 
   306 
   307     def getlogin():
   307     def getlogin():
   308         """avoid usinng os.getlogin() because of strange tty / stdin problems
   308         """avoid using os.getlogin() because of strange tty/stdin problems
   309         (man 3 getlogin)
   309         (man 3 getlogin)
   310         Another solution would be to use $LOGNAME, $USER or $USERNAME
   310         Another solution would be to use $LOGNAME, $USER or $USERNAME
   311         """
   311         """
   312         return pwd.getpwuid(os.getuid())[0]
   312         return pwd.getpwuid(os.getuid())[0]
   313 
   313 
   400 
   400 
   401     $ psql mydb
   401     $ psql mydb
   402     mydb=> update cw_cwuser set cw_upassword='qHO8282QN5Utg' where cw_login='joe';
   402     mydb=> update cw_cwuser set cw_upassword='qHO8282QN5Utg' where cw_login='joe';
   403     UPDATE 1
   403     UPDATE 1
   404 
   404 
       
   405 You can prefer use a migration script similar to this shell invocation instead::
       
   406 
       
   407     $ cubicweb-ctl shell <instance>
       
   408     >>> from cubicweb.server.utils import crypt_password
       
   409     >>> crypted = crypt_password('joepass')
       
   410     >>> rset = rql('Any U WHERE U is CWUser, U login "joe"')
       
   411     >>> joe = rset.get_entity(0,0)
       
   412     >>> joe.set_attributes(upassword=crypted)
       
   413 
       
   414 The more experimented people would use RQL request directly::
       
   415 
       
   416     >>> rql('SET X upassword %(a)s WHERE X is CWUser, X login "joe"',
       
   417     ...     {'a': crypted})
       
   418 
   405 I've just created a user in a group and it doesn't work !
   419 I've just created a user in a group and it doesn't work !
   406 ---------------------------------------------------------
   420 ---------------------------------------------------------
   407 
   421 
   408 You are probably getting errors such as ::
   422 You are probably getting errors such as ::
   409 
   423