def ListFavBoards(svc, session, params): start = Util.GetInt(params, 'start') end = Util.GetInt(params, 'end') count = Util.GetInt(params, 'count') father = Util.GetInt(params, 'father', -1) fboards = FavBoardMgr.LoadFavBoards(session.GetUser().name) if fboards == None: raise ServerError("failed to load fav boards") fboards.LoadFavBoards() start, end = Util.CheckRange(start, end, count, DEFAULT_LIST_FAVBOARD_COUNT, fboards._count) if (start <= end) and (start >= 1) and (end <= fboards._count): first = True result = '[\n' for index in range(0, fboards._count): fboard = fboards._favboards[index] if fboard.Exists(): if fboard._father == father: if not first: result += ',\n' first = False result += fboard.GetInfoJSON(index, session.GetUser()) result += '\n]' svc.writedata(result) return else: raise WrongArgs('invalid arguments')
def GetPostList(self, svc, session, params): """ handle board/post_list List posts in this board in mode 'mode'. Start listing from post #'start', till post #'end', return at most 'count' posts. """ mode = Util.GetString(params, 'mode', 'normal') start = Util.GetInt(params, 'start') end = Util.GetInt(params, 'end') count = Util.GetInt(params, 'count') allow_empty = not start and not end if (mode == 'normal'): total = self.status.total else: total = self.PostCount(mode) start, end = Util.CheckRange(start, end, count, DEFAULT_GET_POST_COUNT, total) if ((start <= end) and (start >= 1) and (end <= total)): bread = BRead.BReadMgr.LoadBRead(session.GetUser().name) if (bread != None): bread.Load(self.name) if (mode == 'normal' or mode == 'digest' or mode == 'mark' or mode == 'sticky' or mode == 'thread' or mode == 'origin'): dirf = open(self.GetDirPath(mode), 'rb') post = {} first = True result = '[\n' for i in range(start - 1, end): pe = self.GetPostEntry(i, mode, dirf) if (pe is None): continue if (not first): result += ',\n' first = False post = pe.GetInfoExtended(session.GetUser(), self, 'post') post['id'] = i + 1 read = True if (bread != None): read = not bread.QueryUnread(pe.id, self.name) post['read'] = read # post['filename'] = pe.filename result += json.dumps(post, 'utf-8') result += '\n]' svc.writedata(result) dirf.close() else: if allow_empty: svc.writedata('[]') else: raise OutOfRange('out of range') return
def List(user, folder, start, count, end): mbox = mailbox.MailBox(user.GetName()) folder = mbox.get_folder(folder) total = folder.count() start, end = Util.CheckRange(start, end, count, DEFAULT_MAIL_VIEW_COUNT, total) if (start <= end and start >= 1 and end <= total): result = '{ "start": %d, "end": %d, "mails": [\n' % (start, end) first = True for i in range(start - 1, end): entry = folder.get_entry(i) if entry is None: continue if not first: result += ',\n' post = entry.GetInfo('mail') post['id'] = i + 1 result += json.dumps(post) first = False result += '\n]}' return result else: raise OutOfRange('out of range')