From cf3d790b7282d16e6a7190807dcb97b84f1781b6 Mon Sep 17 00:00:00 2001 From: Lars Beckers <lars.beckers@rwth-aachen.de> Date: Tue, 13 Mar 2018 21:17:55 +0100 Subject: [PATCH] Add nomination categories Implements issue #8. --- lehrpreis.py | 10 +++++++++- templates/delete.html | 4 ++++ templates/disable.html | 4 ++++ templates/enable.html | 4 ++++ templates/nomination.txt | 3 ++- templates/nominees.html | 2 ++ 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lehrpreis.py b/lehrpreis.py index 5b7be5b..8b70724 100755 --- a/lehrpreis.py +++ b/lehrpreis.py @@ -177,6 +177,7 @@ class Instance(db.Model): name = db.Column(String(255), nullable=False) enabled = db.Column(Boolean, nullable=False) date = db.Column(Date, nullable=False) + categories = db.Column(String(255), nullable=False) nominees = relationship('Nomination', foreign_keys='Nomination.instance_id', backref='instance') class Nomination(db.Model): @@ -185,6 +186,7 @@ class Nomination(db.Model): person = db.Column(String(255), nullable=False) module = db.Column(String(255), nullable=False) reason = db.Column(String(255), nullable=False) + category = db.Column(String(255), nullable=False) instance_id = db.Column(Integer, ForeignKey('instances.id'), nullable=False) @app.route('/', methods=['GET', 'POST']) @@ -193,6 +195,7 @@ 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() form = NominateForm() + form.category.choices = [ (category.strip(), category.strip()) for category in inst.categories.split(';') ] if form.validate_on_submit(): if inst is None or not (inst.enabled or current_user.is_authenticated()): flash(gettext('You cannot nominate right now. Sorry.'), 'alert-danger') @@ -200,6 +203,7 @@ def main(): nom = Nomination(person = form.person.data, module = form.module.data, reason = form.reason.data, + category = form.category.data, instance_id = inst.id) db.session.add(nom) db.session.commit() @@ -225,7 +229,8 @@ def manage(): if form.validate_on_submit(): inst = Instance(name = form.name.data, enabled = bool(form.enabled.data), - date = form.date.data) + date = form.date.data, + categories = form.categories.data) db.session.add(inst) db.session.commit() flash(gettext('The instance was created.'), 'alert-success') @@ -250,6 +255,7 @@ def modify(instid): inst.name = form.name.data inst.enabled = bool(form.enabled.data) inst.date = form.date.data + inst.categories = form.categories.data db.session.commit() flash(gettext('The instance was modified.'), 'alert-success') return redirect(url_for('.manage')) @@ -302,6 +308,7 @@ class LoginForm(Form): class NominateForm(Form): person = StringField(gettext('Nominee'), validators=[InputRequired(gettext('Please enter the name of the person you want to nominate.'))]) + category = SelectField(gettext('Category'), validators=[InputRequired(gettext('Please select the category you want to nominate the person in.'))]) module = StringField(gettext('Module'), validators=[InputRequired(gettext('Please enter the module/course/lecture that was outstanding.'))]) reason = StringField(gettext('Reason'), validators=[InputRequired(gettext('Please enter a reason why the nominee shall be awarded.'))]) tos = BooleanField(gettext('The nominee is eligible for the award.'), validators=[InputRequired(gettext('Please verify the eligibility beforehand.'))]) @@ -310,6 +317,7 @@ class InstanceForm(Form): name = StringField(gettext('Name'), validators=[InputRequired(gettext('Please enter the instances name, e.g. a semester identifier.'))]) enabled = BooleanField(gettext('Enable'), validators=[Optional()]) date = DateField(gettext('Award Date'), description=getttext('Please use the format YYYY-MM-DD.'), validators=[InputRequired(gettext('Please enter the date this is instance is awarded.'))]) + categories = StringField(gettext('Categories'), description=gettext('Please enter one or more nomination categories and seperate them using a semicolon.'), validators=[InputRequired(gettext('Please enter some categories.'))]) class EnableForm(Form): pass diff --git a/templates/delete.html b/templates/delete.html index e0dbe4c..b542e3e 100644 --- a/templates/delete.html +++ b/templates/delete.html @@ -14,6 +14,10 @@ <label for="mod" class="control-label">{{ gettext('Date') }}</label> <code id="mod" name="mod">{{ inst.date|dateformat('long') }}</code> </div> +<div class="form-group"> + <label for="cat" class="control-label">{{ gettext('Categories') }}</label> + <code id="cat" name="cat">{{ inst.categories }}</code> +</div> <div class="form-group"> <label for="enabled" class="control-label">{{ gettext('Enabled') }}</label> <code id="enabled" name="enabled">{{ gettext('Yes') if inst.enabled else gettext('No') }}</code> diff --git a/templates/disable.html b/templates/disable.html index 59de575..c932037 100644 --- a/templates/disable.html +++ b/templates/disable.html @@ -14,6 +14,10 @@ <label for="mod" class="control-label">{{ gettext('Date') }}</label> <code id="mod" name="mod">{{ inst.date|dateformat('long') }}</code> </div> +<div class="form-group"> + <label for="cat" class="control-label">{{ gettext('Categories') }}</label> + <code id="cat" name="cat">{{ inst.categories }}</code> +</div> <div class="form-group"> <label for="enabled" class="control-label">{{ gettext('Enabled') }}</label> <code id="enabled" name="enabled">{{ gettext('Yes') if inst.enabled else gettext('No') }}</code> diff --git a/templates/enable.html b/templates/enable.html index 22b4e7a..ef45fdf 100644 --- a/templates/enable.html +++ b/templates/enable.html @@ -14,6 +14,10 @@ <label for="mod" class="control-label">{{ gettext('Date') }}</label> <code id="mod" name="mod">{{ inst.date|dateformat('long') }}</code> </div> +<div class="form-group"> + <label for="cat" class="control-label">{{ gettext('Categories') }}</label> + <code id="cat" name="cat">{{ inst.categories }}</code> +</div> <div class="form-group"> <label for="enabled" class="control-label">{{ gettext('Enabled') }}</label> <code id="enabled" name="enabled">{{ gettext('Yes') if inst.enabled else gettext('No') }}</code> diff --git a/templates/nomination.txt b/templates/nomination.txt index c908c5d..1925b2e 100644 --- a/templates/nomination.txt +++ b/templates/nomination.txt @@ -1,4 +1,4 @@ -{% trans instance=nom.instance.name, person=nom.person, module=nom.module, reason=nom.reason %} +{% trans instance=nom.instance.name, person=nom.person, module=nom.module, reason=nom.reason, category=nom.category %} Dear committee members, the following nomination for {{ instance }} was submitted: @@ -6,6 +6,7 @@ the following nomination for {{ instance }} was submitted: Person: {{ person }} Module: {{ module }} Reason: {{ reason }} +Category: {{ category }} {% endtrans %} {% trans %}You can view all nominations by visiting the following URL:{% endtrans %} diff --git a/templates/nominees.html b/templates/nominees.html index bfe3430..f863c60 100644 --- a/templates/nominees.html +++ b/templates/nominees.html @@ -16,6 +16,7 @@ <th>{{ gettext('Nominee') }}</th> <th>{{ gettext('Module') }}</th> <th>{{ gettext('Reason') }}</th> + <th>{{ gettext('Category') }}</th> </tr> </thead> <tbody> @@ -24,6 +25,7 @@ <td>{{ nom.person }}</td> <td>{{ nom.module }}</td> <td>{{ nom.reason }}</td> + <td>{{ nom.category}}</td> </tr> {% endfor %} </tbody> -- GitLab