Before reconstructionCode
Def Newprj (self, DB, userid, prjname, password, privacy, Intro = '' , Status = ' Active ' ):
S = ''
Flag = false
Prjid = 0
Try :
T = dB. Transaction ()
If Privacy =' Public ' And Len (password) <1:
Return ' {"Result": "error", "message": "public access without a password. Anyone can join your project "} '
Folderid, deep = tn. newfolder (dB, prjname, userid, 0, 0)
If Folderid! = 0:
Prjid = dB. insert ( ' Project ' , Folderid = folderid, userid = userid, projectname = prjname,
Password = password, privacy = privacy, Intro = intro, status = status,
Createtime = STR (datetime. datetime. Today (), revision = util. new_revision (dB, userid ))
DB. Update ( " Category " , Where = " Catid = $ folderid " , Projectid = prjid, deep =-1, vars = locals ())
Import JSON
From RoleImport Rolemgr
Rolemgr = rolemgr ()
S = rolemgr. newrole (dB, " Project user " , Prjid)
Dict = JSON. jsondecoder (). Decode (s)
If Dict [ ' Result ' ] = ' OK ' :
Roleid = int (dict [ ' Roleid ' ])
If Rolemgr. bindpermission (dB, roleid, folderid, READ = 1, write = 0) = true:
Flag = true
S = ' {"Result": "OK", "prjid": "% d "} ' % (INT (prjid ))
Else :
S = ' {"Result": "error", "message": "failed to preset project role Permissions "} '
Else :
S = ' {"Result": "error", "message": "preset project role failed "} '
Else :
S = ' {"Result": "error", "message": "a folder with the same name exists "} '
If Flag = true:
T. Commit ()
Else :
T. rollback ()
Return S
Except :
T. rollback ()
Code after reconstruction
Def Newprj (dB, userid, projectname, password, privacy, intro, status = ' Active ' ):
Try :
T = dB. Transaction ()
Projectname = projectname. lstrip (). rstrip ()
If Not _ Checkname (projectname ):
T. rollback ()
Return (False, " Invalid project name " )
Folderid, deep = tn. newfolder (dB, projectname, userid, 0, 0)
If Folderid = 0:
T. rollback ()
Return (False, " An error occurred while creating the project root directory. " )
Projectid = _ insert (dB, projectname, folderid, userid, password, privacy, intro, status)
If Projectid = 0:
T. rollback ()
Return (False, " An error occurred while creating the project. " )
If Folder. setrootfolder (dB, folderid, projectid) = false:
T. rollback ()
Return (False," Failed to Set Directory " )
If _ Presetrole (dB, userid, folderid, projectid) = false:
T. rollback ()
Return (False, " An error occurred while creating the default role. " )
If _ Presetfolder (dB, userid, folderid) = false:
T. rollback ()
Return (False, " An error occurred while creating the project directory. " )
T. Commit ()
Return (True, projectid)
Except :
T. rollback ()
Raise