Datenbank-Zusammenfassung hinzugefuegt

Antworten werden nun nur noch gespeichert, wenn das Text- oder Bewertungsfeld nicht leer ist
This commit is contained in:
lars 2012-08-18 01:21:43 +00:00
parent 4807ec5dc3
commit cac5ec5db2
2 changed files with 78 additions and 5 deletions

View file

@ -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]
# at least one item was found
if opt_params:
answers = Answer.selectBy(session=session, question=question,
option=option)
# at least one item was found
if opt_params:
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:

View file

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:py="http://genshi.edgewall.org/"
lang="de">
<xi:include href="layout.html" />
<head/>
<body>
<h1>Datenbank</h1>
<h2>Antworten</h2>
<table border="1">
<tr>
<th>Frage #</th>
<th>Anzahl</th>
</tr>
<tr py:for="question in Question.select().orderBy('weight')">
<td>${question.weight}</td>
<td>${Answer.selectBy(question=question, option=Option.select()[0]).count()}</td>
</tr>
</table>
<h2>Sitzungen</h2>
<table border="1">
<tr>
<th>Sitzung #</th>
<th>Datum</th>
<th>Fragen</th>
<th>versandt</th>
<th>Standard?</th>
</tr>
<tr py:for="session in Session.select().orderBy('created')">
<td>${session.id}</td>
<td>${session.created}</td>
<td>${Answer.selectBy(session=session).count()}</td>
<td>${Submission.selectBy(session=session).count() > 0}</td>
<td>${Submission.selectBy(session=session, to_default_destination=True).count() > 0}</td>
</tr>
</table>
</body>
</html>