示例#1
0
def send_at_notification(ret, *args, **kwargs):
    db = getconn()
    print ret, kwargs
    if not 'rid' in ret:
        tid = ret['tid']
        title = kwargs['title']
        rid = 0
    else:
        tid = ret.get('tid') or kwargs['tid']
        rid = ret['rid']
        title = db.get(u"SELECT title FROM herzog_topic" "  WHERE tid=%s", tid)
        title = title['title']
    params = '%s\n%s\n%s\n%s' % (title.replace(
        '\n', ' '), kwargs['userid'], tid, rid)
    touserids = RE_AT.findall(kwargs['content'])[:5]
    cli = getclient()
    now = getnow()
    for touserid in touserids:
        userid = cli.userexists(userid=touserid)
        if 'userid' in userid:
            userid = userid['userid']
        else:
            continue
        db.execute(
            u"INSERT INTO herzog_notification"
            "  (userid, t, params, s, lastupdate)"
            " VALUES (%s, %s, %s, %s, %s)", touserid, TYPE_AT, params, tid,
            now)
示例#2
0
def send_upvote_notification(ret, userid, tid=None, rid=None, *args, **kwargs):
    db = getconn()
    if 'tid' is not None:
        rid = 0
        title = db.get(
            u"SELECT title, owner FROM herzog_topic"
            "  WHERE tid=%s", tid)
        touserid = title['owner']
        title = title['title']
    else:
        tid = db.get(u"SELECT tid FROM herzog_reply" "  WHERE rid=%s", rid)
        tid = tid['tid']
        title = db.get(
            u"SELECT title, owner FROM herzog_topic"
            "  WHERE tid=%s", tid)
        touserid = title['owner']
        title = title['title']
    params = '%s\n%s\n%s\n%s' % (title.replace(
        '\n', ' '), kwargs['userid'], tid, rid)
    cli = getclient()
    touserid = cli.userexists(userid=touserid)
    now = getnow()
    if 'userid' in touserid:
        touserid = touserid['userid']
        db.execute(
            u"INSERT INTO herzog_notification"
            "  (userid, t, params, s, lastupdate)"
            " VALUES (%s, %s, %s, %s, %s)", touserid, TYPE_UPVOTE, params, tid,
            now)
示例#3
0
def board(boardname):
    db = getconn()
    board = getclient().showboard(board=boardname)
    if 'error' in board:
        abort(404)
    userid = getuserid()
    if userid:
        topics = db.query(
            u"SELECT herzog_topic.tid, owner, title, score, v, lastupdate,"
            "   lastreply, replynum, partnum, upvote, fromapp, readtime,"
            "   herzog_topicship.flag, content, upvote, boardname, herzog_topicship.flag as tsflag, readtime FROM herzog_topic"
            "  LEFT JOIN herzog_topicship"
            "    ON herzog_topicship.tid=herzog_topic.tid AND userid=%s"
            "  WHERE boardname=%s"
            "  ORDER BY score DESC LIMIT 16", userid, boardname)
    else:
        topics = db.query(
            u"SELECT tid, owner, title, score, v, lastupdate,"
            "   lastreply, replynum, partnum, upvote, fromapp,"
            "   flag, content, upvote, boardname FROM herzog_topic"
            " WHERE boardname=%s ORDER BY score DESC LIMIT 16", boardname)
    if len(topics) == 16:
        score = topics[-1].score
        del topics[15]
    else:
        score = -1
    bsetting = getbsetting(boardname) or dict()
    print bsetting
    return render_template('board.html',
                           board=board,
                           bsetting=bsetting,
                           topics=topics)
示例#4
0
def message():
    userid = authed()
    message = getclient().getmessage()
    db = getconn()
    touch = db.get(
        u"SELECT touch_notification,touch_starpost"
        " FROM herzog_userdata"
        " WHERE userid=%s", userid)
    if touch:
        touch_notification = touch.touch_notification
        touch_starpost = touch.touch_starpost
    else:
        touch_notification = touch_starpost = 0
    notification_num = getconn().get(
        u"SELECT count(nid) as t FROM herzog_notification"
        " WHERE userid=%s AND (lastupdate > %s)"
        " ORDER BY lastupdate DESC"
        " LIMIT 6", userid, touch_notification)
    print notification_num, touch_notification
    star_num = getconn().get(
        u"SELECT count(herzog_topic.tid) as t FROM herzog_topic"
        "  INNER JOIN herzog_topicship"
        " ON herzog_topic.tid = herzog_topicship.tid"
        " WHERE herzog_topicship.userid=%s AND"
        "   herzog_topicship.flag & 8"
        "   AND herzog_topic.lastreply > %s"
        " LIMIT 15", userid, touch_starpost)
    return '%s,%s,%s,%s' % (message['newfavs'], message['mails'],
                            notification_num['t'], star_num['t'])
