Example #1
0
    def test_get_candidate(self):
        """ Test the get_candidate function. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual('Image ok', candidate.candidate_name)

        candidate = nuancierlib.get_candidate(self.session, 10)
        self.assertEqual(None, candidate)
    def test_get_candidate(self):
        """ Test the get_candidate function. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual('Image ok', candidate.candidate_name)

        candidate = nuancierlib.get_candidate(self.session, 10)
        self.assertEqual(None, candidate)
    def test_get_candidate(self):
        """ Test the get_candidate function. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual('DSC_0951', candidate.candidate_name)

        candidate = nuancierlib.get_candidate(self.session, 4)
        self.assertEqual('DSC_0922', candidate.candidate_name)
Example #4
0
    def test_candidates_api_repr(self):
        """ Test the api_repr function of Elections. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual(
            candidate.api_repr(1),
            {'election': u'Wallpaper F19', 'name': u'DSC_0951'}
        )
Example #5
0
    def test_candidates_repr(self):
        """ Test the __repr__ function of Candidates. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertTrue(
            candidate.__repr__().startswith(
                "Candidates(file:u'DSC_0951.JPG', "
                       "name:u'DSC_0951', "
                       "election_id:1, "
            )
        )
Example #6
0
    def test_candidates_api_repr(self):
        """ Test the api_repr function of Elections. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual(
            candidate.api_repr(1), {
                'author': u'pingou',
                'license': u'CC-BY-SA',
                'name': u'Image ok',
                'original_url': None,
                'submitter': u'pingou',
            })
Example #7
0
    def test_candidates_api_repr(self):
        """ Test the api_repr function of Elections. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        self.assertEqual(
            candidate.api_repr(1),
            {
                'author': u'pingou',
                'license': u'CC-BY-SA',
                'name': u'Image ok',
                'original_url': None,
                'submitter': u'pingou',
            }
        )
Example #8
0
    def test_candidates_repr(self):
        """ Test the __repr__ function of Candidates. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        if six.PY2:
            self.assertTrue(candidate.__repr__().startswith(
                "Candidates(file:u'ok.JPG', "
                "name:u'Image ok', "
                "election_id:1, "))
        else:
            self.assertTrue(candidate.__repr__().startswith(
                "Candidates(file:'ok.JPG', "
                "name:'Image ok', "
                "election_id:1, "))
Example #9
0
    def test_candidates_repr(self):
        """ Test the __repr__ function of Candidates. """
        create_elections(self.session)
        create_candidates(self.session)

        candidate = nuancierlib.get_candidate(self.session, 1)
        if six.PY2:
            self.assertTrue(
                candidate.__repr__().startswith(
                    "Candidates(file:u'ok.JPG', "
                    "name:u'Image ok', "
                    "election_id:1, "
                )
            )
        else:
            self.assertTrue(
                candidate.__repr__().startswith(
                    "Candidates(file:'ok.JPG', "
                    "name:'Image ok', "
                    "election_id:1, "
                )
            )
Example #10
0
def update_candidate(cand_id):
    ''' Display the index page for interested contributor. '''
    candidate = nuancierlib.get_candidate(SESSION, cand_id)

    # First some security checks
    if not candidate:
        flask.flash('No candidate found', 'error')
        return flask.render_template('msg.html')
    elif not candidate.election.submission_open:
        flask.flash(
            'The election of this candidate is not open for submission',
            'error')
        return flask.redirect(flask.url_for('elections_list'))
    elif candidate.approved:
        flask.flash(
            'This candidate was already approved, you cannot update it',
            'error')
        return flask.redirect(flask.url_for('elections_list'))
    elif candidate.candidate_submitter != flask.g.fas_user.username:
        flask.flash(
            'You are not the person that submitted this candidate, you may '
            'not update it', 'error')
        return flask.redirect(flask.url_for('elections_list'))

    form = nuancier.forms.AddCandidateForm(obj=candidate)
    if form.validate_on_submit():
        candidate_file = flask.request.files['candidate_file']

        try:
            validate_input_file(candidate_file)
        except nuancierlib.NuancierException as err:
            LOG.debug(
                'ERROR: Uploaded file is invalid - user: "******" '
                'election: "%s"', flask.g.fas_user.username,
                candidate.election.id)
            LOG.exception(err)
            flask.flash('%s' % err, 'error')
            return flask.render_template('update_contribution.html',
                                         candidate=candidate,
                                         form=form)

        filename = secure_filename(
            '%s-%s' % (flask.g.fas_user.username, candidate_file.filename))

        # Only save the file once everything has been safely saved in the DB
        upload_folder = os.path.join(APP.config['PICTURE_FOLDER'],
                                     candidate.election.election_folder)
        if not os.path.exists(upload_folder):  # pragma: no cover
            try:
                os.mkdir(upload_folder)
            except OSError as err:
                LOG.debug('ERROR: cannot add candidate file')
                LOG.exception(err)
                flask.flash(
                    'An error occured while writing the file, please '
                    'contact an administrator', 'error')
                return flask.render_template('update_contribution.html',
                                             candidate=candidate,
                                             form=form)

        # Update the candidate
        form.populate_obj(obj=candidate)
        candidate.candidate_file = filename
        candidate.approved = False
        candidate.approved_motif = None
        SESSION.add(candidate)

        # The PIL module has already read the stream so we need to back up
        candidate_file.seek(0)
        candidate_file.save(os.path.join(upload_folder, filename))

        try:
            SESSION.commit()
        except SQLAlchemyError as err:  # pragma: no cover
            LOG.debug(err)
            SESSION.rollback()
            # Remove file from the system if the db commit failed
            os.unlink(os.path.join(upload_folder, filename))
            LOG.debug(
                'ERROR: cannot add candidate - user: "******" '
                'election: "%s"', flask.g.fas_user.username,
                candidate.election.id)
            LOG.exception(err)
            flask.flash(
                'Someone has already upload a file with the same file name'
                ' for this election', 'error')
            return flask.render_template('update_contribution.html',
                                         candidate=candidate,
                                         form=form)

        flask.flash('Thanks for updating your submission')
        return flask.redirect(flask.url_for('index'))

    return flask.render_template('update_contribution.html',
                                 candidate=candidate,
                                 form=form)
Example #11
0
def process_vote(election_id):
    ''' Actually register the vote, after checking if the user is actually
    allowed to vote.
    '''

    form = nuancier.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.flash('Wrong input submitted', 'error')
        return flask.render_template('msg.html')

    election = nuancierlib.get_election(SESSION, election_id)
    if not election:
        flask.flash('No election found', 'error')
        return flask.render_template('msg.html')

    if not election.election_open:
        flask.flash('This election is not open', 'error')
        return flask.render_template('msg.html')

    candidates = nuancierlib.get_candidates(SESSION,
                                            election_id,
                                            approved=True)
    candidate_ids = set([candidate.id for candidate in candidates])

    entries = set(
        [int(entry) for entry in flask.request.form.getlist('selection')])

    # If not enough candidates selected
    if not entries:
        flask.flash('You did not select any candidate to vote for.', 'error')
        return flask.redirect(flask.url_for('vote', election_id=election_id))

    # If vote on candidates from other elections
    if not set(entries).issubset(candidate_ids):
        flask.flash(
            'The selection you have made contains element which are '
            'not part of this election, please be careful.', 'error')
        return flask.redirect(flask.url_for('vote', election_id=election_id))

    # How many votes the user made:
    votes = nuancierlib.get_votes_user(SESSION, election_id,
                                       flask.g.fas_user.username)

    # Too many votes -> redirect
    if len(votes) >= election.election_n_choice:
        flask.flash(
            'You have cast the maximal number of votes '
            'allowed for this election.', 'error')
        return flask.redirect(
            flask.url_for('election', election_id=election_id))

    # Selected more candidates than allowed -> redirect
    if len(votes) + len(entries) > election.election_n_choice:
        flask.flash(
            'You selected %s wallpapers while you are only allowed '
            'to select %s' % (len(entries),
                              (election.election_n_choice - len(votes))),
            'error')
        return flask.render_template(
            'vote.html',
            form=nuancier.forms.ConfirmationForm(),
            election=election,
            candidates=[
                nuancierlib.get_candidate(SESSION, candidate_id)
                for candidate_id in entries
            ],
            n_votes_done=len(votes),
            picture_folder=os.path.join(APP.config['PICTURE_FOLDER'],
                                        election.election_folder),
            cache_folder=os.path.join(APP.config['CACHE_FOLDER'],
                                      election.election_folder))

    # Allowed to vote, selection sufficient, choice confirmed: process
    for selection in entries:
        value = 1
        if nuancier.has_weigthed_vote(flask.g.fas_user):
            value = 2
        nuancierlib.add_vote(SESSION,
                             selection,
                             flask.g.fas_user.username,
                             value=value)

    try:
        SESSION.commit()
    except SQLAlchemyError as err:  # pragma: no cover
        SESSION.rollback()
        LOG.debug(
            'ERROR: could not process the vote - user: "******" '
            'election: "%s"', flask.g.fas_user.username, election_id)
        LOG.exception(err)
        flask.flash(
            'An error occured while processing your votes, please '
            'report this to your lovely admin or see logs for '
            'more details', 'error')

    flask.flash('Your vote has been recorded, thank you for voting on '
                '%s %s' % (election.election_name, election.election_year))

    if election.election_badge_link:
        flask.flash('Do not forget to <a href="%s" target="_blank">claim your '
                    'badge!</a>' % election.election_badge_link)
    return flask.redirect(flask.url_for('elections_list'))
