1.1 --- a/examples/Common/Candidate/__init__.py Mon Jan 30 22:09:07 2006 +0000
1.2 +++ b/examples/Common/Candidate/__init__.py Mon Jan 30 22:09:27 2006 +0000
1.3 @@ -29,6 +29,9 @@
1.4 "admin" : ("admin_template.xhtml", "admin_input.xsl")
1.5 }
1.6
1.7 + def __init__(self, repository):
1.8 + self.repository = repository
1.9 +
1.10 def respond_to_form(self, trans, form):
1.11
1.12 """
1.13 @@ -80,8 +83,7 @@
1.14 # Synchronise the repository with the CVs found.
1.15
1.16 cvs = admin.xpath("/admin/cvs")[0]
1.17 - repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.18 - for key in repository.keys():
1.19 + for key in self.repository.keys():
1.20 if key.startswith("candidate-"):
1.21 name = key[len("candidate-"):]
1.22 # NOTE: Apostrophes not quoted.
1.23 @@ -91,7 +93,7 @@
1.24 cv.setAttribute("name", name)
1.25 cvs.appendChild(cv)
1.26 else:
1.27 - del repository[key]
1.28 + del self.repository[key]
1.29
1.30 # Start the response.
1.31
1.32 @@ -122,6 +124,9 @@
1.33 "status" : "candidate_status.xml"
1.34 }
1.35
1.36 + def __init__(self, repository):
1.37 + self.repository = repository
1.38 +
1.39 def respond_to_form(self, trans, form):
1.40
1.41 """
1.42 @@ -139,11 +144,10 @@
1.43 if documents.has_key("candidate"):
1.44 candidate = documents["candidate"]
1.45 else:
1.46 - repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.47 - if repository is None or not repository.has_key("candidate-%s" % name):
1.48 + if self.repository is None or not self.repository.has_key("candidate-%s" % name):
1.49 candidate = form.new_instance("candidate")
1.50 else:
1.51 - candidate = libxml2dom.parseString(repository["candidate-%s" % name])
1.52 + candidate = libxml2dom.parseString(self.repository["candidate-%s" % name])
1.53
1.54 # Transform, adding enumerations/ranges.
1.55
1.56 @@ -181,6 +185,9 @@
1.57 "status" : "candidate_status.xml"
1.58 }
1.59
1.60 + def __init__(self, repository):
1.61 + self.repository = repository
1.62 +
1.63 def respond_to_form(self, trans, form):
1.64
1.65 """
1.66 @@ -205,11 +212,10 @@
1.67 if documents.has_key("candidate"):
1.68 candidate = documents["candidate"]
1.69 else:
1.70 - repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.71 - if repository is None or not repository.has_key("candidate-%s" % name):
1.72 + if self.repository is None or not self.repository.has_key("candidate-%s" % name):
1.73 candidate = form.new_instance("candidate")
1.74 else:
1.75 - candidate = libxml2dom.parseString(repository["candidate-%s" % name])
1.76 + candidate = libxml2dom.parseString(self.repository["candidate-%s" % name])
1.77
1.78 # Add and remove elements according to the selectors found.
1.79
1.80 @@ -231,8 +237,7 @@
1.81
1.82 # Save the candidate information.
1.83
1.84 - repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.85 - repository["candidate-%s" % name] = candidate.toString()
1.86 + self.repository["candidate-%s" % name] = candidate.toString()
1.87 trans.redirect(trans.encode_path(show_path, self.path_encoding) +
1.88 "?name=%s" % trans.encode_path(name, self.path_encoding))
1.89
1.90 @@ -242,8 +247,7 @@
1.91
1.92 # Save the candidate information.
1.93
1.94 - repository = DirectoryRepository(os.path.join(self.resource_dir, "candidates"))
1.95 - repository["candidate-%s" % name] = candidate.toString()
1.96 + self.repository["candidate-%s" % name] = candidate.toString()
1.97 trans.redirect(trans.encode_path(admin_path, self.path_encoding))
1.98
1.99 # Start the response.
1.100 @@ -261,16 +265,18 @@
1.101
1.102 # Site map initialisation.
1.103
1.104 -def get_site():
1.105 +def get_site(fsencoding=None):
1.106
1.107 "Return a simple Web site resource."
1.108
1.109 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.110 + repository = DirectoryRepository(os.path.join(resource_dir, "candidates"), fsencoding)
1.111 +
1.112 # Get the main resource and the directory used by the application.
1.113
1.114 - candidate_resource = CandidateResource()
1.115 - display_resource = DisplayResource()
1.116 - admin_resource = AdminResource()
1.117 - directory = candidate_resource.resource_dir
1.118 + candidate_resource = CandidateResource(repository)
1.119 + display_resource = DisplayResource(repository)
1.120 + admin_resource = AdminResource(repository)
1.121
1.122 # Make a simple Web site.
1.123