Ejemplo n.º 1
0
def getNews(station):
    '''
    get staton's all news
    station is id or string name

    title
    date
    '''
    session = getSession()
    res = {}
    if type(station) is types.IntType:
        '''
        get id
        '''
        s = session.query(table.Station).filter(table.Station.id == station).first()
        news = s.news
        res['station'] = s.name
    else:
        res['station'] = station
        s = session.query(table.Station).filter(table.Station.name == station).first()
        news = s.news
    res['news'] = []
    for n in news:
        item = n.item
        res['news'].append(
            {
                'id': n.id,
                'title':n.title,
                'station': n.station.name,
                'date':n.date,
            }
        )
    return res
Ejemplo n.º 2
0
 def GET(self):
     _session = getSession()
     user = _session.query(table.User).filter(table.User.id == session.userid).first()
     #get new message metas
     #-----------------------------------
     metas = user.messages
     res1 = []
     for m in metas:
         #change status
         #...
         if m.status != -1:
             '''
             只取得status为-1的记录
             '''
             continue
         try:
             m.status = 0
             _session.add(m)
             message = m.message
             item = message.item
             res1.append({
                 'id':message.id,
                 'title': message.title,
                 'summary': message.summary,
                 'date': message.date,
                 'content': item.content
             })
         except:
             print 'wrong get new items'
             pass
     #get new reply items
     #-----------------------------------
     res2 = []
     replys = user.replys
     for r in replys:
         print r.replyto
         if r.status != -1:
             continue
         r.status = 0
         _session.add(r)
         item = r.item
         try:
             res2.append({
                 'id':r.id,
                 'replyto':r.replyto,
                 'date':r.date,
                 'content':item.content
             })
         except:
             print 'none reply'
     render = web.template.frender("templates/ajax_get_update_messages.html")
     _session.commit()
     return render(res1, res2)
Ejemplo n.º 3
0
 def GET(self, data):
     data = web.input()
     messageid = data['to']
     #get user
     _session = getSession()
     user = _session.query(table.User).filter(table.User.id == session.userid).first()
     message = _session.query(table.Message).filter(table.Message.id == messageid).first()
     print 'follow %s to %s' % (user.name, message.date)
     follower = table.Follower(user.name, dt.today())
     message.followers.append(follower)
     _session.add(follower)
     _session.add(message)
     _session.commit()
     return 'ok'
Ejemplo n.º 4
0
def getNewsById(id):
    '''
    get news content:
    title
    date
    content
    station
    '''
    session = getSession()
    news = session.query(table.News).filter(table.News.id == id).first()
    res = {}
    res['title'] = news.title
    res['content'] = news.item.content
    res['date'] = news.date
    res['station'] = news.station.name
    return res
Ejemplo n.º 5
0
def getStations():
    '''
    get stations:
    id
    name
    '''
    session = getSession()
    stations = session.query(table.Station)
    res = []
    for s in stations:
        res.append(
            {'name': s.name,
            'id':s.id,
            'num':len(s.news),
            }
        )
    return res
Ejemplo n.º 6
0
 def POST(self, data):
     data = web.input()
     print 'data', '-' * 50
     print data
     _session = getSession()
     #add reply
     reply = table.Reply(dt.today(), -1, data['replyto'], session.userid)
     item = table.ReplyItem(data['content'])
     reply.item = item
     #get user
     message = _session.query(table.Message).filter(table.Message.id == data['messageid']).first()
     owner_id = message.creator_id
     user = _session.query(table.User).filter(table.User.id == owner_id).first()
     user.replys.append(reply)
     _session.add_all([reply, item, user])
     _session.commit()
     res =  {
         'name':user.name,
         'logo_url':user.logo_url
     }
     render = web.template.frender("templates/ajax_reply.html")
     return render(res)
Ejemplo n.º 7
0
 def GET(self):
     print 'hello-----' * 50
     userinfo = userctrl.getInfo(session.userid)
     print 'userinfo: ', userinfo
     _session = getSession()
     messages = _session.query(table.Message).filter(table.Message.creator_id == session.userid).all()
     res = []
     for m in messages:
         f = getFollowers(_session, m.id)
         if not f: continue
         res.append({
             'id': m.id,
             'title' : m.title,
             'summary': m.summary,
             'date': m.date,
             'followers': f,
             'followers_num': len(f)
         })
     print '--'*50
     print 'own messages:'
     print res
     render = web.template.render("templates/", base="template")
     return render.own_messages(userinfo, res)
Ejemplo n.º 8
0
    "/sigle(.*)", "sigle",
    "/items(.*)", "items",
    # show circles
    "/circles", "circles",
    #profile
    "/profile", "user_profile",
    "/profile_edit", "profile_edit",
    "/profile_join_circles", "profile_join_circles", 
    "/profile_select_news", "profile_select_news",
)

app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'userid': -1})

#--------------- db ctroler--------------------
_session = getSession()
userctrl = user.User()
circlectrl = circle.Circle()
messagectrl = message.Message()


class index:
    def GET(self):
        render = web.template.render("templates/", base="template")
        return render.login()

class signin:
    def GET(self):
        render = web.template.render("templates/", base="template")
        return render.signin()