def admin_cache(election_id): ''' Regenerate the cache for this election. ''' election = nuancierlib.get_election(SESSION, election_id) next_url = None if 'next' in flask.request.args: next_url = flask.request.args['next'] if not next_url or next_url == flask.url_for( '.admin_cache', election_id=election_id): next_url = flask.url_for('.admin_index') if not election: flask.flash('No election found', 'error') return flask.render_template('msg.html') try: nuancierlib.generate_cache( session=SESSION, election=election, picture_folder=APP.config['PICTURE_FOLDER'], cache_folder=APP.config['CACHE_FOLDER'], size=APP.config['THUMB_SIZE']) flask.flash('Cache regenerated for election %s' % election.election_name) except nuancierlib.NuancierException as err: SESSION.rollback() LOG.debug('User: "******" could not generate cache for "%s"', flask.g.fas_user.username, election_id) LOG.exception(err) flask.flash(err.message, 'error') return flask.redirect(next_url)
def test_generate_cache(self): """ Test the generate_cache function. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 2) self.assertFalse(os.path.exists(CACHE_FOLDER)) nuancierlib.generate_cache(session=self.session, election=election, picture_folder=PICTURE_FOLDER, cache_folder=CACHE_FOLDER, size=(128, 128)) self.assertTrue(os.path.exists(CACHE_FOLDER))
def test_generate_cache(self): """ Test the generate_cache function. """ create_elections(self.session) election = nuancierlib.get_election(self.session, 2) self.assertFalse(os.path.exists(CACHE_FOLDER)) nuancierlib.generate_cache( session=self.session, election=election, picture_folder=PICTURE_FOLDER, cache_folder=CACHE_FOLDER, size=(128, 128) ) self.assertTrue(os.path.exists(CACHE_FOLDER))
def admin_cache(election_id): ''' Regenerate the cache for this election. ''' election = nuancierlib.get_election(SESSION, election_id) next_url = None if 'next' in flask.request.args: next_url = flask.request.args['next'] if not next_url or next_url == flask.url_for('.admin_cache', election_id=election_id): next_url = flask.url_for('.admin_index') if not election: flask.flash('No election found', 'error') return flask.render_template('msg.html') try: nuancierlib.generate_cache(session=SESSION, election=election, picture_folder=APP.config['PICTURE_FOLDER'], cache_folder=APP.config['CACHE_FOLDER'], size=APP.config['THUMB_SIZE']) flask.flash('Cache regenerated for election %s' % election.election_name) except nuancierlib.NuancierMultiExceptions as multierr: # pragma: no cover SESSION.rollback() LOG.debug('User: "******" could not generate cache for "%s"', flask.g.fas_user.username, election_id) LOG.exception(multierr.messages) for msg in multierr.messages: flask.flash(msg, 'error') except nuancierlib.NuancierException as err: SESSION.rollback() LOG.debug('User: "******" could not generate cache for "%s"', flask.g.fas_user.username, election_id) LOG.exception(err) flask.flash(str(err), 'error') return flask.redirect(next_url)
# -*- coding: utf-8 -*- __requires__ = ['SQLAlchemy >= 0.7', 'jinja2 >= 2.4'] import pkg_resources import os os.environ['NUANCIER_CONFIG'] = '/etc/nuancier/nuancier.cfg' from nuancier import APP, SESSION, lib election = lib.get_election(SESSION, 1) lib.generate_cache( SESSION, election, APP.config['PICTURE_FOLDER'], APP.config['CACHE_FOLDER'], APP.config['THUMB_SIZE'], )