# HG changeset patch # User paulb # Date 1128120857 0 # Node ID 12aaeb3bfb876f9afeda34ed2c804a5ea9824ab9 # Parent a7a48357f7102ebe9aa9452f7ce5b44afc2f47d5 [project @ 2005-09-30 22:54:13 by paulb] Added another example application. diff -r a7a48357f710 -r 12aaeb3bfb87 examples/Common/Candidate/Resources/candidate_init.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Candidate/Resources/candidate_init.xsl Fri Sep 30 22:54:17 2005 +0000 @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r a7a48357f710 -r 12aaeb3bfb87 examples/Common/Candidate/Resources/candidate_status.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Candidate/Resources/candidate_status.xml Fri Sep 30 22:54:17 2005 +0000 @@ -0,0 +1,7 @@ + + + + + + + diff -r a7a48357f710 -r 12aaeb3bfb87 examples/Common/Candidate/Resources/candidate_template.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Candidate/Resources/candidate_template.xhtml Fri Sep 30 22:54:17 2005 +0000 @@ -0,0 +1,114 @@ + + + + + Candidate + + +
+ +

Candidate Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
General
Name + +
Work status + +
Skills
Skill + + +
+ +
Qualifications
Course/Diploma/Title + + +
Grade/Level/Class + +
Institution + +
+ +
Experience
Employment + From + to + +
Employer + +
+ +
+ +
+ + diff -r a7a48357f710 -r 12aaeb3bfb87 examples/Common/Candidate/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Candidate/__init__.py Fri Sep 30 22:54:17 2005 +0000 @@ -0,0 +1,110 @@ +#!/usr/bin/env python + +"A job candidate editing application." + +import WebStack.Generic +import XSLForms.Resources +import XSLForms.Utils +import os + +# Site map imports. + +from WebStack.Resources.ResourceMap import MapResource +from WebStack.Resources.Static import DirectoryResource + +# Resource classes. + +class CandidateResource(XSLForms.Resources.XSLFormsResource): + + "A resource providing editing facilities for a job candidate profile." + + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") + encoding = "utf-8" + template_resources = { + "candidate" : ("candidate_template.xhtml", "candidate_output.xsl") + } + transform_resources = { + "init" : ["candidate_init.xsl"] + } + document_resources = { + "status" : "candidate_status.xml" + } + in_page_resources = { + } + + def respond_to_form(self, trans, form): + + """ + Respond to a request having the given transaction 'trans' and the given + 'form' information. + """ + + in_page_resource = self.get_in_page_resource(trans) + parameters = form.get_parameters() + documents = form.get_documents() + + # Ensure the presence of a document. + + if documents.has_key("candidate"): + candidate = documents["candidate"] + else: + candidate = form.new_instance("candidate") + + # Add and remove elements according to the selectors found. + + selectors = form.get_selectors() + XSLForms.Utils.remove_elements(selectors.get("remove")) + XSLForms.Utils.add_elements(selectors.get("add-skill"), "skill", "skills") + XSLForms.Utils.add_elements(selectors.get("add-qualification"), "qualification", "qualifications") + XSLForms.Utils.add_elements(selectors.get("add-employment"), "employment", "experience") + + # Transform, adding enumerations/ranges. + + init_xsl = self.prepare_transform("init") + status_xml = self.prepare_document("status") + candidate = self.get_result(init_xsl, candidate, references={"status" : status_xml}) + + # Start the response. + + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding)) + + # Define the stylesheet parameters. + + stylesheet_parameters = {} + + # Ensure that an output stylesheet exists. + + if in_page_resource in self.in_page_resources.keys(): + trans_xsl = self.prepare_fragment("candidate", in_page_resource) + element_path = parameters.get("element-path", [""])[0] + stylesheet_parameters["element-path"] = element_path + else: + trans_xsl = self.prepare_output("candidate") + + # Complete the response. + + self.send_output(trans, [trans_xsl], candidate, stylesheet_parameters) + +# Site map initialisation. + +def get_site(): + + "Return a simple Web site resource." + + # Get the main resource and the directory used by the application. + + candidate_resource = CandidateResource() + directory = candidate_resource.resource_dir + + # Make a simple Web site. + + resource = MapResource({ + # Static resources: + #"scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}), + # Main page and in-page resources: + None : candidate_resource + }) + + return resource + +# vim: tabstop=4 expandtab shiftwidth=4