[Erp5-report] r10121 - /erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Sep 18 18:15:52 CEST 2006


Author: vincent
Date: Mon Sep 18 18:15:50 2006
New Revision: 10121

URL: http://svn.erp5.org?rev=10121&view=rev
Log:
Add new function getFormulatorFieldValue to get the value of a formulator field. It's quite rough for now and returns directly the html of the field.
Re-enable code gathering portal status message using minidom.

Modified:
    erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

Modified: erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py?rev=10121&r1=10120&r2=10121&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py (original)
+++ erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py Mon Sep 18 18:15:50 2006
@@ -68,17 +68,28 @@
     """
       Parses the last received page and returns the value of the portal_status_message, or None if not present.
     """
-# XXX: disabled temporarily to survive html style bogus html.
-#    from xml.dom.minidom import parseString
-#    document = parseString(self.getHtml().get_data())
-#    for element in document.getElementsByTagName(u'td'):
-#      if element.attributes.get(u'class') is not None and element.attributes.get(u'class').value == u'error': # XXX: Hardcoded class name
-#        for child in element.childNodes:
-#          if child.nodeType == child.TEXT_NODE:
-#            return child.wholeText
-    for line in self.getHtml().get_data().split('\n'):
-      if 'class="error"' in line:
-        return line
+    from xml.dom.minidom import parseString
+    document = parseString(self.getHtml().get_data())
+    for element in document.getElementsByTagName(u'div'):
+      if element.attributes.get(u'id') is not None and element.attributes.get(u'id').value == u'transition_message': # XXX: Hardcoded class name
+        for child in element.childNodes:
+          if child.nodeType == child.TEXT_NODE:
+            return child.wholeText
+    return None
+
+  def getFormulatorFieldValue(self, field_label):
+    """
+      Returns the raw html content of the formulator field present in last loaded page.
+      Returns None id the field is not found.
+    """
+    from xml.dom.minidom import parseString
+    document = parseString(self.getHtml().get_data())
+    for element in document.getElementsByTagName(u'div'):
+      if element.attributes.get(u'class') is not None and 'field' in element.attributes.get(u'class').value:
+        if len(element.getElementsByTagName('label')) == 1 and \
+           field_label in element.getElementsByTagName('label')[0].firstChild.wholeText and \
+           len(element.getElementsByTagName('div')) == 1: # field_label in ... might get false positives.
+          return element.getElementsByTagName('div')[0].firstChild.wholeText
     return None
 
   def selectMainForm(self):




More information about the Erp5-report mailing list