1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/BaseHTTPRequestHandler/QuestionPlayerApp.py Fri Nov 21 01:42:17 2008 +0100
1.3 @@ -0,0 +1,15 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy
1.7 +import QuestionPlayer
1.8 +
1.9 +# Get a simple Web site.
1.10 +
1.11 +resource = QuestionPlayer.get_site()
1.12 +
1.13 +# Special magic incantation.
1.14 +
1.15 +print "Serving..."
1.16 +deploy(resource, handle_errors=0)
1.17 +
1.18 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/QuestionPlayer/Resources/player_template.xhtml Fri Nov 21 01:42:17 2008 +0100
2.3 @@ -0,0 +1,100 @@
2.4 +<?xml version="1.0" encoding="iso-8859-1"?>
2.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
2.6 + "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
2.7 +<html xmlns="http://www.w3.org/1999/xhtml"
2.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
2.9 +<head>
2.10 + <title>Questionnaire</title>
2.11 + <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles/styles.css"
2.12 + rel="stylesheet" type="text/css" />
2.13 +</head>
2.14 +
2.15 +<body template:element="questionnaire">
2.16 +<h1>Questionnaire</h1>
2.17 +
2.18 +<form method="POST" action="">
2.19 +
2.20 +<div class="questionnaire">
2.21 +
2.22 + <div class="shadow">
2.23 +
2.24 + <table class="questionnaire">
2.25 + <tbody template:element="question" template:init="no">
2.26 + <tr>
2.27 + <th class="question">Question #<span template:value="count(preceding-sibling::question) + 1">n</span></th>
2.28 + <td class="question">
2.29 + <span template:value="@question-text">Question</span>
2.30 +
2.31 + <!-- Hidden state. -->
2.32 +
2.33 + <input template:attribute-field="question-text" type="hidden" name="..." value="..." />
2.34 + <input template:attribute-field="choice-response" type="hidden" name="..." value="..." />
2.35 + </td>
2.36 + </tr>
2.37 + <tr>
2.38 + <th class="response">Response</th>
2.39 + <td class="response">
2.40 + <div template:element="choice" template:init="no">
2.41 +
2.42 + <!-- Show a radio or checkbox if appropriate. -->
2.43 +
2.44 + <p xml:space="preserve">
2.45 +
2.46 + <span template:if="not(response-type/@value = 'text')">
2.47 +
2.48 + <!-- Show checkboxes. -->
2.49 +
2.50 + <input template:if="../@choice-response = 'multiple'"
2.51 + type="checkbox"
2.52 + name="{template:other-list-attributes('selected', 'value', ..)}" value="{@response-choice}"
2.53 + template:expr="count(../selected[@value = current()/@response-choice]) > 0" template:expr-attr="checked" />
2.54 +
2.55 + <!-- Show radio boxes. -->
2.56 +
2.57 + <input template:if="not(../@choice-response = 'multiple')"
2.58 + type="radio"
2.59 + name="{template:other-attributes('selected', ..)}" value="{@response-choice}"
2.60 + template:expr="../@selected = @response-choice" template:expr-attr="checked" />
2.61 +
2.62 + </span>
2.63 +
2.64 + <span template:value="@response-choice">Choice</span>
2.65 + </p>
2.66 +
2.67 + <!-- Show a text box if appropriate. -->
2.68 +
2.69 + <p template:if="response-type/@value and not(response-type/@value = 'choice')">
2.70 + <input template:attribute-field="response-text" type="text" size="40" name="..." value="..." />
2.71 + </p>
2.72 +
2.73 + <!-- Hidden state. -->
2.74 +
2.75 + <input template:element="response-type" template:attribute-field="value" type="hidden" name="..." value="..." />
2.76 + <input template:attribute-field="response-choice" type="hidden" name="..." value="..." />
2.77 + </div>
2.78 + </td>
2.79 + </tr>
2.80 + </tbody>
2.81 + </table>
2.82 +
2.83 + </div>
2.84 +
2.85 +</div>
2.86 +
2.87 +<div class="operations">
2.88 +
2.89 + <p>
2.90 + <input type="submit" value="Update" name="update" /> to refresh the form.
2.91 + </p>
2.92 +
2.93 + <p>
2.94 + <input type="submit" value="Finish" name="finish" /> when you are happy with
2.95 + your responses.
2.96 + </p>
2.97 +
2.98 +</div>
2.99 +
2.100 +</form>
2.101 +
2.102 +</body>
2.103 +</html>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/Common/QuestionPlayer/Resources/styles/styles.css Fri Nov 21 01:42:17 2008 +0100
3.3 @@ -0,0 +1,61 @@
3.4 +/* Page sections. */
3.5 +
3.6 +div.questionnaire {
3.7 + padding: 10px;
3.8 +}
3.9 +
3.10 +div.operations {
3.11 + padding-top: 10px;
3.12 + clear: both;
3.13 +}
3.14 +
3.15 +/* Questionnaire and shadow effect. */
3.16 +
3.17 +div.shadow {
3.18 + background-color: #555555;
3.19 +}
3.20 +
3.21 +div.shadow table.questionnaire {
3.22 + background-color: #ffffff;
3.23 + border: 1px solid #000000;
3.24 + padding: 5px;
3.25 + position: relative;
3.26 + top: -10px;
3.27 + left: -10px;
3.28 +}
3.29 +
3.30 +/* Questionnaire table. */
3.31 +
3.32 +table.questionnaire {
3.33 + width: 100%;
3.34 + border-spacing: 0px;
3.35 +}
3.36 +
3.37 +/* Questionnaire and preview cells. */
3.38 +
3.39 +table.questionnaire td, table.questionnaire th {
3.40 + padding: 10px;
3.41 + margin: 0px;
3.42 +}
3.43 +
3.44 +table.questionnaire td p {
3.45 + margin: 0px 5px 5px 5px;
3.46 +}
3.47 +
3.48 +.question, .question-options {
3.49 + background-color: #dddddd;
3.50 + color: #000000;
3.51 + vertical-align: top;
3.52 +}
3.53 +
3.54 +.response, .response-options {
3.55 + background-color: #ffffff;
3.56 + color: #000000;
3.57 + vertical-align: top;
3.58 +}
3.59 +
3.60 +.choice, .choice-options {
3.61 + background-color: #eeeeee;
3.62 + color: #000000;
3.63 + vertical-align: top;
3.64 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/examples/Common/QuestionPlayer/__init__.py Fri Nov 21 01:42:17 2008 +0100
4.3 @@ -0,0 +1,101 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +"""
4.7 +A WebStack application for "playing" questionnaires designed by the
4.8 +questionnaire editor.
4.9 +"""
4.10 +
4.11 +import WebStack.Generic
4.12 +from XSLForms.Resources.WebResources import \
4.13 + XSLFormsResource, input, output, resources, prepare_resources as xslforms_prepare_resources
4.14 +import os
4.15 +import libxml2dom
4.16 +from WebStack.Repositories.Directory import DirectoryRepository
4.17 +import time
4.18 +
4.19 +# Site map imports.
4.20 +
4.21 +from WebStack.Resources.ResourceMap import MapResource
4.22 +from WebStack.Resources.Selectors import EncodingSelector
4.23 +from WebStack.Resources.Static import DirectoryResource
4.24 +
4.25 +# Configuration settings.
4.26 +
4.27 +encoding = "utf-8"
4.28 +storage_directory = os.path.join(os.getcwd(), "Responses")
4.29 +
4.30 +# Resource classes.
4.31 +
4.32 +class QuestionnairePlayerResource(XSLFormsResource):
4.33 +
4.34 + "A resource providing a questionnaire editor."
4.35 +
4.36 + resource_dir = resources(__file__)
4.37 + template_resources = {
4.38 + "questionnaire" : output("player_template.xhtml")
4.39 + }
4.40 + #init_resources = {
4.41 + # "questionnaire" : input("player_template.xhtml")
4.42 + # }
4.43 + document_resources = {
4.44 + "questions" : "questions.xml"
4.45 + }
4.46 +
4.47 + def select_activity(self, trans, form):
4.48 + form.set_activity("questionnaire")
4.49 +
4.50 + def create_document(self, trans, form):
4.51 + if XSLFormsResource.create_document(self, trans, form):
4.52 + questions_xml = self.prepare_document("questions")
4.53 + questions = libxml2dom.parse(questions_xml)
4.54 + doc = form.get_document()
4.55 + imported_questions = doc.importNode(questions.documentElement, 1)
4.56 + doc.replaceChild(imported_questions, doc.documentElement)
4.57 +
4.58 + def respond_to_input(self, trans, form):
4.59 +
4.60 + parameters = form.get_parameters()
4.61 + selectors = form.get_selectors()
4.62 + questionnaire = form.get_document()
4.63 +
4.64 + # Send a response according to certain parameters.
4.65 + # When saved, an XML version of the data is employed.
4.66 +
4.67 + if parameters.has_key("finish"):
4.68 + repository = DirectoryRepository(storage_directory)
4.69 + key = str(time.time())
4.70 + output_filename = repository.lock(key, 1)
4.71 + try:
4.72 + questionnaire.toStream(open(output_filename, "wb"), "utf-8", prettyprint=1)
4.73 + finally:
4.74 + repository.unlock(key)
4.75 +
4.76 +# Site map initialisation.
4.77 +
4.78 +def get_site():
4.79 +
4.80 + "Return a simple Web site resource."
4.81 +
4.82 + # Get the main resource and the directory used by the application.
4.83 +
4.84 + questionnaire_resource = QuestionnairePlayerResource()
4.85 + directory = questionnaire_resource.resource_dir
4.86 +
4.87 + # Make a simple Web site.
4.88 +
4.89 + resource = MapResource({
4.90 + # Static resources:
4.91 + "styles" : DirectoryResource(os.path.join(directory, "styles"), {"css" : "text/css"}),
4.92 + # Main page:
4.93 + "" : questionnaire_resource
4.94 + })
4.95 +
4.96 + return EncodingSelector(resource, encoding)
4.97 +
4.98 +# Resource preparation ahead of time - useful for making installations.
4.99 +
4.100 +def prepare_resources():
4.101 + for cls in [QuestionnairePlayerResource]:
4.102 + xslforms_prepare_resources(cls)
4.103 +
4.104 +# vim: tabstop=4 expandtab shiftwidth=4