示例#5
0
def del_fs_reply(userid, rid, **ps):
    db = getconn()
    reply = db.get(
        u"SELECT tid, oldfilename FROM herzog_reply"
        "  WHERE rid=%s", rid)
    if not reply:
        raise HZActionError('No such reply')
    if not reply.oldfilename:
        logger.warning(
            "Try delete a no oldfilename file, userid=%s, fromhost=%s, reply=%s",
            userid, request.remote_addr, reply)
        return True
    topic = db.get(u"SELECT boardname FROM herzog_topic"
                   "  WHERE tid=%s", reply.tid)
    if not topic:
        raise HZActionError('No such topic')
    r = getclient().do_del(board=topic.boardname, file=reply.oldfilename)
    if 'error' in r:
        if r['emsg'] == u"文件不存在, 删除失败":
            if (isowner_topic(userid, tid)):
                warning(
                    "Delete a no exists file, filename=%s, userid=% [%s], fromhost=%s",
                    topic.oldfilename, authed, request.remote_addr, topic)
                return True
        raise HZActionError(r['emsg'])
    return True
示例#6
0
def logout():
    authed()
    ret = getclient().do_logout()
    if ret.get('success') :
        session.clear()
        return json_success()
    return json_error(4, ret['emsg'])
示例#7
0
def index():
    db = getconn()
    topics = db.query(u"SELECT tid, owner, title, score, v, lastupdate,"
                      "   lastreply, replynum, partnum, upvote, fromapp,"
                      "   flag, content, boardname FROM herzog_topic"
                      "  ORDER BY score DESC LIMIT 21")
    if len(topics) == 21:
        score = topics[-1].score
        del topics[20]
    else:
        score = -1
    boards = getclient().allboards()
    # Filter the topics use a whitelist
    fresh = groupup(topics)
    # TODO : topics may be NONE
    # TODO : perm filter
    # TODO : fresh and topten
    topten = [
        dict(title=t.title, tid=t.tid, owner=t.owner) for t in topics[:10]
    ]
    img = hzd.get('page:fresh:image')
    goods = hzd.geta('page:fresh:goods')
    ad = hzd.geto('pgae:fresh:ad')
    return render_template('fresh.html',
                           fresh=fresh,
                           img=img,
                           boards=boards,
                           score=score,
                           topten=topten,
                           goods=goods,
                           ad=ad)
示例#8
0
文件: board.py 项目: argolab/herzog
def board(boardname):
    db = getconn()
    board = getclient().showboard(board=boardname)
    if 'error' in board :
        abort(404)
    userid = getuserid()
    if userid :
        topics = db.query(u"SELECT herzog_topic.tid, owner, title, score, v, lastupdate,"
                          "   lastreply, replynum, partnum, upvote, fromapp, readtime,"
                          "   herzog_topicship.flag, content, upvote, boardname, herzog_topicship.flag as tsflag, readtime FROM herzog_topic"
                          "  LEFT JOIN herzog_topicship"
                          "    ON herzog_topicship.tid=herzog_topic.tid AND userid=%s"
                          "  WHERE boardname=%s"
                          "  ORDER BY score DESC LIMIT 16", userid, boardname)
    else :
        topics = db.query(u"SELECT tid, owner, title, score, v, lastupdate,"
                          "   lastreply, replynum, partnum, upvote, fromapp,"
                          "   flag, content, upvote, boardname FROM herzog_topic"
                          " WHERE boardname=%s ORDER BY score DESC LIMIT 16", boardname)
    if len(topics) == 16 :
        score = topics[-1].score
        del topics[15]
    else :
        score = -1
    bsetting = getbsetting(boardname) or dict()
    print bsetting
    return render_template('board.html', board=board, bsetting=bsetting,
                           topics=topics)
示例#9
0
def logout():
    authed()
    ret = getclient().do_logout()
    if ret.get('success'):
        session.clear()
        return json_success()
    return json_error(4, ret['emsg'])
