1.1 --- a/XSLForms/Resources/WebResources.py Fri Oct 05 23:44:25 2007 +0000
1.2 +++ b/XSLForms/Resources/WebResources.py Sat Nov 17 20:09:20 2007 +0000
1.3 @@ -359,4 +359,53 @@
1.4 for input_identifier in cls.init_resources.keys():
1.5 prepare_initialiser(cls, input_identifier, 1)
1.6
1.7 +# Convenience methods for specifying resources.
1.8 +
1.9 +def split(filename):
1.10 +
1.11 + """
1.12 + Return a tuple containing the directory and filename without extension for
1.13 + 'filename'.
1.14 + """
1.15 +
1.16 + d, leafname = os.path.split(filename)
1.17 + name, ext = os.path.splitext(leafname)
1.18 + return d, name
1.19 +
1.20 +def output(template_filename):
1.21 +
1.22 + """
1.23 + Return a tuple containing the 'template_filename' and a suitable output
1.24 + stylesheet filename.
1.25 + """
1.26 +
1.27 + d, name = split(template_filename)
1.28 + output_name = name.replace("_template", "_output") + os.path.extsep + "xsl"
1.29 + return (template_filename, os.path.join(d, output_name))
1.30 +
1.31 +def input(template_filename):
1.32 +
1.33 + """
1.34 + Return a tuple containing the 'template_filename' and a suitable output
1.35 + stylesheet filename.
1.36 + """
1.37 +
1.38 + d, name = split(template_filename)
1.39 + input_name = name.replace("_template", "_input") + os.path.extsep + "xsl"
1.40 + return (template_filename, os.path.join(d, input_name))
1.41 +
1.42 +def resources(filename, d="Resources"):
1.43 +
1.44 + """
1.45 + Return the resource directory for the given 'filename', using the optional
1.46 + directory name 'd' to indicate the directory relative to the directory of
1.47 + 'filename' (or the default directory name, indicating that the directory
1.48 + called "Resources" - a sibling of 'filename' - is the resource directory).
1.49 +
1.50 + It is envisaged that callers provide the value of the __file__ special
1.51 + variable to get the resource directory relative to a particular module.
1.52 + """
1.53 +
1.54 + return os.path.join(os.path.split(filename)[0], d)
1.55 +
1.56 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/examples/Common/Candidate/__init__.py Fri Oct 05 23:44:25 2007 +0000
2.2 +++ b/examples/Common/Candidate/__init__.py Sat Nov 17 20:09:20 2007 +0000
2.3 @@ -4,7 +4,7 @@
2.4
2.5 import WebStack.Generic
2.6 from WebStack.Repositories.Directory import DirectoryRepository
2.7 -import XSLForms.Resources.WebResources
2.8 +from XSLForms.Resources.WebResources import XSLFormsResource, input, output, resources
2.9 import XSLForms.Utils
2.10 import os
2.11 import libxml2dom
2.12 @@ -21,16 +21,16 @@
2.13
2.14 # Resource classes.
2.15
2.16 -class AdminResource(XSLForms.Resources.WebResources.XSLFormsResource):
2.17 +class AdminResource(XSLFormsResource):
2.18
2.19 "A resource providing administration facilities for job candidate profiles."
2.20
2.21 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.22 + resource_dir = resources(__file__)
2.23 template_resources = {
2.24 - "admin" : ("admin_template.xhtml", "admin_output.xsl")
2.25 + "admin" : output("admin_template.xhtml")
2.26 }
2.27 init_resources = {
2.28 - "admin" : ("admin_template.xhtml", "admin_input.xsl")
2.29 + "admin" : input("admin_template.xhtml")
2.30 }
2.31
2.32 def __init__(self, repository):
2.33 @@ -116,12 +116,12 @@
2.34
2.35 "A resource providing editing facilities for a job candidate profile."
2.36
2.37 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.38 + resource_dir = resources(__file__)
2.39 template_resources = {
2.40 - "candidate_display" : ("candidate_display_template.xhtml", "candidate_display_output.xsl")
2.41 + "candidate_display" : output("candidate_display_template.xhtml")
2.42 }
2.43 init_resources = {
2.44 - "candidate" : ("candidate_template.xhtml", "candidate_input.xsl")
2.45 + "candidate" : input("candidate_template.xhtml")
2.46 }
2.47 document_resources = {
2.48 "status" : "candidate_status.xml"
2.49 @@ -176,12 +176,12 @@
2.50
2.51 "A resource providing editing facilities for a job candidate profile."
2.52
2.53 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.54 + resource_dir = resources(__file__)
2.55 template_resources = {
2.56 - "candidate" : ("candidate_template.xhtml", "candidate_output.xsl")
2.57 + "candidate" : output("candidate_template.xhtml")
2.58 }
2.59 init_resources = {
2.60 - "candidate" : ("candidate_template.xhtml", "candidate_input.xsl")
2.61 + "candidate" : input("candidate_template.xhtml")
2.62 }
2.63 document_resources = {
2.64 "status" : "candidate_status.xml"
2.65 @@ -274,7 +274,7 @@
2.66 if use_cwd:
2.67 resource_dir = os.getcwd()
2.68 else:
2.69 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.70 + resource_dir = resources(__file__)
2.71 repository = DirectoryRepository(os.path.join(resource_dir, "candidates"), fsencoding)
2.72
2.73 # Get the main resource and the directory used by the application.