コード例 #1
0
ファイル: views.py プロジェクト: jasonbeca/snapcraft.io
def homepage():
    featured_snaps = []
    error_info = {}
    status_code = 200
    try:
        featured_snaps = logic.get_searched_snaps(api.get_featured_snaps())
    except ApiError as api_error:
        status_code, error_info = _handle_errors(api_error)

    return flask.render_template('index.html',
                                 featured_snaps=featured_snaps,
                                 error_info=error_info), status_code
コード例 #2
0
def search_snap():
    status_code = 200
    snap_searched = flask.request.args.get('q', default='', type=str)
    if not snap_searched:
        return flask.redirect('/store')

    size = flask.request.args.get('limit', default=10, type=int)
    offset = flask.request.args.get('offset', default=0, type=int)
    try:
        page = floor(offset / size) + 1
    except ZeroDivisionError:
        size = 10
        page = floor(offset / size) + 1

    error_info = {}
    snaps_results = []
    links = []
    try:
        searched_results = api.get_searched_snaps(
            quote_plus(snap_searched),
            size,
            page
        )

        snaps_results = logic.get_searched_snaps(searched_results)
        links = logic.get_pages_details(
            flask.request.base_url,
            (
                searched_results['_links']
                if '_links' in searched_results
                else []
            )
        )
    except ApiError as api_error:
        status_code, error_info = _handle_errors(api_error)

    context = {
        "query": snap_searched,
        "snaps": snaps_results,
        "links": links,
        "error_info": error_info

    }

    return flask.render_template(
        'search.html',
        **context
    )
コード例 #3
0
def snaps():
    promoted_snaps = []
    error_info = {}
    status_code = 200
    try:
        promoted_snaps = logic.get_searched_snaps(
            api.get_promoted_snaps()
        )
    except ApiError as api_error:
        status_code, error_info = _handle_errors(api_error)

    return flask.render_template(
        'promoted.html',
        snaps=promoted_snaps,
        error_info=error_info
    ), status_code