# HG changeset patch # User paulb # Date 1103568920 0 # Node ID e96db0ca695250d1c2abf1311bbfe57855cb468b # Parent d1460ee96abfcbaf52d6312e1ab2d26fac547f54 [project @ 2004-12-20 18:55:20 by paulb] Fixed module docstring. Added a parameter so that values which are lists of actual values may be handled. Exposed instance creation as a "public" method. diff -r d1460ee96abf -r e96db0ca6952 XSLForms/Fields.py --- a/XSLForms/Fields.py Sat Jun 21 01:28:08 2008 +0200 +++ b/XSLForms/Fields.py Mon Dec 20 18:55:20 2004 +0000 @@ -16,8 +16,8 @@ may have different names. For example: /zoo#1/name - /zoo#1/cage#1:name - /zoo#1/cage#2:name + /zoo#1/cage#1/name + /zoo#1/cage#2/name /zoo#1/funding#3/contributor#1/name Some fields may contain the "=" string. This string is @@ -44,15 +44,20 @@ _pair_separator = "#" _selector_indicator = "=" - def __init__(self, encoding="utf-8"): + def __init__(self, encoding="utf-8", values_are_lists=0): """ Initialise the fields processor with the given 'encoding', which is optional and which only applies to field data in Python string form (and not Unicode objects). + + If the optional 'values_are_lists' parameter is set to true + then each actual field value will be obtained by taking the + first element from each supplied field value. """ self.encoding = encoding + self.values_are_lists = values_are_lists def complete_documents(self, documents, fields): @@ -71,6 +76,11 @@ if model_name is None: continue + # Convert from lists if necessary. + + if self.values_are_lists: + value = value[0] + # Convert the value to Unicode if necessary. if type(value) == type(""): @@ -80,7 +90,7 @@ # model. if not documents.has_key(model_name): - documents[model_name] = self._new_instance(model_name) + documents[model_name] = self.new_instance(model_name) node = documents[model_name] # Traverse the components within the instance. @@ -257,7 +267,7 @@ self.complete_selectors(selectors, fields, documents) return selectors - def _new_instance(self, name): + def new_instance(self, name): "Return an instance root of the given 'name' in a new document."