コード例 #1
0
ファイル: test_nuancierlib.py プロジェクト: grdryn/nuancier
    def test_edit_election(self):
        """ Test the edit_election function. """
        create_elections(self.session)
        election = nuancierlib.get_election(self.session, 2)

        new_election = nuancierlib.edit_election(
            self.session,
            election=election,
            election_name='elec name',
            election_folder='Test',
            election_year=2048,
            election_date_start=TODAY,
            election_date_end=TODAY + timedelta(days=2),
            submission_date_start=TODAY - timedelta(days=2),
            election_n_choice=42,
            election_badge_link='http://badges.fp.o/1234',
            user='******',
        )

        self.assertEqual(new_election.election_name, 'elec name')
        self.assertEqual(new_election.election_folder, 'Test')
        self.assertEqual(new_election.election_year, 2048)
        self.assertEqual(new_election.election_date_start, TODAY)
        self.assertEqual(
            new_election.election_date_end, TODAY + timedelta(days=2))
        self.assertEqual(
            new_election.submission_date_start, TODAY - timedelta(days=2))
        self.assertEqual(new_election.election_n_choice, 42)
        self.assertEqual(
            new_election.election_badge_link, 'http://badges.fp.o/1234')
コード例 #2
0
ファイル: admin.py プロジェクト: fedora-infra/nuancier
def admin_edit(election_id):
    ''' Edit an election. '''
    if not nuancier.is_nuancier_admin(flask.g.fas_user):
        flask.flash('You are not an administrator of nuancier',
                        'error')
        return flask.redirect(flask.url_for('msg'))

    election = nuancierlib.get_election(SESSION, election_id)

    if not election:
        flask.flash('No election found', 'error')
        return flask.render_template('msg.html')

    form = nuancier.forms.AddElectionForm()
    if flask.request.method == 'GET':
        form = nuancier.forms.AddElectionForm(election=election)

    if form.validate_on_submit():
        try:
            election = nuancierlib.edit_election(
                SESSION,
                election=election,
                election_name=form.election_name.data,
                election_folder=form.election_folder.data,
                election_year=form.election_year.data,
                election_date_start=form.election_date_start.data,
                election_date_end=form.election_date_end.data,
                submission_date_start=form.submission_date_start.data,
                submission_date_end=form.submission_date_end.data,
                election_n_choice=form.election_n_choice.data,
                user_n_candidates=form.user_n_candidates.data,
                election_badge_link=form.election_badge_link.data,
                user=flask.g.fas_user.username,
            )
            SESSION.commit()
            flask.flash('Election updated')
        except SQLAlchemyError as err:
            SESSION.rollback()
            LOG.debug("User: %s could not edit election: %s ",
                      flask.g.fas_user.username, election_id)
            LOG.exception(err)
            flask.flash('Could not edit this election, is this name or '
                        'folder already used?', 'error')
            return flask.render_template(
                'admin_edit.html',
                election=election,
                form=form)

        return flask.redirect(flask.url_for('admin_index'))
    return flask.render_template(
        'admin_edit.html',
        election=election,
        form=form)
コード例 #3
0
ファイル: test_nuancierlib.py プロジェクト: xsuchy/nuancier
    def test_edit_election(self):
        """ Test the edit_election function. """
        create_elections(self.session)
        election = nuancierlib.get_election(self.session, 2)

        self.assertRaises(
            nuancierlib.NuancierException,
            nuancierlib.edit_election,
            session=self.session,
            election=election,
            election_name='elec name',
            election_folder='Test',
            election_year=2048,
            election_date_start=TODAY,
            election_date_end=TODAY + timedelta(days=2),
            submission_date_start=TODAY - timedelta(days=2),
            submission_date_end=TODAY - timedelta(days=1),
            election_n_choice=42,
            user_n_candidates=5,
            election_badge_link='http://badges.fp.o/1234',
        )

        new_election = nuancierlib.edit_election(
            self.session,
            election=election,
            election_name='elec name',
            election_folder='Test',
            election_year=2048,
            election_date_start=TODAY,
            election_date_end=TODAY + timedelta(days=2),
            submission_date_start=TODAY - timedelta(days=2),
            submission_date_end=TODAY - timedelta(days=1),
            election_n_choice=42,
            user_n_candidates=5,
            election_badge_link='http://badges.fp.o/1234',
            user='******',
        )

        self.assertEqual(new_election.election_name, 'elec name')
        self.assertEqual(new_election.election_folder, 'Test')
        self.assertEqual(new_election.election_year, 2048)
        self.assertEqual(new_election.election_date_start, TODAY)
        self.assertEqual(new_election.election_date_end,
                         TODAY + timedelta(days=2))
        self.assertEqual(new_election.submission_date_start,
                         TODAY - timedelta(days=2))
        self.assertEqual(new_election.submission_date_end,
                         TODAY - timedelta(days=1))
        self.assertEqual(new_election.election_n_choice, 42)
        self.assertEqual(new_election.election_badge_link,
                         'http://badges.fp.o/1234')
コード例 #4
0
def admin_edit(election_id):
    ''' Edit an election. '''
    if not nuancier.is_nuancier_admin(flask.g.fas_user):
        flask.flash('You are not an administrator of nuancier', 'error')
        return flask.redirect(flask.url_for('msg'))

    election = nuancierlib.get_election(SESSION, election_id)

    if not election:
        flask.flash('No election found', 'error')
        return flask.render_template('msg.html')

    form = nuancier.forms.AddElectionForm()
    if flask.request.method == 'GET':
        form = nuancier.forms.AddElectionForm(election=election)

    if form.validate_on_submit():
        try:
            election = nuancierlib.edit_election(
                SESSION,
                election=election,
                election_name=form.election_name.data,
                election_folder=form.election_folder.data,
                election_year=form.election_year.data,
                election_date_start=form.election_date_start.data,
                election_date_end=form.election_date_end.data,
                submission_date_start=form.submission_date_start.data,
                submission_date_end=form.submission_date_end.data,
                election_n_choice=form.election_n_choice.data,
                user_n_candidates=form.user_n_candidates.data,
                election_badge_link=form.election_badge_link.data,
                user=flask.g.fas_user.username,
            )
            SESSION.commit()
            flask.flash('Election updated')
        except SQLAlchemyError as err:
            SESSION.rollback()
            LOG.debug("User: %s could not edit election: %s ",
                      flask.g.fas_user.username, election_id)
            LOG.exception(err)
            flask.flash(
                'Could not edit this election, is this name or '
                'folder already used?', 'error')
            return flask.render_template('admin_edit.html',
                                         election=election,
                                         form=form)

        return flask.redirect(flask.url_for('admin_index'))
    return flask.render_template('admin_edit.html',
                                 election=election,
                                 form=form)