コード例 #1
0
ファイル: app.py プロジェクト: Flig/mirrormanager2
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Host not found')

    if not (is_site_admin(flask.g.fas_user, hostobj.site)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    host_cat_ids = [cat.id for cat in hostobj.categories]

    if hcobj.id not in host_cat_ids:
        flask.abort(404, 'Category not associated with this host')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit() and is_mirrormanager_admin(flask.g.fas_user):

        form.populate_obj(obj=hcobj)

        try:
            SESSION.flush()
            flask.flash('Host Category updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before updating
            # and therefore the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update Category to the host')
            APP.logger.debug('Could not update Category to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
コード例 #2
0
ファイル: __init__.py プロジェクト: yumsuresht/mirrormanager2
def host_category(host_id, hc_id):
    """ View a host_category.
    """
    hostobj = mmlib.get_host(SESSION, host_id)

    if hostobj is None:
        flask.abort(404, 'Host not found')

    hcobj = mmlib.get_host_category(SESSION, hc_id)

    if hcobj is None:
        flask.abort(404, 'Host/Category not found')

    categories = mmlib.get_categories(SESSION)

    form = forms.EditHostCategoryForm(obj=hcobj)

    if form.validate_on_submit():

        form.populate_obj(obj=hcobj)

        try:
            SESSION.flush()
            flask.flash('Host Category updated')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not update Category to the host')
            APP.logger.debug('Could not update Category to the host')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(
            flask.url_for('host_category', host_id=hostobj.id, hc_id=hcobj.id))

    return flask.render_template(
        'host_category.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )