Beispiel #1
0
 def __init__(self):
     '''
     joint session
     '''
     session = getSession()
     self.session = getSession()
     Ctrl.__init__(self, session, db.CircleKind)
Beispiel #2
0
 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
Beispiel #3
0
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
Beispiel #4
0
 def getStations(self, id):
     '''
     取得其收录的新闻站点
     '''
     self.session = getSession()
     user = self.get(id)
     return user.stations
Beispiel #5
0
def getOptDef(id):
    session = getSession()
    if id == None:
        o = OptDef()
    else:
        o = session.query(OptDef).get(id)

    return o
Beispiel #6
0
 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
Beispiel #7
0
 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        
Beispiel #8
0
 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   
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
0
    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 -------'
Beispiel #12
0
 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
Beispiel #13
0
 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
Beispiel #14
0
 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])
Beispiel #15
0
 def add_user_byId(self, id, user):
     self.session = getSession()
     self.setCur(id)
     self.cur.users.append(user)
     self.commit_all([self.cur, user])
Beispiel #16
0
def getOptDefList ():
    return getSession().query(OptDef).all()

    
Beispiel #17
0
 def __init__(self):
     session = getSession()
     Ctrl.__init__(self, session, db.Message)
Beispiel #18
0
 def addCircle(self, id, circle):
     self.session = getSession()
     self.setCur(id)
     self.cur.circles.append(circle)
     self.commit_all(self.cur, circle)
Beispiel #19
0
 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])
Beispiel #20
0
 def __init__(self):
     '''
     joint session
     '''
     session = getSession()
     Ctrl.__init__(self, session, db.User)
Beispiel #21
0
    
    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'
Beispiel #22
0
 def add(self, circle):
     self.session = getSession()
     self.commit(circle)