# HG changeset patch # User paulb # Date 1214004283 0 # Node ID ce68e5214b0891096b763b0c27b61a34020b8eb9 # Parent 8d9c1e94e78b229aa7563d5f98cfa7862795f266 [project @ 2008-06-20 23:24:43 by paulb] Made get_document support getting the current activity's document if no name is given. Fixed current document retrieval so that the document is retrieved dynamically using the name. Added support for finding out whether a new document has been created. diff -r 8d9c1e94e78b -r ce68e5214b08 XSLForms/Fields.py --- a/XSLForms/Fields.py Fri Jun 20 23:21:24 2008 +0000 +++ b/XSLForms/Fields.py Fri Jun 20 23:24:43 2008 +0000 @@ -5,7 +5,7 @@ Interpretation of field collections from sources such as HTTP request parameter dictionaries. -Copyright (C) 2005, 2006, 2007 Paul Boddie +Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -54,6 +54,10 @@ import Constants import libxml2dom from xml.dom import EMPTY_NAMESPACE +try: + set +except NameError: + from sets import Set as set class FieldsError(Exception): pass @@ -388,11 +392,11 @@ FieldProcessor.__init__(self, *args, **kw) self.parameters = {} self.documents = {} + self.new_documents = set() # Activity-related attributes. self.current_activity = None - self.current_document = None def set_parameters(self, parameters): @@ -422,7 +426,9 @@ return self.documents - def get_document(self, name): + # NOTE: Was get_document. + + def _get_document(self, name): """ Get the form data document with the given 'name' from the container, @@ -492,16 +498,25 @@ def get_activity(self): return self.current_activity - # NOTE: Signature is flexible to support the older method above. + # NOTE: Signatures are flexible to support the older methods above. def set_document(self, name_or_doc, doc=None): if doc is not None: self._set_document(name_or_doc, doc) else: - self.current_document = name_or_doc + self._set_document(self.current_activity, name_or_doc) - def get_document(self): - return self.current_document + def get_document(self, name=None): + if name is None: + return self._get_document(self.current_activity) + else: + return self._get_document(name) + + def is_new_document(self, name=None): + if name is None: + return self.current_activity in self.new_documents + else: + return name in self.new_documents if __name__ == "__main__":