def viewpersonregistration(registration_id): '''Display the selected registration of the current user.''' if users.user_id() != games.get_registration_person(registration_id): return redirect(url_for("index")) user_profile = users.get_profile() game_id = games.get_registration_game(registration_id) game = games.get_details(game_id) gameform = gameforms.get_game_form(game_id) form_data = { "form_id": gameform['id'], "form_name": gameform['name'], "published": gameform['published'] } form = RegistrationForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) question_list = gameforms.get_form_questions(gameform['id']) for question in question_list: question['options'] = questions.get_question_options(question['id']) question['answer'] = answers.get_question_answer( registration_id, question['id']) return render_template("registration.html", form=form, question_list=question_list, action="", title="Ilmoittautuminen: " + game['name'], mode="person")
def game_details(game_id): '''Display the details of the given game.''' game = games.get_details(game_id) if users.user_id() in map(lambda org: org['id'], game['organisers']): registrations = games.get_registrations(game_id) return render_template("gamedetails.html", game=game, organiser=True, registrations=registrations) else: return render_template("gamedetails.html", game=game, organiser=False)
def editform_edit_question(game_id): '''Display the editing page for the submitting question.''' if request.form.get('add_option') or request.form.get('delete_option'): game = games.get_details(game_id) options = [] for field, value in request.form.items(): if 'option_text' in field and value.strip( ) != '' and request.form.get('delete_option') != value: options.append(value.strip()) form_data = request.form form = EditQuestionForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) field_type_name = gameforms.get_field_type_name( request.form['field_type']) return render_template("edit_question.html", form=form, game=game, options=options, action="/game/" + game_id + "/form/edit/update_question", title="Kysymyksen muokkaus: " + field_type_name) else: game = games.get_details(game_id) question = questions.get_question(request.form["edit_question"]) form_data = { "formquestion_id": question['id'], "field_type": str(question['field_type']), "text": question['text'], "description": question['description'] } form = EditQuestionForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) field_type_name = gameforms.get_field_type_name(question['field_type']) options = map(lambda d: d['text'], question['options']) return render_template("edit_question.html", form=form, game=game, options=options, action="/game/" + game_id + "/form/edit/update_question", title="Kysymyksen muokkaus: " + field_type_name)
def downloadgameregistrations(game_id): '''Download the list of registrations for the game as a json list.''' game = games.get_details(game_id) if users.user_id() not in map(lambda org: org['id'], game['organisers']): return redirect(url_for("index")) registration_list = games.get_registration_data(game_id) json_string = json.dumps(registration_list) return Response(json_string, mimetype='application/json', headers={ 'Content-Disposition': 'attachment;filename=registrations.json' })
def editgame(game_id): '''Display the game editor form on GET and save the edited game on POST.''' game = games.get_details(game_id) game['start_date'] = game['start_date'].strftime('%d.%m.%Y') game['end_date'] = game['end_date'].strftime('%d.%m.%Y') if users.user_id() not in map(lambda org: org['id'], game['organisers']): return redirect(url_for("index")) form = GameForm(data=game, meta={'locales': ['fi_FI', 'fi']}) if request.method == 'GET': has_form = False if gameforms.get_game_form(game_id) is None else True is_published = gameforms.is_published(game_id) if len(games.get_registrations(game_id)) > 0: form.edit_form.render_kw = {'disabled': 'disabled'} return render_template("game_editor.html", form=form, action="/game/" + game_id + "/edit", title=game['name'] + ": Tietojen päivitys", has_form=has_form, is_published=is_published) if request.method == 'POST': if 'create_form' in request.form: game_form = gameforms.create_game_form(game_id) gameforms.insert_default_questions(game_form['id']) return redirect("/game/" + game_id + "/form/edit") elif 'edit_form' in request.form: return redirect("/game/" + game_id + "/form/edit") elif 'publish_form' in request.form: gameforms.publish_form(gameforms.get_game_form(game_id)["id"]) flash("Pelin ilmoittautuminen avattu", "success") return redirect("/game/" + game_id + "/edit") elif 'unpublish_form' in request.form: gameforms.unpublish_form(gameforms.get_game_form(game_id)["id"]) flash("Pelin ilmoittautuminen suljettu", "success") return redirect("/game/" + game_id + "/edit") if form.validate_on_submit(): name = request.form["name"] start_date = datetime.datetime.strptime(request.form["start_date"], '%d.%m.%Y') end_date = datetime.datetime.strptime(request.form["end_date"], '%d.%m.%Y') location = request.form["location"] price = request.form["price"] description = request.form["description"] if games.send(users.user_id(), game_id, name, start_date, end_date, location, price, description): flash("Pelin tiedot päivitetty", "success") return redirect("/game/" + game_id + "/edit") else: flash("Pelin tietojen päivitys ei onnistunut", "error") return redirect("/game/" + game_id + "/edit")
def gameregistration(game_id): '''Display the game registration form for the given game on GET and save the registration on POST.''' game = games.get_details(game_id) gameform = gameforms.get_game_form(game_id) form_data = { "form_id": gameform['id'], "form_name": gameform['name'], "published": gameform['published'] } if gameform['published'] == False: return redirect(url_for("index")) form = RegistrationForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) if request.method == 'GET': question_list = gameforms.get_form_questions(gameform['id']) prefill_data = users.get_prefill_data(game) for question in question_list: question['options'] = questions.get_question_options( question['id']) return render_template("registration.html", game=game, form=form, question_list=question_list, prefill_data=prefill_data, action="/game/" + game_id + "/register", title="Ilmoittautuminen: " + game['name'], mode="register") if form.validate_on_submit(): answer_list = [] for key, value in request.form.items(): if "checkbox" in key or "radio" in key: answer_list.append({ "person_id": users.user_id(), "formquestion_id": key.split("_")[1], "option_id": value }) elif "integer" in key or "string" in key or "textarea" in key: answer_list.append({ "person_id": users.user_id(), "formquestion_id": key.split("_")[1], "answer_text": value }) if answers.save_answers(users.user_id(), game_id, answer_list): flash("Ilmoittautuminen tallennettu", "success") return redirect(url_for("index")) else: flash("Ilmoittautuminen ei onnistunut", "error") return redirect("/game/" + game_id + "/register")
def editform_new_question_new_option(game_id): '''Add a new option to the list of options contained in the form and display the updated question edit view.''' game = games.get_details(game_id) options = [] for field, value in request.form.items(): if 'option_text' in field and value.strip() != '': options.append(value.strip()) form_data = request.form form = NewQuestionForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) field_type_name = gameforms.get_field_type_name(request.form['field_type']) return render_template("new_question.html", form=form, game=game, options=options, action="/game/" + game_id + "/form/edit/new_question", title="Uuden kysymyksen luonti: " + field_type_name)
def previewform(game_id): '''Display an inactive preview of the current registration form.''' game = games.get_details(game_id) if users.user_id() not in map(lambda org: org['id'], game['organisers']): return redirect(url_for("index")) gameform = gameforms.get_game_form(game_id) form_data = {"form_id": gameform['id'], "form_name": gameform['name']} form = RegistrationForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) question_list = gameforms.get_form_questions(gameform['id']) for question in question_list: question['options'] = questions.get_question_options( int(question['id'])) return render_template("form_preview.html", game=game, form=form, question_list=question_list, action="", title="Ilmoittautumislomakkeen esikatselu")
def editform(game_id): '''Display the registration form editor on GET and open the new question editor on POST.''' game = games.get_details(game_id) if users.user_id() not in map(lambda org: org['id'], game['organisers']): return redirect(url_for("index")) if len(games.get_registrations(game_id)) > 0: return redirect("/game/" + game_id + "/edit") gameform = gameforms.get_game_form(game_id) form_data = {"form_id": gameform['id'], "form_name": gameform['name']} form = FormEditForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) field_types = gameforms.get_field_types() if request.method == 'GET': question_list = gameforms.get_form_questions(gameform['id']) for question in question_list: question['options'] = questions.get_question_options( int(question['id'])) return render_template("form_editor.html", game=game, form=form, question_list=question_list, field_types=field_types, action="/game/" + game_id + "/form/edit", title="Ilmoittautumislomakkeen muokkaus") elif form.validate_on_submit() and request.form.get('field_type'): form_data = { "form_id": request.form['form_id'], "field_type": request.form['field_type'], "text": "", "description": "" } field_type_name = gameforms.get_field_type_name( request.form['field_type']) form = NewQuestionForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) return render_template( "new_question.html", form=form, game=game, options=[], action="/game/" + game_id + "/form/edit/new_question", title="Uuden kysymyksen luonti: " + field_type_name) else: return redirect("/game/" + game_id + "/form/edit")
def viewgameregistration(game_id, registration_id): '''Display the given registration for the given game.''' game = games.get_details(game_id) if users.user_id() not in map(lambda org: org['id'], game['organisers']): return redirect(url_for("index")) gameform = gameforms.get_game_form(game_id) form_data = { "form_id": gameform['id'], "form_name": gameform['name'], "published": gameform['published'] } form = RegistrationForm(data=form_data, meta={'locales': ['fi_FI', 'fi']}) question_list = gameforms.get_form_questions(gameform['id']) for question in question_list: question['options'] = questions.get_question_options(question['id']) question['answer'] = answers.get_question_answer( registration_id, question['id']) return render_template("registration.html", form=form, question_list=question_list, action="", title="Ilmoittautuminen: " + game['name'], mode="game", game_id=game_id)