Ejemplo n.º 1
0
Archivo: api.py Proyecto: Weasyl/weasyl
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,
    }
Ejemplo n.º 2
0
def api_frontpage_(request):
    form = request.web_input(since=None, count=0)
    since = None
    try:
        if form.since:
            since = d.parse_iso8601(form.since)
        count = int(form.count)
    except ValueError:
        raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED)
    else:
        count = min(count or 100, 100)

    submissions = index.filter_submissions(request.userid,
                                           index.recent_submissions())
    ret = []

    for e, sub in enumerate(submissions, start=1):
        if (since is not None and since >= sub['unixtime']) or (count
                                                                and e > count):
            break

        tidy_submission(sub)
        ret.append(sub)

    return ret
Ejemplo n.º 3
0
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,
    }
Ejemplo n.º 4
0
Archivo: api.py Proyecto: Weasyl/weasyl
def api_frontpage_(request):
    form = request.web_input(since=None, count=0)
    since = None
    try:
        if form.since:
            since = d.parse_iso8601(form.since)
        count = int(form.count)
    except ValueError:
        raise HTTPUnprocessableEntity(json=_ERROR_UNEXPECTED)
    else:
        count = min(count or 100, 100)

    submissions = index.filter_submissions(request.userid, index.recent_submissions())
    ret = []

    for e, sub in enumerate(submissions, start=1):
        if (since is not None and since >= sub['unixtime']) or (count and e > count):
            break

        tidy_submission(sub)
        ret.append(sub)

    return ret
Ejemplo n.º 5
0
    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,
        })
Ejemplo n.º 6
0
    def GET(self):
        form = web.input(since=None, count=0)
        since = None
        try:
            if form.since:
                since = d.parse_iso8601(form.since)
            count = int(form.count)
        except ValueError:
            web.ctx.status = '422 Unprocessable Entity'
            return json.dumps(_ERROR_UNEXPECTED)
        else:
            count = min(count or 100, 100)

        submissions = index.filter_submissions(self.user_id, index.recent_submissions())
        ret = []

        for e, sub in enumerate(submissions, start=1):
            if (since is not None and since >= sub['unixtime']) or (count and e > count):
                break

            tidy_submission(sub)
            ret.append(sub)

        return json.dumps(ret)
Ejemplo n.º 7
0
def test_parse_iso8601(parameter, expected):
    assert d.parse_iso8601(parameter) == expected
Ejemplo n.º 8
0
def test_parse_iso8601(parameter, expected):
    assert d.parse_iso8601(parameter) == expected