Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from deckn/master

Forms added
  • Loading branch information...
commit 1a9534102bf2a1cbba1d98b432a6bf9eec7d0d68 2 parents d7187be + 7a2a523
@exhuma exhuma authored
View
33 lost_tracker/core.py
@@ -1,6 +1,7 @@
from lost_tracker.models import (
Group,
Station,
+ Form,
get_state,
STATE_FINISHED,
STATE_UNKNOWN,
@@ -111,3 +112,35 @@ def add_station(stat_name, contact, phone, session):
session.add(new_station)
return "Station {0} added. Contact: {1} / {2}".format(
stat_name, contact, phone)
+
+
+def add_form_db(form_id, name, max_score, session):
+ tmp_form = get_form_by_id(form_id)
+ if tmp_form:
+ tmp_form.name = name
+ tmp_form.max_score = max_score
+ return "Form {0} updated: {1} - max: {2}".format(
+ form_id, name, max_score)
+ else:
+ new_form = Form(form_id, name, max_score)
+ session.add(new_form)
+ return "Form added: {0} - {1} - max: {2}".format(
+ form_id, name, max_score)
+
+def get_forms():
+ """
+ Returns all forms from the database as :py:class`Form` instances.
+ """
+ forms = Form.query
+ forms = forms.order_by(Form.id)
+ forms = forms.all()
+ return forms
+
+def get_form_by_id(id):
+ """
+ Returns a :py:class:`Form` by class id.
+ """
+ qry = Form.query
+ qry = qry.filter_by(id=id)
+ qry = qry.first()
+ return qry
View
21 lost_tracker/main.py
@@ -3,7 +3,8 @@
from sqlalchemy import create_engine
from lost_tracker.core import (get_matrix, get_state_sum, get_grps, add_grp,
- get_stations, add_station, get_stat_by_name)
+ get_stations, add_station, get_stat_by_name,
+ add_form_db, get_forms)
from flask import (Flask, render_template, abort, jsonify, g, request, flash,
url_for, redirect)
@@ -199,6 +200,24 @@ def form_score():
return redirect(url_for("init_form_score"))
+
+@app.route('/add_form')
+def init_add_form():
+ message = ""
+ forms = get_forms()
+ return render_template('add_form.html', message=message, forms=forms)
+
+
+@app.route('/add_form', methods=['POST'])
+def add_form():
+ form_id = int(request.form['form_id'])
+ name = request.form['name']
+ max_score = int(request.form['max_score'])
+ message = add_form_db(form_id, name, max_score, g.session)
+ flash(message)
+ return redirect(url_for("init_add_form"))
+
+
if __name__ == '__main__':
app.run(debug=app.config.get('DEBUG', False),
host=app.config.get('LISTEN'),
View
16 lost_tracker/models.py
@@ -265,3 +265,19 @@ def __init__(self, name=None, contact=None, phone=None):
def __repr__(self):
return '<Station %r>' % (self.name)
+
+
+class Form(Base):
+ __tablename__ = 'form'
+ id = Column(Integer, primary_key=True)
+ name = Column(Unicode(20))
+ max_score = Column(Integer)
+
+ def __init__(self, id=0, name=None, max_score=100):
+ self.name = name
+ self.max_score = max_score
+
+ def __repr__(self):
+ return '<Form %r>' % (self.name)
+
+
View
2  lost_tracker/templates/add_group.html
@@ -48,7 +48,7 @@
<input type="submit">
</form>
-<table border=1">
+<table border="1">
<tr>
<th>Gruppennumm</th>
<th>Kontakt</th>
Please sign in to comment.
Something went wrong with that request. Please try again.