1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Candidate/__init__.py Fri Sep 30 22:54:17 2005 +0000
1.3 @@ -0,0 +1,110 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"A job candidate editing application."
1.7 +
1.8 +import WebStack.Generic
1.9 +import XSLForms.Resources
1.10 +import XSLForms.Utils
1.11 +import os
1.12 +
1.13 +# Site map imports.
1.14 +
1.15 +from WebStack.Resources.ResourceMap import MapResource
1.16 +from WebStack.Resources.Static import DirectoryResource
1.17 +
1.18 +# Resource classes.
1.19 +
1.20 +class CandidateResource(XSLForms.Resources.XSLFormsResource):
1.21 +
1.22 + "A resource providing editing facilities for a job candidate profile."
1.23 +
1.24 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.25 + encoding = "utf-8"
1.26 + template_resources = {
1.27 + "candidate" : ("candidate_template.xhtml", "candidate_output.xsl")
1.28 + }
1.29 + transform_resources = {
1.30 + "init" : ["candidate_init.xsl"]
1.31 + }
1.32 + document_resources = {
1.33 + "status" : "candidate_status.xml"
1.34 + }
1.35 + in_page_resources = {
1.36 + }
1.37 +
1.38 + def respond_to_form(self, trans, form):
1.39 +
1.40 + """
1.41 + Respond to a request having the given transaction 'trans' and the given
1.42 + 'form' information.
1.43 + """
1.44 +
1.45 + in_page_resource = self.get_in_page_resource(trans)
1.46 + parameters = form.get_parameters()
1.47 + documents = form.get_documents()
1.48 +
1.49 + # Ensure the presence of a document.
1.50 +
1.51 + if documents.has_key("candidate"):
1.52 + candidate = documents["candidate"]
1.53 + else:
1.54 + candidate = form.new_instance("candidate")
1.55 +
1.56 + # Add and remove elements according to the selectors found.
1.57 +
1.58 + selectors = form.get_selectors()
1.59 + XSLForms.Utils.remove_elements(selectors.get("remove"))
1.60 + XSLForms.Utils.add_elements(selectors.get("add-skill"), "skill", "skills")
1.61 + XSLForms.Utils.add_elements(selectors.get("add-qualification"), "qualification", "qualifications")
1.62 + XSLForms.Utils.add_elements(selectors.get("add-employment"), "employment", "experience")
1.63 +
1.64 + # Transform, adding enumerations/ranges.
1.65 +
1.66 + init_xsl = self.prepare_transform("init")
1.67 + status_xml = self.prepare_document("status")
1.68 + candidate = self.get_result(init_xsl, candidate, references={"status" : status_xml})
1.69 +
1.70 + # Start the response.
1.71 +
1.72 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
1.73 +
1.74 + # Define the stylesheet parameters.
1.75 +
1.76 + stylesheet_parameters = {}
1.77 +
1.78 + # Ensure that an output stylesheet exists.
1.79 +
1.80 + if in_page_resource in self.in_page_resources.keys():
1.81 + trans_xsl = self.prepare_fragment("candidate", in_page_resource)
1.82 + element_path = parameters.get("element-path", [""])[0]
1.83 + stylesheet_parameters["element-path"] = element_path
1.84 + else:
1.85 + trans_xsl = self.prepare_output("candidate")
1.86 +
1.87 + # Complete the response.
1.88 +
1.89 + self.send_output(trans, [trans_xsl], candidate, stylesheet_parameters)
1.90 +
1.91 +# Site map initialisation.
1.92 +
1.93 +def get_site():
1.94 +
1.95 + "Return a simple Web site resource."
1.96 +
1.97 + # Get the main resource and the directory used by the application.
1.98 +
1.99 + candidate_resource = CandidateResource()
1.100 + directory = candidate_resource.resource_dir
1.101 +
1.102 + # Make a simple Web site.
1.103 +
1.104 + resource = MapResource({
1.105 + # Static resources:
1.106 + #"scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}),
1.107 + # Main page and in-page resources:
1.108 + None : candidate_resource
1.109 + })
1.110 +
1.111 + return resource
1.112 +
1.113 +# vim: tabstop=4 expandtab shiftwidth=4