From cac5ec5db243f195b28c79d4cf75e201214065c2 Mon Sep 17 00:00:00 2001
From: lars
Date: Sat, 18 Aug 2012 01:21:43 +0000
Subject: [PATCH] Datenbank-Zusammenfassung hinzugefuegt Antworten werden nun
nur noch gespeichert, wenn das Text- oder Bewertungsfeld nicht leer ist
---
umfrage_kirchenplatz2012/src/umfrage.py | 37 ++++++++++++++---
umfrage_kirchenplatz2012/templates/db.html | 46 ++++++++++++++++++++++
2 files changed, 78 insertions(+), 5 deletions(-)
create mode 100644 umfrage_kirchenplatz2012/templates/db.html
diff --git a/umfrage_kirchenplatz2012/src/umfrage.py b/umfrage_kirchenplatz2012/src/umfrage.py
index cdcbfd2..fc5ad9a 100644
--- a/umfrage_kirchenplatz2012/src/umfrage.py
+++ b/umfrage_kirchenplatz2012/src/umfrage.py
@@ -225,6 +225,7 @@ def do_submit(session_id=None, subject=None, from_address=None,
title=subject, text=summary_text)
return render("submitted.html", **params)
+
def get_quality_text(question, quality):
for key, text in question.quality_levels:
if key == quality:
@@ -287,6 +288,16 @@ def show_summary(session):
def render_question(session, question):
input_data = {}
+ for option in Option.select():
+ for key in ("text", "quality"):
+ dict_key = "option_%s_%s" % (option.id, key)
+ answers = list(Answer.selectBy(session=session, question=question,
+ option=option))
+ if answers:
+ input_data[dict_key] = getattr(answers[0], key)
+ else:
+ # this seems to be necessary for the input filter of genshi
+ input_data[dict_key] = ""
for answer in Answer.selectBy(session=session, question=question):
for key in ("text", "quality"):
input_data["option_%s_%s" % (answer.option.id, key)] = \
@@ -300,6 +311,17 @@ def render_question(session, question):
return render("question.html", input_data=input_data, **params)
+@bobo.query('/db')
+def show_db():
+ params = get_default_values()
+ params["Session"] = Session
+ params["Question"] = Question
+ params["Option"] = Option
+ params["Answer"] = Answer
+ params["Submission"] = Submission
+ return render("db.html", **params)
+
+
@bobo.query('/')
def update_question(bobo_request, session_id=None, question_id=None,
go_backward=False):
@@ -323,12 +345,12 @@ def update_question(bobo_request, session_id=None, question_id=None,
opt_params = {}
for key in ("text", "quality"):
dict_key = "option_%s_%s" % (option.id, key)
- if dict_key in kwargs:
+ if (dict_key in kwargs) and kwargs[dict_key]:
opt_params[key] = kwargs[dict_key]
+ answers = Answer.selectBy(session=session, question=question,
+ option=option)
# at least one item was found
if opt_params:
- answers = Answer.selectBy(session=session, question=question,
- option=option)
if answers.count() > 0:
answer = answers[0]
else:
@@ -336,8 +358,13 @@ def update_question(bobo_request, session_id=None, question_id=None,
answer = Answer(session=session, question=question,
option=option)
# update one value
- for key in opt_params:
- setattr(answer, key, opt_params[key])
+ for key in ("text", "quality"):
+ setattr(answer, key, opt_params.get(key, ""))
+ else:
+ # everything is empty -> delete answer
+ if ("option_%s_%s" % (option.id, "text") in kwargs) and \
+ (answers.count() > 0):
+ answers[0].destroySelf()
if go_backward:
target_question = get_previous_question(question)
else:
diff --git a/umfrage_kirchenplatz2012/templates/db.html b/umfrage_kirchenplatz2012/templates/db.html
new file mode 100644
index 0000000..a7f9312
--- /dev/null
+++ b/umfrage_kirchenplatz2012/templates/db.html
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+Datenbank
+
+Antworten
+
+
+ Frage # |
+ Anzahl |
+
+
+ ${question.weight} |
+ ${Answer.selectBy(question=question, option=Option.select()[0]).count()} |
+
+
+
+Sitzungen
+
+
+ Sitzung # |
+ Datum |
+ Fragen |
+ versandt |
+ Standard? |
+
+
+ ${session.id} |
+ ${session.created} |
+ ${Answer.selectBy(session=session).count()} |
+ ${Submission.selectBy(session=session).count() > 0} |
+ ${Submission.selectBy(session=session, to_default_destination=True).count() > 0} |
+
+
+
+
+
+