comparison libervia/server/pages.py @ 1463:2c8449885272

pages: query parameters can now be specified using keyword arguments in `getURL:` rel: 399
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 16:57:54 +0200
parents 284522d8af44
children a8435aebfbcc
comparison
equal deleted inserted replaced
1462:87e48b6a1bbd 1463:2c8449885272
663 redirect_url=urllib.parse.quote_plus(request.uri) 663 redirect_url=urllib.parse.quote_plus(request.uri)
664 if url is None 664 if url is None
665 else url.encode("utf-8"), 665 else url.encode("utf-8"),
666 ) 666 )
667 667
668 def getURL(self, *args: str) -> str: 668 def getURL(self, *args: str, **kwargs: str) -> str:
669 """retrieve URL of the page set arguments 669 """retrieve URL of the page set arguments
670 670
671 @param *args: arguments to add to the URL as path elements empty or None 671 @param *args: arguments to add to the URL as path elements empty or None
672 arguments will be ignored 672 arguments will be ignored
673 @param **kwargs: query parameters
673 """ 674 """
674 url_args = [quote(a) for a in args if a] 675 url_args = [quote(a) for a in args if a]
675 676
676 if self.name is not None and self.name in self.pages_redirects: 677 if self.name is not None and self.name in self.pages_redirects:
677 #  we check for redirection 678 #  we check for redirection
681 current_hash = args_hash[:limit] 682 current_hash = args_hash[:limit]
682 if current_hash in redirect_data: 683 if current_hash in redirect_data:
683 url_base = redirect_data[current_hash] 684 url_base = redirect_data[current_hash]
684 remaining = args[limit:] 685 remaining = args[limit:]
685 remaining_url = "/".join(remaining) 686 remaining_url = "/".join(remaining)
686 return os.path.join("/", url_base, remaining_url) 687 url = os.path.join("/", url_base, remaining_url)
688 break
689 else:
690 url = os.path.join(self.url, *url_args)
691
692 if kwargs:
693 encoded = urllib.parse.urlencode(
694 {k: v for k, v in kwargs.items()}
695 )
696 url += f"?{encoded}"
687 697
688 return self.host.checkRedirection( 698 return self.host.checkRedirection(
689 self.vhost_root, 699 self.vhost_root,
690 os.path.join(self.url, *url_args) 700 url
691 ) 701 )
692 702
693 def getCurrentURL(self, request): 703 def getCurrentURL(self, request):
694 """retrieve URL used to access this page 704 """retrieve URL used to access this page
695 705