comparison libervia/server/pages.py @ 1392:e11a71a08a48

pages: fix `getPostedData` when a single value is requested and a list is used
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 21:03:08 +0100
parents 3e482795630c
children d9a328ddef9c
comparison
equal deleted inserted replaced
1391:fc20818a5266 1392:e11a71a08a48
1240 web_util.redirectTo(url.encode("utf-8"), request) 1240 web_util.redirectTo(url.encode("utf-8"), request)
1241 request.finish() 1241 request.finish()
1242 raise failure.Failure(exceptions.CancelError("HTTP redirection is used")) 1242 raise failure.Failure(exceptions.CancelError("HTTP redirection is used"))
1243 1243
1244 def redirectOrContinue(self, request, redirect_arg="redirect_url"): 1244 def redirectOrContinue(self, request, redirect_arg="redirect_url"):
1245 """helper method to redirect a page to an url given as arg 1245 """Helper method to redirect a page to an url given as arg
1246 1246
1247 if the arg is not present, the page will continue normal workflow 1247 if the arg is not present, the page will continue normal workflow
1248 @param request(server.Request): current HTTP request 1248 @param request(server.Request): current HTTP request
1249 @param redirect_arg(unicode): argument to use to get redirection URL 1249 @param redirect_arg(unicode): argument to use to get redirection URL
1250 @interrupt: redirect the page to requested URL 1250 @interrupt: redirect the page to requested URL
1538 """ 1538 """
1539 #  FIXME: request.args is already unquoting the value, it seems we are doing 1539 #  FIXME: request.args is already unquoting the value, it seems we are doing
1540 # double unquote 1540 # double unquote
1541 if isinstance(keys, str): 1541 if isinstance(keys, str):
1542 keys = [keys] 1542 keys = [keys]
1543 get_first = True
1544 else:
1545 get_first = False
1546 1543
1547 keys = [k.encode('utf-8') for k in keys] 1544 keys = [k.encode('utf-8') for k in keys]
1548 1545
1549 ret = [] 1546 ret = []
1550 for key in keys: 1547 for key in keys:
1559 if raise_on_missing: 1556 if raise_on_missing:
1560 raise KeyError(key) 1557 raise KeyError(key)
1561 else: 1558 else:
1562 ret.append(None) 1559 ret.append(None)
1563 1560
1564 return ret[0] if get_first else ret 1561 if len(keys) == 1:
1562 return ret[0]
1563 else:
1564 return ret
1565 1565
1566 def getAllPostedData(self, request, except_=(), multiple=True): 1566 def getAllPostedData(self, request, except_=(), multiple=True):
1567 """get all posted data 1567 """get all posted data
1568 1568
1569 @param request(server.Request): request linked to the session 1569 @param request(server.Request): request linked to the session
1585 else: 1585 else:
1586 ret[key] = [urllib.parse.unquote(v) for v in values] 1586 ret[key] = [urllib.parse.unquote(v) for v in values]
1587 return ret 1587 return ret
1588 1588
1589 def getProfile(self, request): 1589 def getProfile(self, request):
1590 """helper method to easily get current profile 1590 """Helper method to easily get current profile
1591 1591
1592 @return (unicode, None): current profile 1592 @return (unicode, None): current profile
1593 None if no profile session is started 1593 None if no profile session is started
1594 """ 1594 """
1595 sat_session = self.host.getSessionData(request, session_iface.ISATSession) 1595 sat_session = self.host.getSessionData(request, session_iface.ISATSession)
1596 return sat_session.profile 1596 return sat_session.profile
1597 1597
1598 def getJid(self, request): 1598 def getJid(self, request):
1599 """helper method to easily get current jid 1599 """Helper method to easily get current jid
1600 1600
1601 @return: current jid 1601 @return: current jid
1602 """ 1602 """
1603 sat_session = self.host.getSessionData(request, session_iface.ISATSession) 1603 sat_session = self.host.getSessionData(request, session_iface.ISATSession)
1604 return sat_session.jid 1604 return sat_session.jid
1605 1605
1606 1606
1607 def getRData(self, request): 1607 def getRData(self, request):
1608 """helper method to get request data dict 1608 """Helper method to get request data dict
1609 1609
1610 this dictionnary if for the request only, it is not saved in session 1610 this dictionnary if for the request only, it is not saved in session
1611 It is mainly used to pass data between pages/methods called during request 1611 It is mainly used to pass data between pages/methods called during request
1612 workflow 1612 workflow
1613 @return (dict): request data 1613 @return (dict): request data