Example #12
0
def update_candidate(cand_id):
    ''' Display the index page for interested contributor. '''
    candidate = nuancierlib.get_candidate(SESSION, cand_id)

    # First some security checks
    if not candidate:
        flask.flash('No candidate found', 'error')
        return flask.render_template('msg.html')
    elif not candidate.election.submission_open:
        flask.flash(
            'The election of this candidate is not open for submission',
            'error')
        return flask.redirect(flask.url_for('elections_list'))
    elif candidate.approved:
        flask.flash(
            'This candidate was already approved, you cannot update it',
            'error')
        return flask.redirect(flask.url_for('elections_list'))
    elif candidate.candidate_submitter != flask.g.fas_user.username:
        flask.flash(
            'You are not the person that submitted this candidate, you may '
            'not update it', 'error')
        return flask.redirect(flask.url_for('elections_list'))

    form = nuancier.forms.AddCandidateForm(obj=candidate)
    if form.validate_on_submit():
        candidate_file = flask.request.files['candidate_file']

        try:
            validate_input_file(candidate_file)
        except nuancierlib.NuancierException as err:
            LOG.debug('ERROR: Uploaded file is invalid - user: "******" '
                      'election: "%s"', flask.g.fas_user.username,
                      candidate.election.id)
            LOG.exception(err)
            flask.flash(err.message, 'error')
            return flask.render_template(
                'update_contribution.html',
                candidate=candidate,
                form=form)

        filename = secure_filename('%s-%s' % (flask.g.fas_user.username,
                                   candidate_file.filename))

        # Only save the file once everything has been safely saved in the DB
        upload_folder = os.path.join(
            APP.config['PICTURE_FOLDER'],
            candidate.election.election_folder)
        if not os.path.exists(upload_folder):  # pragma: no cover
            try:
                os.mkdir(upload_folder)
            except OSError, err:
                LOG.debug('ERROR: cannot add candidate file')
                LOG.exception(err)
                flask.flash(
                    'An error occured while writing the file, please '
                    'contact an administrator', 'error')
                return flask.render_template(
                    'update_contribution.html',
                    candidate=candidate,
                    form=form)

        # Update the candidate
        form.populate_obj(obj=candidate)
        candidate.candidate_file = filename
        candidate.approved = False
        candidate.approved_motif = None
        SESSION.add(candidate)

        # The PIL module has already read the stream so we need to back up
        candidate_file.seek(0)
        candidate_file.save(
            os.path.join(upload_folder, filename))

        try:
            SESSION.commit()
        except SQLAlchemyError as err:  # pragma: no cover
            LOG.debug(err)
            SESSION.rollback()
            # Remove file from the system if the db commit failed
            os.unlink(os.path.join(upload_folder, filename))
            LOG.debug('ERROR: cannot add candidate - user: "******" '
                      'election: "%s"', flask.g.fas_user.username,
                      candidate.election.id)
            LOG.exception(err)
            flask.flash(
                'Someone has already upload a file with the same file name'
                ' for this election', 'error')
            return flask.render_template(
                'update_contribution.html',
                candidate=candidate,
                form=form)

        flask.flash('Thanks for updating your submission')
        return flask.redirect(flask.url_for('index'))
