def __generateBrief(self, o): res = {} tender = o.Tender city = o.City res.update(Tender.generateBrief(tender=tender)) res.update(City.generate(city=city)) return res
def createTender(self, jsonInfo): info = json.loads(jsonInfo) # tenderID = info['tenderID'] title = info['title'] cityID = info['cityID'] location = info['location'] url = info['url'] publishDate = info['publishDate'] detail = info['detail'] biddingNum = info['biddingNum'] reviewType = info['reviewType'] typeID = info['typeID'] tenderID = self.generateID(title) (status, reason) = self.doesTenderExists(info=info) if status is True: return (False, ErrorInfo['TENDER_15']) tender = Tender(tenderID=tenderID, title=title, cityID=cityID, location=location, url=url, publishDate=publishDate, detail=detail, typeID=typeID, biddingNum=biddingNum, reviewType=reviewType) tenderSlave = TenderSlave(tenderID=tenderID, title=title, biddingNum=biddingNum) info['tenderID'] = tenderID try: db.session.add(tender) db.session.add(tenderSlave) info['searchName'] = info['title'] info['description'] = info['detail'] info['foreignID'] = info['tenderID'] info['tag'] = SEARCH_KEY_TAG_TENDRE now = datetime.now() info['createTime'] = str(now) info['joinID'] = self.generateID(info['title']) SearchKey.createSearchInfo(info=info) db.session.commit() task1.createWeChatPush.apply_async(args=[info]) except Exception as e: print str(e) # traceback.print_stack() db.session.rollback() errorInfo = ErrorInfo['TENDER_02'] errorInfo['detail'] = str(e) return (False, errorInfo) return (True, None)
def __doCreateCustomizedTender(self, info): title = info['title'] userID = info['userID'] tenderID = self.generateID(title + userID) info['tenderID'] = tenderID now = datetime.now() # return CustomizedTender.create(info=info) url = info['url'] tenderTag = info['tenderTag'] tender = Tender(tenderID=tenderID, title=title, userID=userID, url=url, publishDate=now, typeID='-1', cityID='63', tenderTag=tenderTag) db.session.add(tender) return (True, tenderID)
def updateTenderBackground(self, jsonInfo): info = json.loads(jsonInfo) tokenID = info['tokenID'] (status, userID) = self.isTokenValid(tokenID) if status is not True: errorInfo = ErrorInfo['TENDER_01'] return (False, errorInfo) try: (status, result) = Tender.update(info) db.session.commit() except Exception as e: print str(e) # traceback.print_stack() db.session.rollback() errorInfo = ErrorInfo['TENDER_02'] errorInfo['detail'] = str(e) return (False, errorInfo) return (True, None)
def __generateTender(self, t): tender = t.Tender city = t.City res = {} res.update(Tender.generate(tender=tender)) res.update(City.generate(city=city)) # # 列表中不带详情 # if tag is not None: # del res['detail'] # else: # # 详情中的情况 # favorite = t.Favorite # if favorite is not None: # res['favorite'] = True # else: # res['favorite'] = False return res
def __generateTender(self, t): res = {} res.update(Tender.generateBrief(tender=t.Tender)) res.update(City.generate(city=t.City)) return res