From a8f8d3cbb89d368c21c0406273f7ac5dd9877f18 Mon Sep 17 00:00:00 2001 From: cypress Date: Sat, 6 Oct 2012 21:38:24 +0800 Subject: [PATCH] modify to Model --- web/comm/ajax.py | 10 +++--- web/mobile/m_main.py | 80 +++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/web/comm/ajax.py b/web/comm/ajax.py index 89fb04f..f7e10cb 100644 --- a/web/comm/ajax.py +++ b/web/comm/ajax.py @@ -25,7 +25,7 @@ def get(self, boardname, pid): #todo: if userid has read perm - post = mgr.post.get_post(boardname, pid) + post = mgr.post.get_post(pid) result['success'] = True if post: @@ -58,14 +58,14 @@ def get(self, boardname, pid): return self.write(result) # todo: if userid has read perm - post = mgr.post.get_post(boardname, pid) + post = mgr.post.get_post(pid) if not post: result['success'] = False result['content'] = u'本帖子不存在或者已被删除' return self.write(result) - quote = fun_gen_quote(post['userid'], post['content']) + quote = fun_gen_quote(post['owner'], post['content']) content = post['content'] result['success'] = True @@ -97,7 +97,7 @@ def post(self, boardname): addr = self.remote_ip,\ host = 'TestLand',\ replyid = replyid) - if res: + if res: result['success'],result['conent'] = True, u'发表成功' else: result['success'],result['conent'] = False, u'发表失败' @@ -113,7 +113,7 @@ def get(self, mid): if not self.userid: self.login_page() result = {} uid = mgr.userinfo.name2id(self.userid) - mail = mgr.mail.one_mail(uid, mid) + mail = mgr.mail.one_mail(mid) if mail: result['success'] = True diff --git a/web/mobile/m_main.py b/web/mobile/m_main.py index 36a393d..986f782 100644 --- a/web/mobile/m_main.py +++ b/web/mobile/m_main.py @@ -67,23 +67,25 @@ class MobilePostHandler(MobileBaseHandler): page_size = 25 - def get(self, boardname, startpid = 0): - board = None if not boardname.isalpha() else mgr.board.get_board(boardname) - if not board: - return m_error(self, u'版面不存在') + def get(self, boardname, start = 0): - startpid = int(startpid) if startpid else 0 + if not boardname.isalpha(): + return m_error(self, u'版面不存在') + board = mgr.board.get_board(boardname) + bid = mgr.board.name2id(boardname) + total = mgr.post.get_posts_total(bid) + + start = int(start) if start else 0 + # todo: if has_read_perm + self.page_size = self.__class__.page_size - if startpid == 0: # 0 means the last pid - startpid = mgr.board.get_posts_total(boardname) - self.page_size = -self.page_size - elif startpid < 0: - startpid = -startpid - self.page_size = -self.page_size + if start == 0: # 0 means the last pid + start = total - self.page_size + if start < 0: start = 0 - plist = mgr.post.get_posts(boardname, startpid, self.page_size) + plist = mgr.post.get_posts(bid, start, self.page_size) for p in plist: p.unread = 1 if mgr.readmark.is_read(self.userid, \ @@ -91,14 +93,12 @@ def get(self, boardname, startpid = 0): self._tpl['plist'] = plist self._tpl['board'] = board - empty = not len(plist) > 0 - prev = None if empty \ - else (mgr.post.prev_post_pid(boardname, plist[0].pid)) - if prev is not None: prev = -prev + prev = start - self.page_size + if prev < 0: prev = None - next = None if empty \ - else mgr.post.next_post_pid(boardname, plist[-1].pid) + next = start + self.page_size + if next > total: next = None self._tpl['prev'] = prev self._tpl['next'] = next @@ -149,11 +149,13 @@ def get(self, boardname, pid): m_error(self, u'错误的讨论区') # todo: if has read perm - post = mgr.post.get_post(boardname, pid) + post = mgr.post.get_post(pid) if not post: m_error(self, u'本帖子不存在或已被删除') tid = post.tid - plist = mgr.post.get_posts_onetopic(tid, boardname, None, None) + bid = mgr.board.name2id(boardname) + total = mgr.post.get_posts_topic_total(bid) + plist = mgr.post.get_posts_onetopic(tid, bid, 0, total) self._tpl['board'] = board self._tpl['plist'] = plist @@ -170,7 +172,8 @@ def get(self): for boardname in all_fav] for b in boards: pid = mgr.post.get_last_pid(b.boardname) - b.unread = not mgr.readmark.is_read(self.userid, b.boardname, pid) + if pid is None: pid = -1 + b.unread = not mgr.readmark.is_read(self.userid, b.boardname, pid) self._tpl['boards'] = boards self.mrender('m_fav.html') @@ -178,30 +181,26 @@ def get(self): class MobileMailHandler(MobileBaseHandler): page_size = 5 - def get(self, startmid = 0): + def get(self, start = 0): if not self.userid: self.login_page() - startmid = int(startmid) if startmid else 0 + start = int(start) if start else 0 + total = mgr.mail.get_mail_total(self.userid) - if startmid == 0: # 0 means the last pid - startmid = 0 - self.page_size = -self.page_size - elif startmid < 0: - startmid = -startmid - self.page_size = -self.page_size + if start == 0: # 0 means the last pid + start = total - self.page_size + if start < 0: start = 0 - mlist = mgr.mail.get_mail(self.userid, startmid, self.page_size) + mlist = mgr.mail.get_mail(self.userid, start, self.page_size) self._tpl['mlist'] = mlist - empty = not len(mlist) > 0 - prev = None if empty \ - else (mgr.mail.prev_mail_mid(mlist[0].mid)) - if prev is not None: prev = -prev + prev = start - self.page_size + if prev < 0: prev = None - next = None if empty \ - else mgr.mail.next_mail_mid(mlist[-1].mid) + next = start + self.page_size + if next > total: next = None self._tpl['prev'] = prev self._tpl['next'] = next @@ -228,8 +227,7 @@ def post(self, startmid = 0): content = content,\ fromaddr = self.remote_ip) else: - uid = mgr.userinfo.name2id(self.userid) - old_mail = mgr.mail.one_mail(uid, replyid) + old_mail = mgr.mail.one_mail(replyid) res = mgr.action.reply_mail(self.userid,\ old_mail,\ title = title,\ @@ -246,12 +244,12 @@ def get(self, replyid = 0): if not self.userid: self.login_page() replyid = int(replyid) if replyid else 0 - uid = mgr.userinfo.name2id(self.userid) + uid = mgr.userinfo.name2id(self.userid) mail = {} if replyid != 0: - old_mail = mgr.mail.one_mail(uid, replyid) - if old_mail.title[:3] != 'Re:': + old_mail = mgr.mail.one_mail(replyid) + if old_mail.title[:3] != 'Re:': old_mail.title ='Re:' + old_mail.title mail['title'] = old_mail.title mail['touserid'] = old_mail.fromuserid