def __init__(self): ''' joint session ''' session = getSession() self.session = getSession() Ctrl.__init__(self, session, db.CircleKind)
def login(self, name, pwd): self.session = getSession() session = getSession() user = self.get_byName(session, name) if user: print '>> login get user: ', user.name, user.pwd if user.pwd == pwd: return user.id return -1
def postOptDef(id): session = getSession() id = request.form.get('id') if id == None: o = OptDef() else: o = session.query(OptDef).get(id) o.underlying = 'BANKNIFTY' o.level1 = request.form.get('level1') o.level2 = request.form.get('level2') o.level3 = request.form.get('level3') o.level4 = request.form.get('level4') o.level5 = request.form.get('level5') o.notabove = request.form.get('notabove') o.notbelow = request.form.get('notbelow') o.ivtop = request.form.get('ivtop') o.ivbottom = request.form.get('ivbottom') o.weeklyexpirytargetup = request.form.get('weeklyexpirytargetup') o.weeklyexpirytargetdown = request.form.get('weeklyexpirytargetdown') o.trend15m = request.form.get('trend15m') o.maxpaindirection = request.form.get('maxpaindirection') o.maxpaintarget = request.form.get('maxpaintarget') o.pcrdirection = request.form.get('pcrdirection') o.pcrup = request.form.get('pcrup') o.pcrdown = request.form.get('pcrdown') #o=session.query(OptDef) #o=o.filter(id) #session.flush() if o.id == None: #if new record session.add(o) session.commit() print("the new id: ", o.id) return o.id
def getStations(self, id): ''' 取得其收录的新闻站点 ''' self.session = getSession() user = self.get(id) return user.stations
def getOptDef(id): session = getSession() if id == None: o = OptDef() else: o = session.query(OptDef).get(id) return o
def getUserNames(self, circleid): self.session = getSession() self.setCur(circleid) res = [] for u in self.cur.users: res.append({ 'name': u.name, 'logo_url':u.logo_url, }) return res
def getTags(self, id): self.session = getSession() user = self.get(id) tags = user.tags res = [] for t in tags: res.append( {'id': t.id, 'name': t.name, } ) return res
def getCircles(self, id): self.session = getSession() user = self.get(id) circles = user.circles res = [] for c in circles: res.append( {'id': c.id, 'name': c.name, } ) return res
def getInfo(self, id): #user = self.get(id) session = getSession() user = session.query(db.User).filter(db.User.id == id).first() res = { 'name': user.name, 'pwd': user.pwd, #'logo_url': user.logo_url, 'email': user.email, 'pos': user.pos, 'logo_url': user.logo_url, 'university': user.university, } return res
def getAllNewsList(self, id, page=-1): self.session = getSession() news_page_num = 7 res = [] user = self.get(id) #split page if page == -1: news = user.news else: print user.news news = user.news[page * news_page_num : (page+1) * news_page_num] for n in news: res.append({ 'id': n.id, 'title': n.title, 'date': n.date, 'station': n.station.name }) return res
def push(self, circleid, message_dic): self.session = getSession() circle = self.session.query(db.Circle).filter(db.Circle.id == circleid).first() users = circle.users for u in users: message = db.Message( message_dic['title'], message_dic['summary'], -1, dt.datetime.today(), ) message.creator_id = message_dic['ownerid'] item = db.MessageItem(message_dic['content']) message.item = item self.session.add(message) self.session.add(item) meta = db.MessageMeta(message, -1) print meta u.messages.append(meta) self.session.add_all([u, meta]) self.session.commit() print '-------- messages -------'
def getReplys(self, id): self.session = getSession() res = [] user = self.get(id) replys = user.replys for r in replys: owner_id = r.owner_id #get from user from_user = self.get(owner_id) print r.replyto item = r.item try: res.append({ 'id':r.id, 'replyto':r.replyto, 'date':r.date, 'content':item.content, 'from_user_name': from_user.name, 'from_user_logo_url': from_user.logo_url, }) except: print 'none reply' return res
def getMessages(self, id): ''' 取得 id 的 user 的所有message ''' self.session = getSession() user = self.get(id) messages = user.messages res = [] for m in messages: message = m.message try: res.append( { 'id':message.id, 'title': message.title, 'date': message.date, 'summary': message.summary, 'content': transP(message.item.content), } ) except: print 'no message!' res.reverse() return res
def add_circle_byId(self, id, circle): #ck = self.session.query(db.CircleKind).filter(db.CircleKind.id == id).first() self.session = getSession() self.setCur(id) self.cur.circles.append(circle) self.commit_all([circle, self.cur])
def add_user_byId(self, id, user): self.session = getSession() self.setCur(id) self.cur.users.append(user) self.commit_all([self.cur, user])
def getOptDefList (): return getSession().query(OptDef).all()
def __init__(self): session = getSession() Ctrl.__init__(self, session, db.Message)
def addCircle(self, id, circle): self.session = getSession() self.setCur(id) self.cur.circles.append(circle) self.commit_all(self.cur, circle)
def addTag(self, id, tag): #user = self.session.query(db.User).filter(db.User.id == id).first() self.session = getSession() self.setCur(id) self.cur.tags.append(tag) self.commit_all([self.cur, tag])
def __init__(self): ''' joint session ''' session = getSession() Ctrl.__init__(self, session, db.User)
def getTags(self, id): self.session = getSession() user = self.get(id) tags = user.tags res = [] for t in tags: res.append( {'id': t.id, 'name': t.name, } ) return res if __name__ == '__main__': session = getSession() u = User(session) user = db.User( "chunwei" , "511541", "*****@*****.**", "pos", "pku", 1.0, "./" ) #u.add(user) u.show_all() us = u.get(1) circles = us.circles print 'circles'
def add(self, circle): self.session = getSession() self.commit(circle)