Exemplo n.º 1
0
 def createOperationBiddingBook(self, jsonInfo, imgFileList):
     (status, operationID) = self.createOperation(jsonInfo=jsonInfo)
     if status is not True:
         return (False, operationID)
     ossInfo = {}
     ossInfo['bucket'] = 'sjtender'
     try:
         index = 0
         for i in imgFileList:
             imgID = self.generateID(str(index) + i['imgName'])
             postFix = str(i['imgName']).split('.')
             if len(postFix) > 0:
                 postFix = '.' + postFix[-1]
             else:
                 postFix = ''
             imgPath = imgID + postFix
             imagePath = ImgPath(imgPathID=imgID,
                                 path=imgPath,
                                 foreignID=operationID,
                                 imgName=i['imgName'])
             db.session.add(imagePath)
             index = index + 1
             self.uploadOSSImage('biddocument/%s' % imgPath, ossInfo,
                                 i['file'])
         db.session.commit()
         return (True, operationID)
     except Exception as e:
         print e
         print 'upload file to oss error'
         errorInfo = ErrorInfo['TENDER_31']
         errorInfo['detail'] = str(e)
         return (False, errorInfo)
Exemplo n.º 2
0
    def getNewsDetail(self, jsonInfo):
        info = json.loads(jsonInfo)
        newsID = info['newsID']

        try:
            result = db.session.query(News).filter(
                News.newsID == newsID).first()

            newsResult = {}
            newsResult.update(News.generate(o=result))
            imgResult = db.session.query(ImgPath).filter(
                ImgPath.foreignID == newsResult['newsID']).all()
            ossInfo = {}
            ossInfo['bucket'] = 'sjtender'
            newsResult['imgList'] = [
                ImgPath.generate(img=o,
                                 directory=TENDER_NEWS,
                                 ossInfo=ossInfo,
                                 hd=True,
                                 isFile=False) for o in imgResult
            ]
            return (True, newsResult)
        except Exception as e:
            print e
            traceback.print_exc()
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            db.session.rollback()
            return (False, errorInfo)
Exemplo n.º 3
0
 def getCompanyImg(self, jsonInfo):
     info = json.loads(jsonInfo)
     startIndex = info['startIndex']
     pageCount = info['pageCount']
     companyID = info['companyID']
     tag = int(info['tag'])
     try:
         query = db.session.query(ImgPath).filter(
             and_(
                 ImgPath.foreignID == companyID,
                 ImgPath.tag == tag
             )
         ).offset(startIndex).limit(pageCount)
         allResult = query.all()
         count = db.session.query(func.count(ImgPath.imgPathID)).filter(
             and_(
                 ImgPath.foreignID == companyID,
                 ImgPath.tag == tag
             )
         ).first()
     except Exception as e:
         print e
         errorInfo = ErrorInfo['TENDER_02']
         errorInfo['detail'] = str(e)
         db.session.rollback()
         return (False, errorInfo)
     ossInfo = {}
     ossInfo['bucket'] = 'sjtender'
     imgList = [ImgPath.generate(result, ossInfo, 'company', True) for result in allResult]
     imgResult = {}
     imgResult['imgList'] = imgList
     imgResult['count'] = count[0]
     return (True, imgResult)
Exemplo n.º 4
0
 def createCustomizedTender(self, info, imgFileList):
     userID = info['userID']
     ossInfo = {}
     ossInfo['bucket'] = 'sjtender'
     try:
         info['userID'] = userID
         info['tenderTag'] = PUSH_TENDER_INFO_TAG_CUS
         (status, tenderID) = self.__doCreateCustomizedTender(info=info)
         index = 0
         for i in imgFileList:
             imgID = self.generateID(str(index) + i['imgName'])
             postFix = str(i['imgName']).split('.')
             if len(postFix) > 0:
                 postFix = '.' + postFix[-1]
             else:
                 postFix = ''
             imgPath = imgID + postFix
             imagePath = ImgPath(imgPathID=imgID, path=imgPath,
                                 foreignID=tenderID, imgName=i['imgName'])
             db.session.add(imagePath)
             index = index + 1
             self.uploadOSSImage('customizedtender/%s' % imgPath, ossInfo, i['file'])
         db.session.commit()
         return (True, tenderID)
     except Exception as e:
         print e
         traceback.print_exc()
         print 'upload file to oss error'
         errorInfo = ErrorInfo['TENDER_31']
         errorInfo['detail'] = str(e)
         return (False, errorInfo)
