diff --git a/lehrpreis.py b/lehrpreis.py index d83d67a5c3725acf08ab0d48799b3f47c7576a18..0566c294f39599e892f85f199a1710dcdc74f3bb 100755 --- a/lehrpreis.py +++ b/lehrpreis.py @@ -201,8 +201,14 @@ class Nomination(db.Model): def main(): today = datetime.date.today() inst = Instance.query.filter_by(enabled=True).filter(Instance.date > today).order_by( - Instance.date.asc()).first() or Instance.query.filter(Instance.date > today).order_by( - Instance.date.asc()).first() + Instance.date.asc()) or Instance.query.filter(Instance.date > today).order_by( + Instance.date.asc()) + return render_template('main.html', instances=inst) + + +@app.route('/nominate/<int:instid>', methods=['GET', 'POST']) +def nominate(instid): + inst = Instance.query.filter_by(id=instid).first_or_404() form = NominateForm() form.category.choices = [(category.strip(), category.strip()) for category in inst.categories.split(';')] if inst else [] if form.validate_on_submit(): @@ -227,7 +233,8 @@ def main(): mail['X-Generator'] = 'Lehpreis WebApp' s = smtplib.SMTP(config.MAIL_HOST) s.send_message(mail) - return render_template('main.html', inst=inst, form=form) + return redirect(url_for('.main')) + return render_template('nominate.html', inst=inst, form=form) @app.route('/manage', methods=['GET', 'POST']) diff --git a/templates/main.html b/templates/main.html index ef0efe9102ba45f6c2e2c0e28b223537563d27c8..5f851edcc8e56369ecbbe2692f2d0097db47c119 100644 --- a/templates/main.html +++ b/templates/main.html @@ -8,19 +8,15 @@ {{ config.BRANDING_INFORMATION[get_locale()]|safe }} </div> {% endif %} -{% if inst is none %} -<div class="alert alert-danger" role="alert">{{ gettext('Sorry, there is currently no nomination process running.') }}</div> -{% elif not inst.enabled %} -{% if current_user.is_authenticated %} -<div class="alert alert-warning" role="alert">{{ gettext('Nominations are closed for %(instname)s, currently. As authenticated user, you can still nominate. The results will be announced at %(instdate)s.', instname=inst.name, instdate=inst.date|dateformat('long')) }}</div> - {{ render_form(form, action_url=url_for('.main'), action_text=gettext('Submit'), class_="form", btn_class='btn btn-primary') }} +{% if instances is none %} + <div class="alert alert-danger" role="alert">{{ gettext('Sorry, there is currently no nomination process running.') }}</div> {% else %} -<div class="alert alert-warning" role="alert">{{ gettext('Sorry, you cannot nominate for %(instname)s, currently. The results will be announced at %(instdate)s.', instname=inst.name, instdate=inst.date|dateformat('long')) }}</div> -{% endif %} -{% else %} -<h3>{{ gettext('Nominate someone!') }}</h3> -<div class="alert alert-info" role="alert">{{ gettext('Your nomination counts for %(instname)s, currently. The results will be announced at %(instdate)s.', instname=inst.name, instdate=inst.date|dateformat('long')) }}</div> - {{ render_form(form, action_url=url_for('.main'), action_text=gettext('Submit'), class_="form", btn_class='btn btn-primary') }} +<h3>{{ gettext('Please select the award for which you would like to nominate someone.') }}</h3> +<ul class="container"> +{% for instance in instances %} + <li><a href="{{ url_for('nominate', instid=instance.id) }}">{{ instance.name }}</a></li> +{% endfor %} +</ul> {% endif %} {% endblock %} diff --git a/templates/nominate.html b/templates/nominate.html new file mode 100644 index 0000000000000000000000000000000000000000..5674157f360080d0a02636684f038508a1031897 --- /dev/null +++ b/templates/nominate.html @@ -0,0 +1,19 @@ +{% extends "layout.html" %} +{% from 'macros.html' import render_form %} +{% block title %}{{ gettext('Nominate') }}{% endblock %} + +{% block content %} +{% if config.BRANDING_INFORMATION %} +<div> + {{ config.BRANDING_INFORMATION[get_locale()]|safe }} +</div> +{% endif %} +{% if inst is none %} + <div class="alert alert-danger" role="alert">{{ gettext('Sorry, there is currently no nomination possible.') }}</div> +{% else %} + <h3>{{ gettext('Nominate someone!') }}</h3> + <div class="alert alert-info" role="alert">{{ gettext('Your nomination counts for %(instname)s, currently. The results will be announced at %(instdate)s.', instname=inst.name, instdate=inst.date|dateformat('long')) }}</div> + {{ render_form(form, action_url=url_for('.nominate', instid=inst.id), action_text=gettext('Submit'), class_="form", btn_class='btn btn-primary') }} +{% endif %} + +{% endblock %}