app.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:aniping 作者: kuruoujou 项目源码 文件源码
def update_show():
    """Show add and edit handler.

    Either displays a template allowing the user to edit or add a show, or attempts
    to edit or add the show, depending on if the method is GET or POST. The function
    is aborted with a ``404`` message to hide the page if the user is not authenticated.

    GET method:
        Requires ``id`` to be passed as the ID of the show in a query string. If
        the show can't be found, abort with a ``404`` message. Otherwise, lookup
        the show in the db, as well as sub groups subtitling the show and the selected
        sub group if there is one, and some fanart to render on the background.

    POST method:
        Requires ``id``, ``beid``, and ``subgroup`` to be passed as form parameters.
        ``id`` is the DB id of the show, ``beid`` is the backend ID of the show, and
        ``subgroup`` is the subgroup the user has selected. This will attempt to add
        the show to the backend.

    Returns:
        A rendered template with a form on the GET method.
        A redirect to the home as a refresh on the POST method.
    """
    log.debug("Entering update_show, trying to {0} show".format(request.path.strip('/')))
    logged_in = fe.check_login_id(escape(session['logged_in']))
    if logged_in and request.method == 'POST':
       log.debug("Request method is POST, so sending results to function.")
       subgroup = request.form['subgroup']
       dbid = request.form['dbid']
       beid = request.form['beid']
       log.debug("Got SG: {0} ID: {1} and BEID: {2} from form.".format(subgroup, dbid, beid))
       fe.add_update_show(dbid, beid, subgroup)
       log.debug("Refreshing user's page.")
       return redirect('/')
    elif logged_in and request.method == 'GET':
        log.debug("Request method is GET, so showing page to user.")
        if 'id' in request.args:
            id = request.args['id']
            log.debug("Attempting to operate on id {0}".format(id))
            sonarr_show = fe.search_show_from_backend(id)
            if not sonarr_show:
                log.debug("Could not find show from backend with ID {0}".format(id))
                abort(404)
            db_show = fe.get_show_from_db(id)
            subgroups = fe.get_subgroups(id)
            selected_group = fe.get_selected_group(sonarr_show['beid'])
            fanart = fe.get_fanart(sonarr_show['beid'])
            log.debug("Rendering form for user")
            return render_template("add.html", id=id, title=db_show['title'], subgroups=subgroups, selectedGroup=selected_group, sonarr=sonarr_show, logged_in=logged_in, fanart=fanart, action=request.path.strip('/'))
        log.debug("No ID sent with request, so just refresh user's page to the home.")
        return redirect('/')
    log.debug("User cannot be authenticated, send 404 to hide page.")
    abort(404)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号