コード例 #1
0
ファイル: __init__.py プロジェクト: nphilipp/mirrormanager2
def create_site(session):
    ''' Create some site to play with for the tests
    '''
    item = model.Site(
        name='test-mirror',
        password='******',
        org_url='http://fedoraproject.org',
        private=False,
        admin_active=True,
        user_active=True,
        all_sites_can_pull_from_me=True,
        downstream_comments='Mirror available over RSYNC and HTTP.',
        email_on_drop=False,  # Default value - not changeable in the UI Oo
        email_on_add=False,  # Default value - not changeable in the UI Oo
        created_by='pingou',
    )
    session.add(item)
    item = model.Site(
        name='test-mirror2',
        password='******',
        org_url='http://getfedora.org',
        private=False,
        admin_active=True,
        user_active=True,
        all_sites_can_pull_from_me=True,
        downstream_comments='Mirror available over HTTP.',
        email_on_drop=False,
        email_on_add=False,
        created_by='kevin',
    )
    session.add(item)
    item = model.Site(
        name='test-mirror_private',
        password='******',
        org_url='http://192.168.0.15',
        private=True,
        admin_active=True,
        user_active=True,
        all_sites_can_pull_from_me=False,
        downstream_comments='My own mirror available over HTTP.',
        email_on_drop=False,
        email_on_add=False,
        created_by='skvidal',
    )
    session.add(item)

    session.commit()
コード例 #2
0
def site_new():
    """ Create a new site.
    """
    form = forms.AddSiteForm()
    if form.validate_on_submit():
        site = model.Site()
        SESSION.add(site)
        form.populate_obj(obj=site)
        site.admin_active = True
        site.created_by = flask.g.fas_user.username
        if site.org_url.endswith('/'):
            site.org_url = site.org_url[:-1]

        try:
            SESSION.flush()
            flask.flash('Site added')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this as there is no unique constraint in the
            # Site table. So the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not create the new site')
            APP.logger.debug('Could not create the new site')
            APP.logger.exception(err)
            return flask.redirect(flask.url_for('index'))

        try:
            msg = mmlib.add_admin_to_site(
                SESSION, site, flask.g.fas_user.username)
            flask.flash(msg)
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            APP.logger.debug(
                'Could not add admin "%s" to site "%s"' % (
                    flask.g.fas_user.username, site))
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site_new.html',
        form=form,
    )
コード例 #3
0
ファイル: __init__.py プロジェクト: yumsuresht/mirrormanager2
def site_new():
    """ Create a new site.
    """
    form = forms.AddSiteForm()
    if form.validate_on_submit():
        site = model.Site()
        SESSION.add(site)
        form.populate_obj(obj=site)
        site.created_by = flask.g.fas_user.username

        try:
            SESSION.flush()
            flask.flash('Site added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new site')
            APP.logger.debug('Could not create the new site')
            APP.logger.exception(err)
            return flask.redirect(flask.url_for('index'))

        try:
            msg = add_admin_to_site(SESSION, site, flask.g.fas_user.username)
            fask.flash(msg)
        except SQLAlchemyError as err:
            SESSION.rollback()
            APP.logger.debug('Could not add admin "%s" to site "%s"' %
                             (flask.g.fas_user.username, site))
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site_new.html',
        form=form,
    )