示例#10
0
文件: fresh.py 项目: argolab/herzog
def index():
    db = getconn()
    topics = db.query(u"SELECT tid, owner, title, score, v, lastupdate,"
                      "   lastreply, replynum, partnum, upvote, fromapp,"
                      "   flag, content, boardname FROM herzog_topic"
                      "  ORDER BY score DESC LIMIT 21")
    if len(topics) == 21 :
        score = topics[-1].score
        del topics[20]
    else :
        score = -1
    boards = getclient().allboards()
    # Filter the topics use a whitelist
    fresh = groupup(topics)
    # TODO : topics may be NONE
    # TODO : perm filter
    # TODO : fresh and topten
    topten = [ dict(title=t.title, tid=t.tid, owner=t.owner)
               for t in topics[:10] ]
    img = hzd.get('page:fresh:image')
    goods = hzd.geta('page:fresh:goods')
    ad = hzd.geto('pgae:fresh:ad')
    return render_template('fresh.html', fresh=fresh, img=img,
                           boards=boards, score=score,
                           topten=topten, goods=goods, ad=ad)
示例#11
0
文件: mail.py 项目: argolab/herzog
def mail():
    userid = authed()
    offset = request.args.get('offset', 1)
    mails = getclient().listmails(offset=offset, limit=20)
    if 'error' in mails :
        return render_template('mailstatus.html', **mails)
    mails['offset'] = int(offset)
    return render_template('mail.html', limit=20, userid=userid, **mails)
示例#12
0
def mail():
    userid = authed()
    offset = request.args.get('offset', 1)
    mails = getclient().listmails(offset=offset, limit=20)
    if 'error' in mails:
        return render_template('mailstatus.html', **mails)
    mails['offset'] = int(offset)
    return render_template('mail.html', limit=20, userid=userid, **mails)
示例#13
0
def sendmail():
    if request.method == 'POST':
        form = getfields(_require=('userid', 'title', 'text'))
        ret = getclient().do_sendmail(userid=form['userid'].encode('utf8'),
                                      title=form['title'].encode('utf8'),
                                      text=form['text'].encode('utf8'))
        return render_template('mailstatus.html', **ret)
    else:
        return render_template('sendmail.html')
示例#14
0
def ajax_login():
    form = getfields(('userid', 'password'))
    print form
    cli = getclient()
    ret = cli.do_login(id=form['userid'], pw=form['password'])
    if ret.get('success'):
        return json_success()
    else:
        return json_error(3, ret['emsg'])
示例#15
0
文件: mail.py 项目: argolab/herzog
def sendmail():
    if request.method == 'POST' :
        form = getfields(_require=('userid', 'title', 'text'))
        ret = getclient().do_sendmail(userid=form['userid'].encode('utf8'),
                                      title=form['title'].encode('utf8'),
                                      text=form['text'].encode('utf8'))
        return render_template('mailstatus.html', **ret)
    else :
        return render_template('sendmail.html')
示例#16
0
def ajax_login():
    form = getfields(('userid', 'password'))
    print form
    cli = getclient()
    ret = cli.do_login(id=form['userid'], pw=form['password'])
    if ret.get('success') :
        return json_success()
    else :
        return json_error(3, ret['emsg'])
示例#17
0
文件: board.py 项目: argolab/herzog
def allboards():
    boards = getboards()
    sections = groupup(boards)
    bs = get_all_bsetting()
    if authed() :
        msg = getclient().getmessage()
    else :
        msg = None
    return render_template('allboards.html', secdatas=secdatas,
                           boards=boards, sections=sections, bs=bs, msg=msg)
示例#18
0
文件: mail.py 项目: argolab/herzog
def replymail(filename):
    if request.method == 'POST' :
        form = getfields(_require=('userid', 'title', 'text', 'filenum'))
        ret = getclient().do_sendmail(userid=form['userid'].encode('utf8'),
                                      title=form['title'].encode('utf8'),
                                      filenum=form['filenum'],
                                      text=form['text'].encode('utf8'))
        return render_template('mailstatus.html', **ret)
    else :
        try:
            index = int(request.args.get('num'))
        except ValueError :
            return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
        mail = getclient().showmail(start=index)
        if mail.get('filename') == filename :
            title = quote_title(mail['title'])
            return render_template('replymail.html', title=title, index=index, mail=mail)
        else :
            return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')            
