示例#1
0
def add_record():
    """
    Process form data & use it to create and update Episode records.
    :return: Response
    """
    bg = Background()
    bg.episode = Episode()
    bg.location = Location()
    ref = ''

    if request.method == 'POST':
        form = BGForm(request.form, obj=bg)
        if form.validate():
            form.populate_obj(bg)
            bg.save()
            flash('Scene {} was successfully saved.'.format(bg.scene), 'info')
            return redirect_back('bg_routes.details_view', record_id=bg.id)
    else:
        # load show if specified
        if request.args.get('episode_id'):
            bg.episode = get_or_404(
                Episode.select(),
                Episode.id == int(request.args.get('episode_id')))
        ref = get_redirect_target()
        form = BGForm(obj=bg)

    title = 'Adding New BG'
    return render_template('bg_form.html',
                           bg=bg,
                           form=form,
                           title=title,
                           next=ref,
                           action=request.url_rule.rule)
示例#2
0
def edit_record(record_id):
    """
    Create new background record.
    :param record_id: Background id matching record in database.
    :type record_id: int
    :return: Response
    """
    bg = get_or_404(Background.select(), Background.id == record_id)
    ref = ''

    if request.method == 'POST':
        form = BGForm(request.form, obj=bg)
        if form.validate():
            form.populate_obj(bg)
            bg.save()
            flash('Scene {} was successfully updated.'.format(bg.scene),
                  'info')
            return redirect_back('bg_routes.details_view', record_id=bg.id)
    else:
        form = BGForm(obj=bg)
        ref = get_redirect_target()

    action = '/bg/{}/edit/'.format(bg.id)
    title = 'Editing {} “{}” scene {}'.format(
        bg.episode.format_padded_number(), bg.episode.title,
        bg.format_padded_scene())
    return render_template('bg_form.html',
                           bg=bg,
                           form=form,
                           title=title,
                           action=action,
                           next=ref)
示例#3
0
def edit_record(record_id):
    """
    Create new episode record.
    :param record_id: Episode id in database.
    :type record_id: int
    :return: Response
    """
    e = get_or_404(Episode.select(), Episode.id == record_id)

    if request.method == 'POST':
        form = EpisodeForm(request.form, obj=e)
        if form.validate():
            form.populate_obj(e)
            e.save()
            flash('Episode “{}” was successfully updated.'.format(e.title),
                  'info')
            return redirect_back('episode_routes.details_view', record_id=e.id)
    else:
        form = EpisodeForm(obj=e)

    action = '/episode/{}/edit/'.format(e.id)
    title = 'Editing {}'.format(str(e))
    ref = get_redirect_target()
    return render_template('episode_form.html',
                           episode=e,
                           form=form,
                           title=title,
                           next=ref,
                           action=action)
示例#4
0
def add_record():
    """
    Process form data & use it to create and update Episode records.
    :return: Response
    """
    e = Episode()
    e.show = Show()

    if request.method == 'POST':
        form = EpisodeForm(request.form, obj=e)
        if form.validate():
            form.populate_obj(e)
            e.save()
            flash('Episode “{}” was successfully saved.'.format(e.title),
                  'info')
            return redirect_back('episode_routes.details_view', record_id=e.id)
    else:
        # load show if specified
        if request.args.get('show_id'):
            e.show = get_or_404(Show.select(),
                                Show.id == int(request.args.get('show_id')))
        form = EpisodeForm(obj=e)

    title = 'Add New Episode'
    ref = get_redirect_target()
    return render_template('episode_form.html',
                           episode=e,
                           form=form,
                           title=title,
                           next=ref,
                           action=request.url_rule.rule)
def details_view(record_id):
    """
    List the episodes available in the requested show.
    :param record_id: Show id matching database record.
    :type record_id: int
    :return: Response
    """
    s = get_or_404(Show.select().where(Show.id == record_id))
    try:
        episodes = get_episode_listings(s.id)
    except Episode.DoesNotExist:
        msg = 'Error retrieving episodes in {}'.format(s.title)
        return render_template('error.html', error_msg=msg)
    ref = '/show/{}'.format(s.id)
    return render_template('show_details.html', title=str(s), show=s, episodes=episodes, next=ref)
def delete(record_id):
    """
    Display confirmation form before deleting Show record.
    :param record_id: Id of Show record to delete.
    :return: HTML Response
    """
    s = get_or_404(Show.select(), Show.id == record_id)

    if request.method == 'POST':
        show_title = str(s)
        s.delete_instance()
        flash('Show {} was successfully deleted.'.format(show_title), 'info')
        return redirect_back(s, 'show_routes.listings')
    else:
        title = 'Deleting {}'.format(str(s))
        ref = get_redirect_target()

    return render_template('show_confirm_delete.html', show=s, title=title, next=ref)
示例#7
0
def delete(record_id):
    """
    Display confirmation form before deleting BG record.
    :param record_id: Id of BG record to delete.
    :return: HTML Response
    """
    bg = get_or_404(Background.select(), Background.id == record_id)

    if request.method == 'POST':
        bg_name = str(bg)
        bg.delete_instance()
        flash('{} BG was successfully deleted.'.format(bg_name), 'info')
        return redirect_back('bg_routes.listings')
    else:
        title = 'Deleting {}'.format(str(bg))
        ref = get_redirect_target()

    return render_template('bg_confirm_delete.html',
                           bg=bg,
                           title=title,
                           next=ref)
def edit_record(record_id):
    """
    Validate and serialize show data.
    :param record_id: Id of show record to edit
    :return: Response
    """
    s = get_or_404(Show.select(), Show.id == record_id)

    if request.method == 'POST':
        form = ShowForm(request.form, obj=s)
        if form.validate():
            form.populate_obj(s)
            s.save()
            flash('Show “{}” was successfully updated.'.format(s.title), 'info')
            return redirect_back(s, 'show_routes.details_view', record_id=s.id)
    else:
        form = ShowForm(obj=s)

    action = '/show/{}/edit'.format(s.id)
    title = 'Editing {}'.format(str(s))
    ref = get_redirect_target()
    return render_template('show_form.html', show=s, form=form, title=title, next=ref, action=action)
示例#9
0
def delete(record_id):
    """
    Display confirmation form before deleting Episode record.
    :param record_id: Id of Episode record to delete.
    :return: HTML Response
    """
    e = get_or_404(Episode.select(), Episode.id == record_id)

    if request.method == 'POST':
        episode_title = str(e)
        e.delete_instance()
        flash('Episode {} was successfully deleted.'.format(episode_title),
              'info')
        return redirect_back('episode_routes.listings')
    else:
        title = 'Deleting {}'.format(str(e))
        ref = get_redirect_target()

    return render_template('episode_confirm_delete.html',
                           episode=e,
                           title=title,
                           next=ref)