1.1 --- a/XSLForms/Fields.py Fri Jun 20 23:21:24 2008 +0000
1.2 +++ b/XSLForms/Fields.py Fri Jun 20 23:24:43 2008 +0000
1.3 @@ -5,7 +5,7 @@
1.4 Interpretation of field collections from sources such as HTTP request parameter
1.5 dictionaries.
1.6
1.7 -Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU Lesser General Public License as published by the Free
1.12 @@ -54,6 +54,10 @@
1.13 import Constants
1.14 import libxml2dom
1.15 from xml.dom import EMPTY_NAMESPACE
1.16 +try:
1.17 + set
1.18 +except NameError:
1.19 + from sets import Set as set
1.20
1.21 class FieldsError(Exception):
1.22 pass
1.23 @@ -388,11 +392,11 @@
1.24 FieldProcessor.__init__(self, *args, **kw)
1.25 self.parameters = {}
1.26 self.documents = {}
1.27 + self.new_documents = set()
1.28
1.29 # Activity-related attributes.
1.30
1.31 self.current_activity = None
1.32 - self.current_document = None
1.33
1.34 def set_parameters(self, parameters):
1.35
1.36 @@ -422,7 +426,9 @@
1.37
1.38 return self.documents
1.39
1.40 - def get_document(self, name):
1.41 + # NOTE: Was get_document.
1.42 +
1.43 + def _get_document(self, name):
1.44
1.45 """
1.46 Get the form data document with the given 'name' from the container,
1.47 @@ -492,16 +498,25 @@
1.48 def get_activity(self):
1.49 return self.current_activity
1.50
1.51 - # NOTE: Signature is flexible to support the older method above.
1.52 + # NOTE: Signatures are flexible to support the older methods above.
1.53
1.54 def set_document(self, name_or_doc, doc=None):
1.55 if doc is not None:
1.56 self._set_document(name_or_doc, doc)
1.57 else:
1.58 - self.current_document = name_or_doc
1.59 + self._set_document(self.current_activity, name_or_doc)
1.60
1.61 - def get_document(self):
1.62 - return self.current_document
1.63 + def get_document(self, name=None):
1.64 + if name is None:
1.65 + return self._get_document(self.current_activity)
1.66 + else:
1.67 + return self._get_document(name)
1.68 +
1.69 + def is_new_document(self, name=None):
1.70 + if name is None:
1.71 + return self.current_activity in self.new_documents
1.72 + else:
1.73 + return name in self.new_documents
1.74
1.75 if __name__ == "__main__":
1.76