do not redirect on submit, display result on same page
This commit is contained in:
parent
2e089c894e
commit
31596802eb
|
@ -81,16 +81,27 @@ class EffectiveQuizForm(form.Form):
|
|||
|
||||
@button.buttonAndHandler(_(u'Submit'))
|
||||
def handleApply(self, action):
|
||||
return
|
||||
|
||||
def was_submitted(self):
|
||||
if self.request.form:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_correct(self):
|
||||
data, errors = self.extractData()
|
||||
error = False
|
||||
for key in self.fields._data.keys():
|
||||
if [data.get(key)] != self.good_answers[key]:
|
||||
error = True
|
||||
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
||||
if error:
|
||||
plone_utils.addPortalMessage(_('Some errors, somewhere...'))
|
||||
return self.request.response.redirect(self.context.context.absolute_url())
|
||||
else:
|
||||
plone_utils.addPortalMessage(_('Congrats, you know all about us!'))
|
||||
return self.request.response.redirect('./')
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_score(self):
|
||||
data, errors = self.extractData()
|
||||
error = False
|
||||
score = 0
|
||||
for key in self.fields._data.keys():
|
||||
if [data.get(key)] == self.good_answers[key]:
|
||||
score += 1
|
||||
return score
|
||||
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal">
|
||||
<body>
|
||||
<div tal:condition="view/was_submitted" id="quiz-result">
|
||||
<p tal:condition="view/is_correct" id="bravo">
|
||||
Bravo, vous connaissez tout de nous !
|
||||
</p>
|
||||
<p tal:condition="not: view/is_correct" tal:define="score view/get_score">
|
||||
Votre score :
|
||||
<span tal:condition="python: score == 0">Aucune bonne réponse.</span>
|
||||
<span tal:condition="python: score == 1">Une bonne réponse.</span>
|
||||
<span tal:condition="python: score > 1"><span tal:replace="score"/> bonnes réponses.</span>
|
||||
</p>
|
||||
</div>
|
||||
<form method="post" action="." tal:attributes="action context/absolute_url">
|
||||
<metal:use use-macro="context/@@ploneform-macros/fields" />
|
||||
<metal:use use-macro="context/@@ploneform-macros/actions" />
|
||||
|
|
Reference in New Issue