def GET(self): form = web.input(count=0, backtime=0, nexttime=0) try: count = int(form.count) backtime = int(form.backtime) nexttime = int(form.nexttime) except ValueError: web.ctx.status = '422 Unprocessable Entity' return json.dumps(_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = message.select_submissions( self.user_id, count + 1, backtime=backtime, nexttime=nexttime) backtime, nexttime = d.paginate(submissions, backtime, nexttime, count, 'unixtime') ret = [] for sub in submissions: tidy_submission(sub) ret.append(sub) return json.dumps({ 'backtime': backtime, 'nexttime': nexttime, 'submissions': ret, })
def api_messages_submissions_(request): form = request.web_input(count=0, backtime=0, nexttime=0) try: count = int(form.count) backtime = int(form.backtime) nexttime = int(form.nexttime) except ValueError: raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = message.select_submissions(request.userid, count + 1, include_tags=True, backtime=backtime, nexttime=nexttime) backtime, nexttime = d.paginate(submissions, backtime, nexttime, count, 'unixtime') ret = [] for sub in submissions: tidy_submission(sub) ret.append(sub) return { 'backtime': backtime, 'nexttime': nexttime, 'submissions': ret, }
def api_user_gallery_(request): userid = profile.resolve_by_login(request.matchdict['login']) if not userid: raise WeasylError('userRecordMissing') form = request.web_input(since=None, count=0, folderid=0, backid=0, nextid=0) since = None try: if form.since: since = d.parse_iso8601(form.since) count = int(form.count) folderid = int(form.folderid) backid = int(form.backid) nextid = int(form.nextid) except ValueError: raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = submission.select_list( request.userid, d.get_rating(request.userid), count + 1, otherid=userid, folderid=folderid, backid=backid, nextid=nextid) backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid') ret = [] for sub in submissions: if since is not None and since >= sub['unixtime']: break tidy_submission(sub) ret.append(sub) return { 'backid': backid, 'nextid': nextid, 'submissions': ret, }
def api_user_gallery_(request): userid = profile.resolve_by_login(d.get_sysname(request.matchdict['login'])) if not userid: raise WeasylError('userRecordMissing') form = request.web_input(since=None, count=0, folderid=0, backid=0, nextid=0) since = None try: if form.since: since = d.parse_iso8601(form.since) count = int(form.count) folderid = int(form.folderid) backid = int(form.backid) nextid = int(form.nextid) except ValueError: raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = submission.select_list( request.userid, d.get_rating(request.userid), count + 1, otherid=userid, folderid=folderid, backid=backid, nextid=nextid) backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid') ret = [] for sub in submissions: if since is not None and since >= sub['unixtime']: break tidy_submission(sub) ret.append(sub) return { 'backid': backid, 'nextid': nextid, 'submissions': ret, }
def GET(self, login): userid = profile.resolve_by_login(login) if not userid: web.ctx.status = '404 Not Found' raise WeasylError('userRecordMissing') form = web.input(since=None, count=0, folderid=0, backid=0, nextid=0) since = None try: if form.since: since = d.parse_iso8601(form.since) count = int(form.count) folderid = int(form.folderid) backid = int(form.backid) nextid = int(form.nextid) except ValueError: web.ctx.status = '422 Unprocessable Entity' return json.dumps(_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = submission.select_list( self.user_id, d.get_rating(self.user_id), count + 1, otherid=userid, folderid=folderid, backid=backid, nextid=nextid) backid, nextid = d.paginate(submissions, backid, nextid, count, 'submitid') ret = [] for sub in submissions: if since is not None and since >= sub['unixtime']: break tidy_submission(sub) ret.append(sub) return json.dumps({ 'backid': backid, 'nextid': nextid, 'submissions': ret, })
def api_messages_submissions_(request): form = request.web_input(count=0, backtime=0, nexttime=0) try: count = int(form.count) backtime = int(form.backtime) nexttime = int(form.nexttime) except ValueError: raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED) else: count = min(count or 100, 100) submissions = message.select_submissions( request.userid, count + 1, include_tags=True, backtime=backtime, nexttime=nexttime) backtime, nexttime = d.paginate(submissions, backtime, nexttime, count, 'unixtime') ret = [] for sub in submissions: tidy_submission(sub) ret.append(sub) return { 'backtime': backtime, 'nexttime': nexttime, 'submissions': ret, }
def test_paginate(parameters, expected_pair, expected_rows): pair = d.paginate(*parameters) assert (pair, parameters[0]) == (expected_pair, expected_rows)