1.1 --- a/XSLForms/Fields.py Sat Jun 21 01:28:08 2008 +0200
1.2 +++ b/XSLForms/Fields.py Mon Dec 20 18:55:20 2004 +0000
1.3 @@ -16,8 +16,8 @@
1.4 may have different names. For example:
1.5
1.6 /zoo#1/name
1.7 - /zoo#1/cage#1:name
1.8 - /zoo#1/cage#2:name
1.9 + /zoo#1/cage#1/name
1.10 + /zoo#1/cage#2/name
1.11 /zoo#1/funding#3/contributor#1/name
1.12
1.13 Some fields may contain the "=" string. This string is
1.14 @@ -44,15 +44,20 @@
1.15 _pair_separator = "#"
1.16 _selector_indicator = "="
1.17
1.18 - def __init__(self, encoding="utf-8"):
1.19 + def __init__(self, encoding="utf-8", values_are_lists=0):
1.20
1.21 """
1.22 Initialise the fields processor with the given 'encoding',
1.23 which is optional and which only applies to field data in
1.24 Python string form (and not Unicode objects).
1.25 +
1.26 + If the optional 'values_are_lists' parameter is set to true
1.27 + then each actual field value will be obtained by taking the
1.28 + first element from each supplied field value.
1.29 """
1.30
1.31 self.encoding = encoding
1.32 + self.values_are_lists = values_are_lists
1.33
1.34 def complete_documents(self, documents, fields):
1.35
1.36 @@ -71,6 +76,11 @@
1.37 if model_name is None:
1.38 continue
1.39
1.40 + # Convert from lists if necessary.
1.41 +
1.42 + if self.values_are_lists:
1.43 + value = value[0]
1.44 +
1.45 # Convert the value to Unicode if necessary.
1.46
1.47 if type(value) == type(""):
1.48 @@ -80,7 +90,7 @@
1.49 # model.
1.50
1.51 if not documents.has_key(model_name):
1.52 - documents[model_name] = self._new_instance(model_name)
1.53 + documents[model_name] = self.new_instance(model_name)
1.54 node = documents[model_name]
1.55
1.56 # Traverse the components within the instance.
1.57 @@ -257,7 +267,7 @@
1.58 self.complete_selectors(selectors, fields, documents)
1.59 return selectors
1.60
1.61 - def _new_instance(self, name):
1.62 + def new_instance(self, name):
1.63
1.64 "Return an instance root of the given 'name' in a new document."
1.65