summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Geyso <nico.geyso@fu-berlin.de>2014-12-10 01:11:17 +0100
committerNico Geyso <nico.geyso@fu-berlin.de>2014-12-10 01:11:17 +0100
commitfc1c782fba3967607e35f83f9c12a9db26c30fc9 (patch)
tree3f3efa3d5c740f92f24bbd6d3caf7cdfdc30a25b
parent3283c54d915ada01ce44dda9fb3f4472c41566f6 (diff)
downloadklausuren-fc1c782fba3967607e35f83f9c12a9db26c30fc9.tar.gz
klausuren-fc1c782fba3967607e35f83f9c12a9db26c30fc9.tar.bz2
klausuren-fc1c782fba3967607e35f83f9c12a9db26c30fc9.zip
Remove optinal slug for forms
-rw-r--r--app/forms.py3
-rw-r--r--app/main.py20
2 files changed, 6 insertions, 17 deletions
diff --git a/app/forms.py b/app/forms.py
index 2332179..355314c 100644
--- a/app/forms.py
+++ b/app/forms.py
@@ -29,9 +29,8 @@ class UploadForm(Form):
raise ValidationError(u'Zu große Datei')
def validate_course(form, field):
- courses = dict(current_app.config['STUDIES'][form.study.data])
data = form.course.data
- if data not in courses or data == '':
+ if (data, data) not in field.choices or data == '':
raise ValidationError(u'Bitte wähle einen Kurs!')
diff --git a/app/main.py b/app/main.py
index ef4e549..180715e 100644
--- a/app/main.py
+++ b/app/main.py
@@ -23,15 +23,6 @@ def get_studies():
path_rel = os.path.join('studies', abbr)
path_app = os.path.join('app', 'static', path_rel)
studies[abbr] = Storage(path_rel, path_app)
-
- # iterate over all courses in our backend
- for course in g._studies[abbr].get_courses():
- # check if course is already listed
- entry = (course.encode('ascii', errors='ignore'), course)
- if entry not in courses:
- current_app.config['STUDIES'][abbr].append(entry)
-
- current_app.config['STUDIES'][abbr].sort()
return studies
@@ -43,7 +34,10 @@ def upload(study, course = None):
form.study.data = study
# dynamically fill form values
- form.course.choices = current_app.config['STUDIES'][study]
+ courses = set(current_app.config['STUDIES'][study] +
+ get_studies()[study].get_courses())
+ choices = [(k,k) for k in sorted(courses, key=unicode.lower)]
+ form.course.choices = choices
if 'new' not in dict(form.course.choices):
form.course.choices.append(('', u'---'))
form.course.choices.append(('new', u'neuen Kurs hinzufügen'))
@@ -51,12 +45,8 @@ def upload(study, course = None):
if form.validate_on_submit():
if form.course.data == 'new':
course = form.course_new.data
- slug = course.encode('ascii', errors='ignore')
- current_app.config['STUDIES'][study].append((slug,course))
- current_app.config['STUDIES'][study].sort()
-
else:
- course = dict(current_app.config['STUDIES'][study])[form.course.data]
+ course = form.course.data
year = form.year.data
filename = secure_filename(form.exam.data.filename)