Example #13
0
def process_vote(election_id):
    ''' Actually register the vote, after checking if the user is actually
    allowed to vote.
    '''

    form = nuancier.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.flash('Wrong input submitted', 'error')
        return flask.render_template('msg.html')

    election = nuancierlib.get_election(SESSION, election_id)
    if not election:
        flask.flash('No election found', 'error')
        return flask.render_template('msg.html')

    if not election.election_open:
        flask.flash('This election is not open', 'error')
        return flask.render_template('msg.html')

    candidates = nuancierlib.get_candidates(
        SESSION, election_id, approved=True)
    candidate_ids = set([candidate.id for candidate in candidates])

    entries = set([int(entry)
                   for entry in flask.request.form.getlist('selection')])

    # If not enough candidates selected
    if not entries:
        flask.flash('You did not select any candidate to vote for.', 'error')
        return flask.redirect(flask.url_for('vote', election_id=election_id))

    # If vote on candidates from other elections
    if not set(entries).issubset(candidate_ids):
        flask.flash('The selection you have made contains element which are '
                    'not part of this election, please be careful.', 'error')
        return flask.redirect(flask.url_for('vote', election_id=election_id))

    # How many votes the user made:
    votes = nuancierlib.get_votes_user(SESSION, election_id,
                                       flask.g.fas_user.username)

    # Too many votes -> redirect
    if len(votes) >= election.election_n_choice:
        flask.flash('You have cast the maximal number of votes '
                    'allowed for this election.', 'error')
        return flask.redirect(
            flask.url_for('election', election_id=election_id))

    # Selected more candidates than allowed -> redirect
    if len(votes) + len(entries) > election.election_n_choice:
        flask.flash('You selected %s wallpapers while you are only allowed '
                    'to select %s' % (
                        len(entries),
                        (election.election_n_choice - len(votes))),
                    'error')
        return flask.render_template(
            'vote.html',
            form=nuancier.forms.ConfirmationForm(),
            election=election,
            candidates=[nuancierlib.get_candidate(SESSION, candidate_id)
                        for candidate_id in entries],
            n_votes_done=len(votes),
            picture_folder=os.path.join(
                APP.config['PICTURE_FOLDER'], election.election_folder),
            cache_folder=os.path.join(
                APP.config['CACHE_FOLDER'], election.election_folder)
        )

    # Allowed to vote, selection sufficient, choice confirmed: process
    for selection in entries:
        value = 1
        if nuancier.has_weigthed_vote(flask.g.fas_user):
            value = 2
        nuancierlib.add_vote(
            SESSION, selection, flask.g.fas_user.username, value=value)

    try:
        SESSION.commit()
    except SQLAlchemyError as err:  # pragma: no cover
        SESSION.rollback()
        LOG.debug('ERROR: could not process the vote - user: "******" '
                  'election: "%s"', flask.g.fas_user.username,
                  election_id)
        LOG.exception(err)
        flask.flash('An error occured while processing your votes, please '
                    'report this to your lovely admin or see logs for '
                    'more details', 'error')

    flask.flash('Your vote has been recorded, thank you for voting on '
                '%s %s' % (election.election_name, election.election_year))

    if election.election_badge_link:
        flask.flash('Do not forget to <a href="%s" target="_blank">claim your '
                    'badge!</a>' % election.election_badge_link)
    return flask.redirect(flask.url_for('elections_list'))
