Permalink
Browse files

finish mail.html

  • Loading branch information...
1 parent edd5626 commit b3f0fe08a183edcce44e19224793785acbb2cd9c @LTaoist LTaoist committed Oct 12, 2012
View
@@ -302,25 +302,29 @@ def init_user_favourite(self, userid):
self.ch.delete(key)
self.ch.sunionstore(key, self.keyf % self.default_userid)
- def add(self, userid, boardname):
+ def add(self, userid, bid):
u''' Add an board into user's favourtie.'''
key = self.keyf % userid
- self.ch.sadd(key, boardname)
+ self.ch.sadd(key, bid)
- def remove(self, userid, boardname):
+ def remove(self, userid, bid):
key = self.keyf % userid
- self.ch.srem(key, boardname)
+ self.ch.srem(key, bid)
def get_all(self, userid):
u'''Return a set holds all board's name in user's favourite.'''
key = self.keyf % userid
return self.ch.smembers(key)
- def add_default(self, boardname):
- self.add(self.default_userid, boardname)
+ def is_fav(self, userid, bid):
+ key = self.keyf % userid
+ return self.ch.sismember(key, bid)
+
+ def add_default(self, bid):
+ self.add(self.default_userid, bid)
- def remove_default(self, boardname):
- self.remove(self.default_userid, boardname)
+ def remove_default(self, bid):
+ self.remove(self.default_userid, bid)
class Post(Model):
@@ -620,6 +624,12 @@ class UserInfo(Model):
def get_user(self,name):
return self.table_get_by_key(self.__, 'userid', name)
+ def get_avatar(self, userid):
+ res = self.db.get("SELECT iconidx FROM %s "
+ "WHERE userid=%%s" % self.__,
+ userid)
+ return res and res['iconidx']
+
def add_user(self,**kwargs):
return self.table_insert(self.__, kwargs)
@@ -816,7 +826,7 @@ def get_mail(self, userid, start, limit):
start, limit)
def get_mail_simple(self, userid, start, limit):
- return self.db.query("SELECT title,mid FROM `%s` "
+ return self.db.query("SELECT title,mid,sendtime,readmark FROM `%s` "
"WHERE touserid=%%s "
"ORDER BY mid "
"LIMIT %%s,%%s" % (self._index_table), userid,
@@ -829,6 +839,14 @@ def get_mid_rank(self, touserid, mid):
'ORDER BY mid' % self._index_table,
mid, touserid)['sum']
+ def get_first_unread(self, touserid):
+ return self.db.get('SELECT count(*) '
+ 'FROM `%s` '
+ 'WHERE mid < ( '
+ ' SELECT mid FROM `%s` WHERE touserid=%%s '
+ ' AND readmark=0 ORDER BY mid LIMIT 1 )' % (\
+ self._index_table, self._index_table), touserid)['count(*)']
+
def rank2mid(self, touserid, rank):
res = self.db.get("SELECT mid "
"WHERE touser=%%s ORDER BY mid "
@@ -894,6 +912,12 @@ def update_mail(self, mid, **kwargs):
return self.table_update_by_key(self._index_table, 'mid', mid, kwargs)
def set_read(self, uid, mid):
+ # old version that need to be clean
+ sql = "UPDATE `%s` SET readmark = readmark | 1 WHERE mid = %%s" %\
+ self._index_table
+ self.db.execute(sql, mid)
+
+ def set_mail_read(self, mid):
sql = "UPDATE `%s` SET readmark = readmark | 1 WHERE mid = %%s" %\
self._index_table
self.db.execute(sql, mid)
@@ -1077,7 +1101,6 @@ def clear_unread(self, userid, boardname, last):
key = self.keyf%(userid,boardname)
self.ch.delete(key)
self.ch.zadd(key, last, last)
- print ('clear', last)
def get_first_read(self, userid, boardname):
d = self.ch.zrange(self.__(userid, boardname), 0, 0)
View
@@ -141,9 +141,7 @@ class ReadMailFrame(BaseMailListFrame):
]
def get_mid_rank(self, mid):
- return self.MODE_RANKER[self.mode](self.session.user['uid'],
- self.userid,
- mid)
+ return self.MODE_RANKER[self.mode](self.userid, mid)
def initialize(self, mode=0):
manager.status.set_status(self.seid,
@@ -278,10 +276,12 @@ def initialize(self, touserid=None):
self.writeln(u'取消写信!')
self.pause()
self.goto_back()
- if not manager.userinfo.get_user(touserid):
+ touser = manager.userinfo.get_user(touserid)
+ if not touser :
self.writeln(u'无法找到该收信人!')
self.pause()
self.goto_back()
+ touserid = touser.userid
self.touserid = touserid
sign_num = manager.usersign.get_sign_num(self.userid)
self.attrs = self.read_attrs(touserid, sign_num)
View
@@ -6,28 +6,25 @@
class BoardHandler(BaseHandler):
+ page_size = 30
+
def get(self, boardname, rank=None):
board = manager.board.get_board(boardname)
if not board:
raise tornado.web.HTTPError(404)
boardname = board.boardname
- maxrank = max(0, manager.post.get_post_total(board['bid']) - 3)
- if rank is not None:
+ maxrank = max(0, manager.post.get_post_total(board['bid']))
+ if rank is None:
+ rank = maxrank // self.page_size * self.page_size
+ else :
rank = int(rank)
- posts = manager.post.get_posts(board['bid'], rank, 30)
- elif self.get_current_user() :
- userid = self.get_current_user()
- lastread = manager.readmark.get_first_read(userid, boardname) or 0
- lastread = manager.post.prev_three_post(board.bid, lastread) or 0
- posts = manager.post.get_posts_after_pid(
- board.bid, lastread, 30)
- rank = manager.post.get_rank_num(board.bid, lastread)
- else:
- rank = maxrank
- posts = manager.post.get_posts(board['bid'], rank, 30)
+ posts = manager.post.get_posts(board['bid'], rank, self.page_size)
if self.get_current_user() :
userid = self.get_current_user()
manager.readmark.wrapper_post_with_readmark(posts, boardname, userid)
+ isfav = manager.favourite.is_fav(userid, board.bid)
+ else:
+ isfav = None
vistors = (
("LTaoist", "2012-03-04"),
("gcc", "2012-01-09"),
@@ -36,7 +33,8 @@ def get(self, boardname, rank=None):
board['bm'] = board['bm'] and board['bm'].split(':')
board['httpbg'] = "http://ww3.sinaimg.cn/large/6b888227jw1dwesulldlyj.jpg"
self.srender('board.html', board=board, rank=rank, maxrank=maxrank,
- posts=posts, vistors=vistors)
+ posts=posts, vistors=vistors, isfav=isfav,
+ page_size=self.page_size)
class AjaxBookBoardHandler(BaseHandler):
@@ -55,9 +53,8 @@ def get(self, boardname):
"content": u"没有该版块."
})
return
- boardname = board.boardname
- manager.favourite.add(userid, boardname)
+ manager.favourite.add(userid, board.bid)
return self.write({
"success": True,
- "msg": u"预定成功!",
+ "content": u"预定成功!",
})
View
@@ -105,9 +105,9 @@ def get(self, mid):
uid = mgr.userinfo.name2id(self.userid)
mail = mgr.mail.one_mail(mid)
- if mail:
+ if mail and (mail.touserid == self.userid):
result['success'] = True
- mgr.mail.set_read(uid, mid)
+ mgr.mail.set_mail_read(mid)
for k,v in mail.items():
try:
v = str(v)
View
@@ -35,7 +35,7 @@ def url_for_avatar(userid):
Return the avatar url for userid.
NOT IMPLEMENTED YET.
'''
- return "/static/img/avatar/%s" % userid
+ return manager.userinfo.get_avatar(userid) or "/static/img/avatar_default.jpg"
func = SDict([
("url_for_avatar", url_for_avatar),
@@ -106,6 +106,11 @@ def timeformat(time):
'''
return time.strftime("%d-%m")
+def shorttime(time):
+ '''
+ Better and short outlook for time.
+ '''
+ return time.strftime('%d-%m')
def fun_gen_quote(userid, content):
'''
View
@@ -1,33 +1,61 @@
-from lib import BaseHandler, manager
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from lib import BaseHandler, manager, url_for_avatar, timeformat, fun_gen_quote
import tornado.web
class MailHandler(BaseHandler):
- page_size = 10
+ def get(self):
+ self.srender('mail.html')
+
+class AjaxMailListHandler(BaseHandler):
- def get(self, start = 0):
+ page_size = 20
+
+ def get(self, start = None):
userid = self.get_current_user()
if not userid :
- self.login_page()
+ self.write({
+ "success": False,
+ "content": "未认证用户!",
+ })
+ return
- start = int(start) or 0
total = manager.mail.get_mail_total(userid)
+ if start is None:
+ start = manager.mail.get_first_unread(userid)
+ if start == 0 :
+ start = total
+ start = start // 20 * 20
+ else:
+ start = int(start)
- if start == 0:
+ if start > total:
+ self.write({
+ "success": False,
+ "content": "没有新的数据!",
+ })
+ return
+
+ if (start < 0) :
start = total - self.page_size
if start < 0 :
start = 0
maillist = manager.mail.get_mail_simple(userid, start, self.page_size)
+ for li in maillist :
+ li['sendtime'] = timeformat(li['sendtime'])
self.write({
- "success":True,
- "content":maillist,
+ "success": True,
+ "content": maillist,
+ "start": start,
})
class AjaxAddMailHandler(BaseHandler):
def get(self):
- self.srender("add_mail")
+ self.render('addmail.html')
def post(self):
userid = self.get_current_user()
@@ -41,13 +69,18 @@ def post(self):
"content":u"错误的收件人。",
})
return
- title=self.get_argument("title", None),
+ title = self.get_argument("title", None)
if not title :
self.write({
"success":False,
"content":u"必须有标题!",
})
return
+ signnum = self.get_argument('signnum', None)
+ if signnum is None or signnum < manager.usersign.get_sign_num(userid):
+ signature = ''
+ else:
+ signature = manager.usersign.get_sign(userid, signnum)
manager.action.send_mail(
fromuserid=userid, touserid=touserid,
content=self.get_argument("text"), title=title,
@@ -74,16 +107,16 @@ def get(self, mid):
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,
- })
+ content = fun_gen_quote(mail.fromuserid, mail.content)
+ self.render('replymail.html', title=title, content=content, mid=mid)
def post(self, mid):
userid = self.get_current_user()
if not userid :
- self.login_page()
+ self.write({
+ "success": False,
+ "content": "未认证用户!",
+ })
return
mail = manager.mail.one_mail(mid)
if not mail or mail.touserid != userid :
@@ -92,13 +125,46 @@ def post(self, mid):
"content":"没有该邮件!",
})
return
- manager.action.reply_mail(userid,
- self.get_argument('replymid'),
+ signnum = self.get_argument('signnum', None)
+ if signnum is None or signnum < manager.usersign.get_sign_num(userid):
+ signature = ''
+ else:
+ signature = manager.usersign.get_sign(userid, signnum)
+ manager.action.reply_mail(userid, mail,
content=self.get_argument('content'),
title=self.get_argument('title'),
- fromaddr=self.request.remote_ip)
+ fromaddr=self.request.remote_ip,
+ signature=signature)
self.write({
"success":True,
"content":"回复邮件成功!",
})
-
+
+class AjaxGetMailHandler(BaseHandler):
+
+ def get(self, mid):
+ userid = self.get_current_user()
+ if not userid :
+ self.write({
+ "success":False,
+ "content":"没有登录",
+ })
+ return
+ mail = manager.mail.one_mail(mid)
+ if mail and (mail.touserid == userid):
+ manager.mail.set_mail_read(mid)
+ self.write({
+ "success":True,
+ "UserAvatar": url_for_avatar(mail.fromuserid),
+ "Title": mail.title,
+ "Userid": mail.fromuserid,
+ "Content": mail.content,
+ "Sendtime": timeformat(mail.sendtime),
+ "Signature": mail.signature,
+ "Mid": mail.mid,
+ })
+ return
+ self.write({
+ "success":False,
+ "content":"没有该邮件!",
+ })
Oops, something went wrong.

0 comments on commit b3f0fe0

Please sign in to comment.