Exemplo n.º 5
0
    def __generateImg(self, o, dic, ossInfo):
        foreignID = o.foreignID
        img = ImgPath.generate(img=o,
                               directory=TENDER_NEWS,
                               ossInfo=ossInfo,
                               hd=True,
                               isFile=False)

        if not dic.has_key(foreignID):
            imgList = [img]
            dic[foreignID] = imgList
        else:
            imgList = dic[foreignID]
            imgList.append(img)
        return (True, None)
Exemplo n.º 6
0
    def createNews(self, jsonInfo, imgFileList):
        info = json.loads(jsonInfo)
        title = info['title'].replace('\'', '\\\'').replace('\"',
                                                            '\\\"').strip()
        content = info['content'].replace('\'', '\\\'').replace('\"', '\\\"')

        newsID = self.generateID(title)
        ossInfo = {}
        ossInfo['bucket'] = 'sjtender'
        try:
            index = 0
            for i in imgFileList:
                imgID = self.generateID(str(index) + i['imgName'])
                postFix = str(i['imgName']).split('.')
                if len(postFix) > 0:
                    postFix = '.' + postFix[-1]
                else:
                    postFix = ''
                imgPath = imgID + postFix
                imagePath = ImgPath(imgPathID=imgID,
                                    path=imgPath,
                                    foreignID=newsID,
                                    imgName=i['imgName'])
                db.session.add(imagePath)
                index = index + 1
                self.uploadOSSImage('tendernews/%s' % imgPath, ossInfo,
                                    i['file'])

            # 增加资讯记录
            now = datetime.now()
            news = News(newsID=newsID,
                        title=title,
                        content=content,
                        createTime=now)
            db.session.add(news)
            db.session.commit()
            return (True, newsID)
        except Exception as e:
            print e
            traceback.print_exc()
            print 'upload file to oss error'
            errorInfo = ErrorInfo['TENDER_31']
            errorInfo['detail'] = str(e)
            return (False, errorInfo)
Exemplo n.º 7
0
    def addImagesWithOSS(self, info):
        imgList = info['imgList']
        directory = info['directory']
        foreignID = info['foreignID']

        ossInfo = {}
        ossInfo['bucket'] = 'sjtender'
        index = 0

        for img in imgList:
            imgID = self.generateID(str(index) + img['imgPath'])
            path = imgID + img['imgPath']
            imgFile = img['imgFile']
            imagePath = ImgPath(imgPathID=imgID, path=path, foreignID=foreignID)
            db.session.add(imagePath)
            index = index + 1
            self.uploadOSSImage('%s/%s' % (directory, path), ossInfo, imgFile)

        return (True, None)
Exemplo n.º 8
0
    def addImage(self, info):
        imgList = info['imgList']
        foreignID = info['foreignID']
        if info.has_key('tag'):
            tag = info['tag']
        else:
            tag = 0

        index = 0
        for img in imgList:
            imgName = img['imgName']
            imgNum = img['imgNum']
            imgID = self.generateID(str(index) + imgName)
            imagePath = ImgPath(imgPathID=imgID, path=imgName, foreignID=foreignID,
                                tag=tag, imgNum=imgNum)
            db.session.add(imagePath)
            index = index + 1

        return (True, None)
Exemplo n.º 9
0
    def addImageListWithoutOSS(self, info):
        imgList = info['imgList']
        foreignID = info['foreignID']
        try:
            for img in imgList:
                imgPath = img['imgPath']
                imgName = img['imgName']
                tag = img['tag']
                imageID = self.generateID(imgPath)
                _img = ImgPath(imgPathID=imageID, path=imgPath,
                               foreignID=foreignID, tag=tag,
                               imgName=imgName)
                db.session.add(_img)

            db.session.commit()
        except Exception as e:
            print e
            errorInfo = ErrorInfo['TENDER_02']
            errorInfo['detail'] = str(e)
            return (False, errorInfo)
        return (True, None)
Exemplo n.º 10
0
 def __generateImg(o):
     res = {}
     res.update(ImgPath.generate(img=o, ossInfo=self.ossInfo,
                                 directory='contract', hd=True, isFile=True))
     return res