Example #14
0
def admin_process_review(election_id):
    ''' Process the reviewing of a new 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'))

    status = flask.request.args.get('status', None)
    endpoint = 'admin_review'
    if status:
        endpoint = 'admin_review_status'

    election = nuancierlib.get_election(SESSION, election_id)

    form = nuancier.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.flash('Wrong input submitted', 'error')
        return flask.render_template('msg.html')

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

    if election.election_open:
        flask.flash(
            'This election is already open to public votes and can no '
            'longer be changed', 'error')
        return flask.redirect(flask.url_for('results_list'))

    if election.election_public:
        flask.flash(
            'The results of this election are already public, this election'
            ' can no longer be changed', 'error')
        return flask.redirect(flask.url_for('results_list'))

    candidates = nuancierlib.get_candidates(SESSION, election_id)
    candidates_id = [str(candidate.id) for candidate in candidates]

    candidates_selected = flask.request.form.getlist('candidates_id')
    motifs = flask.request.form.getlist('motifs')
    action = flask.request.form.get('action')

    if action:
        action = action.strip()

    if action not in ['Approved', 'Denied']:
        flask.flash(
            'Only the actions "Approved" or "Denied" are accepted',
            'error')
        return flask.redirect(flask.url_for(
                endpoint, election_id=election_id, status=status))

    selections = []
    for cand in candidates_id:
        if cand not in candidates_selected:
            selections.append(None)
        else:
            selections.append(cand)

    if action == 'Denied':
        req_motif = False
        if not motifs:
            req_motif = True
        for cnt in range(len(motifs)):
            motif = motifs[cnt]
            if selections[cnt] and not motif.strip():
                req_motif = True
                break
        if req_motif:
            flask.flash(
                'You must provide a motif to deny a candidate',
                'error')
            return flask.redirect(flask.url_for(
                endpoint, election_id=election_id, status=status))

    cnt = 0
    for candidate in candidates_selected:
        if candidate not in candidates_id:
            flask.flash(
                'One of the candidate submitted was not candidate in this '
                'election', 'error')
            return flask.redirect(flask.url_for(
                endpoint, election_id=election_id, status=status))

    msgs = []

    for candidate in selections:
        if candidate:
            candidate = nuancierlib.get_candidate(SESSION, candidate)
            motif = None
            if len(motifs) > cnt:
                motif = motifs[cnt].strip()
            if action == 'Approved':
                candidate.approved = True
                candidate.approved_motif = motif
            else:
                candidate.approved = False
                candidate.approved_motif = motif
                if APP.config.get(
                        'NUANCIER_EMAIL_NOTIFICATIONS',
                        False):  # pragma: no cover
                    nuancierlib.notifications.email_publish(
                        to_email=candidate.submitter_email,
                        img_title=candidate.candidate_name,
                        motif=motif)
                else:
                    LOG.warning(
                        'Should have sent an email to "%s" about "%s" that has'
                        ' been rejected because of "%s"',
                        candidate.submitter_email,
                        candidate.candidate_name,
                        motif)

            SESSION.add(candidate)
            msgs.append({
                'topic': 'candidate.%s' % (action.lower()),
                'msg': dict(
                    agent=flask.g.fas_user.username,
                    election=election.api_repr(version=1),
                    candidate=candidate.api_repr(version=1),
                )
            })
        cnt += 1

    try:
        SESSION.commit()
    except SQLAlchemyError as err:  # pragma: no cover
        SESSION.rollback()
        LOG.debug('User: "******" could not approve/deny candidate(s) for '
                  'election "%s"', flask.g.fas_user.username,
                  election_id)
        LOG.exception(err)
        flask.flash('Could not approve/deny candidate', 'error')

    flask.flash('Candidate(s) updated')

    for msg in msgs:
        nuancierlib.notifications.publish(
            topic=msg['topic'],
            msg=msg['msg'],
        )

    return flask.redirect(flask.url_for(
        endpoint, election_id=election_id, status=status))
Example #15
0
def admin_process_review(election_id):
    ''' Process the reviewing of a new 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'))

    status = flask.request.args.get('status', None)
    endpoint = 'admin_review'
    if status:
        endpoint = 'admin_review_status'

    election = nuancierlib.get_election(SESSION, election_id)

    form = nuancier.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.flash('Wrong input submitted', 'error')
        return flask.render_template('msg.html')

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

    if election.election_open:
        flask.flash(
            'This election is already open to public votes and can no '
            'longer be changed', 'error')
        return flask.redirect(flask.url_for('results_list'))

    if election.election_public:
        flask.flash(
            'The results of this election are already public, this election'
            ' can no longer be changed', 'error')
        return flask.redirect(flask.url_for('results_list'))

    candidates = nuancierlib.get_candidates(SESSION, election_id)
    candidates_id = [str(candidate.id) for candidate in candidates]

    candidates_selected = flask.request.form.getlist('candidates_id')
    motifs = flask.request.form.getlist('motifs')
    action = flask.request.form.get('action')

    if action:
        action = action.strip()

    if action not in ['Approved', 'Denied']:
        flask.flash('Only the actions "Approved" or "Denied" are accepted',
                    'error')
        return flask.redirect(
            flask.url_for(endpoint, election_id=election_id, status=status))

    selections = []
    for cand in candidates_id:
        if cand not in candidates_selected:
            selections.append(None)
        else:
            selections.append(cand)

    if action == 'Denied':
        req_motif = False
        if not motifs:
            req_motif = True
        for cnt in range(len(motifs)):
            motif = motifs[cnt]
            if selections[cnt] and not motif.strip():
                req_motif = True
                break
        if req_motif:
            flask.flash('You must provide a reason to deny a candidate',
                        'error')
            return flask.redirect(
                flask.url_for(endpoint, election_id=election_id,
                              status=status))

    cnt = 0
    for candidate in candidates_selected:
        if candidate not in candidates_id:
            flask.flash(
                'One of the candidate submitted was not candidate in this '
                'election', 'error')
            return flask.redirect(
                flask.url_for(endpoint, election_id=election_id,
                              status=status))

    msgs = []

    for candidate in selections:
        if candidate:
            candidate = nuancierlib.get_candidate(SESSION, candidate)
            motif = None
            if len(motifs) > cnt:
                motif = motifs[cnt].strip()
            if action == 'Approved':
                candidate.approved = True
                candidate.approved_motif = motif
            else:
                candidate.approved = False
                candidate.approved_motif = motif
                if APP.config.get('NUANCIER_EMAIL_NOTIFICATIONS',
                                  False):  # pragma: no cover
                    nuancierlib.notifications.email_publish(
                        to_email=candidate.submitter_email,
                        img_title=candidate.candidate_name,
                        motif=motif)
                else:
                    LOG.warning(
                        'Should have sent an email to "%s" about "%s" that has'
                        ' been rejected because of "%s"',
                        candidate.submitter_email, candidate.candidate_name,
                        motif)

            SESSION.add(candidate)
            msgs.append({
                'topic':
                'candidate.%s' % (action.lower()),
                'msg':
                dict(
                    agent=flask.g.fas_user.username,
                    election=election.api_repr(version=1),
                    candidate=candidate.api_repr(version=1),
                )
            })
        cnt += 1

    try:
        SESSION.commit()
    except SQLAlchemyError as err:  # pragma: no cover
        SESSION.rollback()
        LOG.debug(
            'User: "******" could not approve/deny candidate(s) for '
            'election "%s"', flask.g.fas_user.username, election_id)
        LOG.exception(err)
        flask.flash('Could not approve/deny candidate', 'error')

    flask.flash('Candidate(s) updated')

    for msg in msgs:
        nuancierlib.notifications.publish(
            topic=msg['topic'],
            msg=msg['msg'],
        )

    return flask.redirect(
        flask.url_for(endpoint, election_id=election_id, status=status))