Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add some ajax interface

  • Loading branch information...
commit edd5626d01430dbc96ed3e1741aa5263fc4deee5 1 parent 15c1384
@LTaoist LTaoist authored
View
9 README.md
@@ -51,6 +51,12 @@ Dependencies
其中jinja2目前被telnet端使用,可能会被web端使用。
+!!! redis版本应该在2.4以上!
+
+```bash
+redis -v
+```
+
Install
-------
@@ -134,3 +140,6 @@ python server.py
`mrg.userperm.init_user_team`, `init_boardteam``model.Model.foreach`可以
对SQL进行一些简单的迭代,不过仅是测试或许直接重新建造更方便。
+!!! redis
+ubuntu 2.4的ppa
+https://launchpad.net/~chris-lea/+archive/redis-server/+index#
View
14 model/Model.py
@@ -644,8 +644,11 @@ def select_attr(self,userid,sql_what):
return self.db.get("SELECT %s FROM `%s` WHERE userid = %%s" % (sql_what, self.__),
userid)
- def user_exist(self, userid):
- return True
+ def safe_userid(self, userid):
+ res = self.db.get("SELECT userid FROM `%s` "
+ "WHERE userid=%%s" % self.__,
+ userid)
+ return res and res['userid']
class Status(Model):
@@ -811,6 +814,13 @@ def get_mail(self, userid, start, limit):
"ORDER BY mid "
"LIMIT %%s,%%s" % (self._index_table), userid,
start, limit)
+
+ def get_mail_simple(self, userid, start, limit):
+ return self.db.query("SELECT title,mid FROM `%s` "
+ "WHERE touserid=%%s "
+ "ORDER BY mid "
+ "LIMIT %%s,%%s" % (self._index_table), userid,
+ start, limit)
def get_mid_rank(self, touserid, mid):
return self.db.get('SELECT count(*) as sum '
View
27 web/board.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
import tornado.web
from lib import BaseHandler, manager
@@ -34,3 +37,27 @@ def get(self, boardname, rank=None):
board['httpbg'] = "http://ww3.sinaimg.cn/large/6b888227jw1dwesulldlyj.jpg"
self.srender('board.html', board=board, rank=rank, maxrank=maxrank,
posts=posts, vistors=vistors)
+
+class AjaxBookBoardHandler(BaseHandler):
+
+ def get(self, boardname):
+ userid = self.get_current_user()
+ if userid is None:
+ self.write({
+ "success": False,
+ "content": u"未登录用户.",
+ })
+ return
+ board = manager.board.get_board(boardname)
+ if not board :
+ self.write({
+ "success": False,
+ "content": u"没有该版块."
+ })
+ return
+ boardname = board.boardname
+ manager.favourite.add(userid, boardname)
+ return self.write({
+ "success": True,
+ "msg": u"预定成功!",
+ })
View
104 web/mail.py
@@ -0,0 +1,104 @@
+from lib import BaseHandler, manager
+import tornado.web
+
+class MailHandler(BaseHandler):
+
+ page_size = 10
+
+ def get(self, start = 0):
+ userid = self.get_current_user()
+ if not userid :
+ self.login_page()
+
+ start = int(start) or 0
+ total = manager.mail.get_mail_total(userid)
+
+ if start == 0:
+ start = total - self.page_size
+ if start < 0 :
+ start = 0
+
+ maillist = manager.mail.get_mail_simple(userid, start, self.page_size)
+ self.write({
+ "success":True,
+ "content":maillist,
+ })
+
+class AjaxAddMailHandler(BaseHandler):
+
+ def get(self):
+ self.srender("add_mail")
+
+ def post(self):
+ userid = self.get_current_user()
+ if not userid :
+ self.login_page()
+ return
+ touserid = manager.userinfo.safe_userid(self.get_argument("touserid"))
+ if not touserid :
+ self.write({
+ "success":False,
+ "content":u"错误的收件人。",
+ })
+ return
+ title=self.get_argument("title", None),
+ if not title :
+ self.write({
+ "success":False,
+ "content":u"必须有标题!",
+ })
+ return
+ manager.action.send_mail(
+ fromuserid=userid, touserid=touserid,
+ content=self.get_argument("text"), title=title,
+ fromaddr=self.request.remote_ip, signature=signature
+ )
+ self.write({
+ "success":True,
+ "content":"发送邮件成功!",
+ })
+
+class AjaxReplyMailHandler(BaseHandler):
+
+ def get(self, mid):
+ userid = self.get_current_user()
+ if not userid :
+ self.login_page()
+ return
+ mail = manager.mail.one_mail(mid)
+ if not mail or mail.touserid != userid :
+ self.write({
+ "success":False,
+ "content":"没有该邮件!",
+ })
+ return
+ title = mail.title if mail.title.startswith('Re: ') \
+ else 'Re: %s' % mail.title
+ content = fun_gen_quote(mail.owner, mail.content)
+ self.write({
+ "title": title,
+ "content" : content,
+ })
+
+ def post(self, mid):
+ userid = self.get_current_user()
+ if not userid :
+ self.login_page()
+ return
+ mail = manager.mail.one_mail(mid)
+ if not mail or mail.touserid != userid :
+ self.write({
+ "success":False,
+ "content":"没有该邮件!",
+ })
+ return
+ manager.action.reply_mail(userid,
+ self.get_argument('replymid'),
+ content=self.get_argument('content'),
+ title=self.get_argument('title'),
+ fromaddr=self.request.remote_ip)
+ self.write({
+ "success":True,
+ "content":"回复邮件成功!",
+ })
+
View
2  web/post.py
@@ -38,7 +38,7 @@ def get(self, replyid):
raise tornado.web.HTTPError(404)
if not self.get_current_user():
raise tornado.web.HTTPError(404)
- default = fun_gen_quote(self.get_current_user(), post.content)
+ default = fun_gen_quote(post.owner, post.content)
title = post.title if post.title.startswith('Re:') \
else 'Re: %s' % post.title
self.srender("replypost.html", post=post, title=title,
View
7 web/server.py
@@ -22,6 +22,7 @@ def __init__(self, handlers, **settings):
self.ch = globaldb.global_cache
urls = [
+
(r"/", import_handler("index", "IndexHandler")),
(r"/account/login", import_handler("index", "LoginHandler")),
(r'/account/logout', import_handler('index', 'LogoutHandler')),
@@ -31,12 +32,18 @@ def __init__(self, handlers, **settings):
(r'/post/add/(\w{1,40})', import_handler('post', 'NewPostHandler')),
(r'/notify', import_handler('user', 'NoticeHandler')),
+ (r'/a/get_maillist/(\d{1,4})', import_handler('mail', 'MailHandler')),
+ (r'/a/add_mail', import_handler('mail', 'AjaxAddMailHandler')),
+ (r'/a/reply_mail', import_handler('mail', 'AjaxReplyMailHandler')),
+
(r"/a/checkmail/?", import_handler("comm_ajax","CommAjaxCheckMailHandler")),
(r"/a/mail/(\d{1,10})/?", import_handler("comm_ajax","CommAjaxGetMailHandler")),
(r"/a/board/(\d{1,2})/?", import_handler("comm_ajax","CommAjaxGetBoardHandler")),
(r"/a/(\w{2,16})/(\d{1,10})/?", import_handler("comm_ajax","CommAjaxGetPostHandler")),
(r"/a/(\w{2,16})/quote/(\d{1,10})/?", import_handler("comm_ajax","CommAjaxGetQuoteHandler")),
(r"/a/(\w{2,16})/post/?", import_handler("comm_ajax", "CommAjaxNewPostHandler")),
+ (r"/a/book_board/(\w{2,16})", import_handler("board", "AjaxBookBoardHandler")),
+
# mobile
(r"/m/?$", import_handler("mobile.m_main","MobileIndexHandler")),
View
2  web/template/board.html
@@ -36,7 +36,7 @@
<p>{{ board['about'] }}</p>
</div>
<img class="img-rounded" src="{{ board['httpbg'] }}"/>
- <a id="board-head-bookbtn" class="btn btn-mini pull-right btn-info">收藏该版</a>
+ <a id="board-head-bookbtn" href="/board/{{ board.boardname }}/book" class="btn btn-mini pull-right btn-info">收藏该版</a>
</div>
{% end %}
View
27 web/template/mail.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+
+{% block main %}
+<div class="cell">
+ <div class="btn-toolbar">
+ <a href="/mail/add" class="btn btn-small btn-success">写信</a>
+ </div>
+ <table class="mailtable table table-hover table-condensed" width="100%">
+ <thead>
+ <tr>
+ <th width="auto">标题</th>
+ <th width="20%">发信人</th>
+ <th width="20%">最后更新</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for li in mails %}
+ <tr{% if li.readmark %} class="read"{% end %}>
+ <td><a href="/mail/{{ li.tid }}">{{ li.title }}</a></td>
+ <td><a href="/user/{{ li.fromuserid }}">{{ li.fromuserid }}</td>
+ <td>{{ li.lastupdate }}</td>
+ </tr>
+ {% end %}
+ </tbody>
+ </table>
+</div>
+{% end %}
View
1  web/template/post.html
@@ -2,6 +2,7 @@
{% block main %}
<div class="cell-group">
+ <a class="pull-left" href="/board/{{ board.boardname }}/">« 回到 {{ board.boardname }} 版</a>
{% module PostNav(firstpid, prevpid, nextpid, lastpid, post.pid) %}
<div class="post-wrapper">
<div class="post-head">
Please sign in to comment.
Something went wrong with that request. Please try again.