Ejemplo n.º 1
0
def create_hostcategoryurl(session):
    ''' Create some HostCategoryUrl to play with for the tests
    '''
    item = model.HostCategoryUrl(
        host_category_id=1,
        url='http://infrastructure.fedoraproject.org/pub/fedora/linux',
        private=False,
    )
    session.add(item)
    item = model.HostCategoryUrl(
        host_category_id=1,
        url='http://infrastructure.fedoraproject.org/pub/epel',
        private=False,
    )
    session.add(item)

    item = model.HostCategoryUrl(
        host_category_id=1,
        url='http://dl.fedoraproject.org/pub/fedora/linux',
        private=False,
    )
    session.add(item)
    item = model.HostCategoryUrl(
        host_category_id=1,
        url='http://dl.fedoraproject.org/pub/epel',
        private=False,
    )
    session.add(item)

    session.commit()
Ejemplo n.º 2
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    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.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)

        url = form.url.data.strip()
        if url.endswith('/'):
            url = url[:-1]
        host_category_u.url = url

        SESSION.add(host_category_u)

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

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

    return flask.render_template(
        'host_category_url_new.html',
        form=form,
        host=hostobj,
        hostcategory=hcobj,
    )
Ejemplo n.º 3
0
def host_category_url_new(host_id, hc_id):
    """ Create a new host_category_url.
    """
    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.AddHostCategoryUrlForm()

    if form.validate_on_submit():

        host_category_u = model.HostCategoryUrl()
        host_category_u.host_category_id = hcobj.id
        form.populate_obj(obj=host_category_u)
        SESSION.add(host_category_u)

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

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

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