Esempio n. 1
0
def update_user(user_info):

    s = app.helpers.session.get_session()

    if 'is_active' in user_info:
        user_info.is_active = '1'
    else:
        user_info.is_active = '0'

    #FIXME: mudar para não precisar de updates separados
    if user_info.password:
        result = db.update('users',
                           where='id = $id',
                           vars={'id': user_info.id},
                           name=user_info.name, is_active=user_info.is_active, comments=user_info.comments, password=create_password(user_info.password), email=user_info.email, lastupdated=int(time.time()), lastupdatedby=s.userid)
    else:
        result = db.update('users',
                           where='id = $id',
                           vars={'id': user_info.id},
                           name=user_info.name, is_active=user_info.is_active, comments=user_info.comments, email=user_info.email, lastupdated=int(time.time()), lastupdatedby=s.userid)
    logger.info(result)
    # initiate dictionary
    records = {}

    # se result == True, assume que usuario foi atualizado com sucesso
    if result == 1:
        # set response message to OK
        records['Result'] = 'OK'
    else:
        records['Result'] = 'ERROR'
        records['Message'] = 'Nenhuma informação alterada'

    return json.dumps(records)
Esempio n. 2
0
 def moveImgLine(self, headId, lineIds):
     if lineIds is None or len(lineIds) == 0:
         return
     retHeadId = None
     imgQty = 0
     imgOrd = self.getMaxOrd(headId)
     imgNameList = []
     ids = ""
     for lineId in lineIds:
         ids += "," + lineId
     ids = ids[1:]
     for line in db.select("imgLine", where="lineId in (" + ids + ")").list():
         if retHeadId is None:
             retHeadId = line["headId"]
         imgQty += 1
         imgOrd += 1
         line["headId"] = headId
         line["imgOrd"] = imgOrd
         db.update('imgLine', where="lineId=$lineId", vars={'lineId':line["lineId"]}, **line)
         imgNameList.append(line.get("imgNameP"))
     imgHeaderDest = self.updateHeadSizeAndQty(headId)
     imgHeaderSrc = self.updateHeadSizeAndQty(retHeadId)
     imgPathList = []
     for imgName in imgNameList:
         imgPathList.append(pathJoin(imgHeaderSrc.get("headNum"), imgName))
         imgPathList.append(pathJoin(imgHeaderSrc.get("headNum"), "s_" + imgName))
     return retHeadId, imgPathList, imgHeaderDest.get("headNum")
Esempio n. 3
0
 def saveImgHead(self, imgHead):
     headNum = imgHead.get("headNum")
     if headNum:
         imgHeadDb = self.getByHeadNum(headNum)
         if imgHeadDb:
             headId = imgHeadDb.get("headId")
             db.update("imgHead", where="headId=$headId", vars={'headId':headId}, **imgHead) 
         else:
             db.insert("imgHead", **imgHead)
Esempio n. 4
0
 def saveOrUpdate(self, uploadTask):
     uploadTaskDb = None
     if uploadTask and uploadTask.headId:
         uploadTaskDb = self.getByHeadId(uploadTask.headId)
     if uploadTaskDb:
         uploadTask['uploadTaskId'] = uploadTaskDb.uploadTaskId
         db.update("uploadTask", where="uploadTaskId=$uploadTaskId", vars={'uploadTaskId':uploadTaskDb.uploadTaskId}, **uploadTask)    
     else:
         return self.getById(db.insert("uploadTask", **uploadTask))
Esempio n. 5
0
 def editImgLine(self, lineId, imgOrd, imgNameS):
     dbImgLine = db.select("imgLine", where="lineId=$lineId", vars={"lineId":lineId}).list()[0]
     if imgOrd is not None and imgOrd != "":
         imgOrd = int(imgOrd)
         dbImgOrd = dbImgLine["imgOrd"]
         headId = dbImgLine.get("headId")
         if dbImgOrd > imgOrd:
             db.query("update imgLine set imgOrd = imgOrd + 1 where headId = " + str(headId) + " and imgOrd >= " + str(imgOrd) + " and imgOrd <" + str(dbImgOrd))
         elif dbImgOrd < imgOrd:
             db.query("update imgLine set imgOrd = imgOrd - 1 where headId = " + str(headId) + " and imgOrd > " + str(dbImgOrd) + " and imgOrd <=" + str(imgOrd))
         dbImgLine["imgOrd"] = imgOrd
     if imgNameS is not None and imgNameS != "":
         dbImgLine["imgNameS"] = imgNameS
     db.update("imgLine", where="lineId=$lineId", vars={"lineId":dbImgLine.lineId}, **dbImgLine)
     return dbImgLine["headId"]
Esempio n. 6
0
 def saveAll(self, headId, imgLines):
     lineIds = []
     dbImgLines = db.select('imgLine', where="headId=$headId", vars={"headId":headId})
     for imgLine in dbImgLines:
         lineIds.append(imgLine.get("lineId"))
     imgOrd = self.getMaxOrd(headId)
     ret = []
     for imgLine in imgLines:
         if imgLine.get("lineId") in lineIds:
             db.update('imgLine', where="lineId=$lineId", vars={'lineId':imgLine.get("lineId")}, **imgLine)
             ret.append(self.getByLineId(imgLine.get("lineId")))
         else:
             imgOrd += 1
             imgLine['imgOrd'] = imgOrd
             imgLine["headId"] = headId
             lineId = db.insert('imgLine', **imgLine)
             ret.append(self.getByLineId(lineId))
     return ret
Esempio n. 7
0
 def saveHeadAndLine(self, imgHead):
     from imgLineDao import ImgLineDao 
     imgLineDao = ImgLineDao()
     allLines = []
     imgLines = imgHead.get("imgLines")
     # 头表
     if imgLines or imgLines is not None and len(imgLines) == 0: 
         del imgHead["imgLines"]
     headId = imgHead.get('headId')
     if headId:
         db.update('imgHead', where="headId=$headId", vars={'headId':headId}, **imgHead)
     else:
         headId = db.insert('imgHead', **imgHead)
     # 行表
     if imgLines is None or len(imgLines) == 0:
         return None
     dbLines = imgLineDao.saveAll(headId, imgLines)
     allLines.extend(dbLines)
     self.updateHeadSizeAndQty(headId)
     return allLines
Esempio n. 8
0
 def updateImgHeadNum(self, headId, headNum):
     dbHead = self.getById(headId)
     userForm = json.loads(dbHead.userForm)
     for f in userForm:  
         if str(f.get("groupBy"))=="1":
             f["value"] = headNum 
             break;
     if userForm:
         db.update("imgHead", where="headId=$headId", vars={"headId":headId}, **{"headNum":headNum,"userForm":json.dumps(userForm)})
     else:
         db.update("imgHead", where="headId=$headId", vars={"headId":headId}, **{"headNum":headNum})
     db.update("imgLine", where="headId=$headId", vars={"headId":headId}, **{"headNum":headNum})
Esempio n. 9
0
 def updateStatusByHeadId(self, headId, status):
     if headId:
         db.update("uploadTask", where="headId=$headId", vars={'headId':headId}, status=status) 
Esempio n. 10
0
 def updateImgHeadNum(self, headId, headNum):
     db.update("imgLine", where="headId=$headId", vars={"headId":headId}, **{"headNum":headNum})    
Esempio n. 11
0
 def initImgOrd(self, headId):
     imgOrd = 0
     for line in db.select("imgLine", where="headId = $headId" , vars={"headId":headId}).list():
         imgOrd += 1
         db.update("imgLine", where="lineId=$lineId", vars={"lineId":line.lineId}, **{"imgOrd":imgOrd})
Esempio n. 12
0
def update_last_login(id):
    db.update('users',
        where='id = $id',
        vars={'id': id},
        lastlogin=int(time.time()))
Esempio n. 13
0
 def update(self, imgHead):
     if imgHead and  imgHead.get("headId"):
         db.update("imgHead", where="headId=$headId", vars={'headId':imgHead.get("headId")}, **imgHead)
Esempio n. 14
0
 def updateStatusByheadId(self, headId, status):
     if headId:
         db.update("imgHead", where="headId=$headId", vars={'headId':headId}, status=status)
Esempio n. 15
0
 def updateHeadSizeAndQty(self, headId):
     from imgLineDao import ImgLineDao 
     imgLineDao = ImgLineDao()
     headSize = imgLineDao.getHeadSize(headId)
     imgQty = imgLineDao.getImgQty(headId)
     db.update('imgHead', where="headId=$headId", vars={'headId':headId}, **{"headSize":headSize, "imgQty":imgQty})
Esempio n. 16
0
 def updateHeadSizeAndQty(self, headId):
     headSize = self.getHeadSize(headId)
     imgQty = self.getImgQty(headId)
     db.update('imgHead', where="headId=$headId", vars={'headId':headId}, **{"headSize":headSize, "imgQty":imgQty})
     for head in db.select('imgHead', where="headId=$headId", vars={'headId':headId}).list():
         return head
Esempio n. 17
0
 def updateImgLine(self, imgLine):
     lineId = imgLine.get("lineId")
     if lineId:
         db.update("imgLine", where="lineId=$lineId", vars={'lineId':lineId}, **imgLine)
Esempio n. 18
0
 def update(self, ocrResult):
     resultId = ocrResult.get("resultId")
     if resultId:
         db.update("ocrResult", where="resultId=$resultId", vars={'resultId':resultId}, **ocrResult)