示例#19
0
文件: mail.py 项目: argolab/herzog
def readmail(filename) :
    try:
        index = int(request.args.get('index'))
    except ValueError :
        return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
    mail = getclient().showmail(start=index)
    if mail.get('filename') == filename :
        mail['content'] = filter_ansi(open(getbbsfile(mail['@article']),
                                           encoding='gbk', errors='ignore').read())
        return render_template('readmail.html', index=index, mail=mail)
    else :
        return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
示例#20
0
def replymail(filename):
    if request.method == 'POST':
        form = getfields(_require=('userid', 'title', 'text', 'filenum'))
        ret = getclient().do_sendmail(userid=form['userid'].encode('utf8'),
                                      title=form['title'].encode('utf8'),
                                      filenum=form['filenum'],
                                      text=form['text'].encode('utf8'))
        return render_template('mailstatus.html', **ret)
    else:
        try:
            index = int(request.args.get('num'))
        except ValueError:
            return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
        mail = getclient().showmail(start=index)
        if mail.get('filename') == filename:
            title = quote_title(mail['title'])
            return render_template('replymail.html',
                                   title=title,
                                   index=index,
                                   mail=mail)
        else:
            return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
示例#21
0
def readmail(filename):
    try:
        index = int(request.args.get('index'))
    except ValueError:
        return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
    mail = getclient().showmail(start=index)
    if mail.get('filename') == filename:
        mail['content'] = filter_ansi(
            open(getbbsfile(mail['@article']), encoding='gbk',
                 errors='ignore').read())
        return render_template('readmail.html', index=index, mail=mail)
    else:
        return render_template('mailstatus.html', error=1, emsg=u'没有该邮件')
示例#22
0
def update2fs(userid, tid, title, content, **ps):
    db = getconn()
    topic = db.get(u"SELECT boardname, oldfilename FROM herzog_topic"
                   "  WHERE tid=%s", tid)
    if not topic :
        raise HZActionError('No such topic')
    r = getclient().do_edit(board=topic.boardname,
                            title=title.encode('utf8'),
                            text=content.encode('utf8'),
                            file=topic.oldfilename)
    if r.has_key('error') :
        raise HZActionError(r['emsg'])
    return True
示例#23
0
def allboards():
    boards = getboards()
    sections = groupup(boards)
    bs = get_all_bsetting()
    if authed():
        msg = getclient().getmessage()
    else:
        msg = None
    return render_template('allboards.html',
                           secdatas=secdatas,
                           boards=boards,
                           sections=sections,
                           bs=bs,
                           msg=msg)
示例#24
0
def update2fs_reply(userid, rid, content, **ps) :
    db = getconn()
    reply = db.get(u"SELECT tid, oldfilename FROM herzog_reply"
                   "  WHERE rid=%s", rid)
    if not reply :
        raise HZActionError('No such reply')
    topic = db.get(u"SELECT boardname FROM herzog_topic"
                   "  WHERE tid=%s", reply.tid)
    if not topic :
        raise HZActionError("No such topic")
    header, _, quote, tail = getfspost(topic.boardname,
                                       reply.oldfilename)
    r = getclient().do_edit(board=topic.boardname,
                            title=header['title'].decode('gbk').encode('utf8'),
                            text=content.encode('utf8'),
                            file=reply.oldfilename)
    if r.has_key('error') :
        raise HZActionError(r['emsg'])
    return True
示例#25
0
文件: mail.py 项目: argolab/herzog
def ajax_delmail():
    form = getfields(_require=('filenum', 'filename'))
    ret = getclient().do_delmail(filenum=form['filenum'],
                                 filename=form['filename'])
    return jsonify(**ret)
示例#26
0
def ajax_delmail():
    form = getfields(_require=('filenum', 'filename'))
    ret = getclient().do_delmail(filenum=form['filenum'],
                                 filename=form['filename'])
    return jsonify(**ret)
示例#27
0
文件: user.py 项目: argolab/herzog
def user(userid):
    user = getclient().queryuser(userid=userid)
    if '@plans' in user :
        user['plans'] = read_bbsfile(user['@plans'])
    return render_template('query_user.html', user=user)
示例#28
0
def user(userid):
    user = getclient().queryuser(userid=userid)
    if '@plans' in user:
        user['plans'] = read_bbsfile(user['@plans'])
    return render_template('query_user.html', user=user)