Commit 6e88a9c0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Similarly to submit(), add a class_attribute parameter to be able to

get a link from its class attribute, and add getImportExportLink() and
getFastInputLink() using class_attribute as the href is context-dependent


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@44967 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 66b6ed8d
......@@ -261,23 +261,64 @@ class Browser(ExtendedTestBrowser):
self._main_form = ContextMainForm(self, form)
return self._main_form
def getLink(self, url=None, *args, **kwargs):
def getLink(self, url=None, class_attribute=None, *args, **kwargs):
"""
Override original C{getLink} allowing to not consider the HTTP
query string unless it is explicitly given.
@param url: URL to look for
@type url: str
Also, allows to select a link by its class attribute, which
basically look for the first element whose C{attribute} is
C{class_attribute} then call C{getLink} with the element C{href}.
@param class_attribute: Get the link with this class
@type class_attribute: str
@param args: Positional arguments given to original C{getLink}
@type args: list
@param kwargs: Keyword arguments given to original C{getLink}
@type kwargs: dict
"""
if url and '?' not in url:
if class_attribute:
element_list = self.etree.xpath('//a[contains(@class, "%s")]' % \
class_attribute)
try:
url = element_list[0].get('href')
except (IndexError, AttributeError):
url = None
if not url:
raise LookupError("Could not find any link whose class is '%s'" % \
class_attribute)
elif url and '?' not in url:
url += '?'
return super(Browser, self).getLink(url=url, *args, **kwargs)
def getImportExportLink(self):
"""
Get Import/Export link. Use the class attribute rather than the
name as the latter is dependent on the context.
@return: The link whose class is C{report}
@rtype: Link
@todo: Should perhaps be a ContextBrowser class?
"""
return self.getLink(class_attribute='import_export')
def getFastInputLink(self):
"""
Get Fast Input link. Use the class attribute rather than the name
as the latter is dependent on the context.
@return: The link whose class is C{fast_input}
@rtype: Link
@todo: Should perhaps be a ContextBrowser class?
"""
return self.getLink(class_attribute='fast_input')
def getTransitionMessage(self):
"""
Parses the current page and returns the value of the portal_status
......@@ -450,7 +491,8 @@ class MainForm(Form):
name = None
if not name:
raise LookupError("Could not find any '%s' element" % class_attribute)
raise LookupError("Could not find any button whose class is '%s'" % \
class_attribute)
if label is None and name is None:
super(MainForm, self).submit(label=label, name=name, *args, **kwargs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment