From d6caa01d3878923bc7013b1a958ac02a15ff3737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 20 Aug 2019 17:34:56 +0200 Subject: [PATCH 1/7] draft for guessing preferred client language via header --- __init__.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 6d9197d..52559f8 100644 --- a/__init__.py +++ b/__init__.py @@ -360,18 +360,40 @@ def selectLanguage( self, path ): elif conf["viur.languageMethod"] == "url": tmppath = urlparse.urlparse( path ).path tmppath = [ urlparse.unquote( x ) for x in tmppath.lower().strip("/").split("/") ] + langSet = False if len( tmppath )>0 and tmppath[0] in conf["viur.availableLanguages"]+list( conf["viur.languageAliasMap"].keys() ): self.language = tmppath[0] - return( path[ len( tmppath[0])+1: ] ) #Return the path stripped by its language segment + langSet = True + return path[ len( tmppath[0])+1: ] # Return the path stripped by its language segment else: # This URL doesnt contain an language prefix, try to read it from session if session.current.getLanguage(): self.language = session.current.getLanguage() - elif "X-Appengine-Country" in self.request.headers.keys(): + langSet = True + if not langSet and "Accept-Language" in self.request.headers: + acceptLangHeader = self.request.headers["Accept-Language"] + if acceptLangHeader: + acceptLangHeader = acceptLangHeader.split(",") + for possibleLang in acceptLangHeader[:7]: + try: + lng, regionEtc = possibleLang.split("-", 1) + except ValueError: + lng = possibleLang + + if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: + self.language = lng + langSet = True + break + elif ";" in lng: + lng, weight = lng.split(";") + if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: + self.language = lng + langSet = True + break + if not langSet and "X-Appengine-Country" in self.request.headers.keys(): lng = self.request.headers["X-Appengine-Country"].lower() if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng - return( path ) - + return path def processRequest( self, path, *args, **kwargs ): #Bring up the enviroment for this request, handle errors self.internalRequest = False From b8db83e381afffe083b1f859d455a517d67dfc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 3 Sep 2019 02:03:58 +0200 Subject: [PATCH 2/7] improving my patch driven by comments from @tsteinruecken --- __init__.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/__init__.py b/__init__.py index 52559f8..624ae90 100644 --- a/__init__.py +++ b/__init__.py @@ -360,36 +360,30 @@ def selectLanguage( self, path ): elif conf["viur.languageMethod"] == "url": tmppath = urlparse.urlparse( path ).path tmppath = [ urlparse.unquote( x ) for x in tmppath.lower().strip("/").split("/") ] - langSet = False if len( tmppath )>0 and tmppath[0] in conf["viur.availableLanguages"]+list( conf["viur.languageAliasMap"].keys() ): self.language = tmppath[0] - langSet = True return path[ len( tmppath[0])+1: ] # Return the path stripped by its language segment else: # This URL doesnt contain an language prefix, try to read it from session - if session.current.getLanguage(): - self.language = session.current.getLanguage() - langSet = True - if not langSet and "Accept-Language" in self.request.headers: + sessionLang = session.current.getLanguage() + if sessionLang: + self.language = sessionLang + return path + if "Accept-Language" in self.request.headers: acceptLangHeader = self.request.headers["Accept-Language"] if acceptLangHeader: acceptLangHeader = acceptLangHeader.split(",") + # we only accept up to seven language entries here. for possibleLang in acceptLangHeader[:7]: - try: - lng, regionEtc = possibleLang.split("-", 1) - except ValueError: - lng = possibleLang - + lng = possibleLang.split("-")[0] if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng - langSet = True - break + return path elif ";" in lng: lng, weight = lng.split(";") if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng - langSet = True - break - if not langSet and "X-Appengine-Country" in self.request.headers.keys(): + return path + elif "X-Appengine-Country" in self.request.headers.keys(): lng = self.request.headers["X-Appengine-Country"].lower() if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng From 70b0b63420de11dd1b841729d56d4822aa29f9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 3 Sep 2019 02:12:15 +0200 Subject: [PATCH 3/7] changed elif to if for being more expressive and directly return path after found a lang to use --- __init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 624ae90..5bc63e6 100644 --- a/__init__.py +++ b/__init__.py @@ -383,10 +383,11 @@ def selectLanguage( self, path ): if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng return path - elif "X-Appengine-Country" in self.request.headers.keys(): + if "X-Appengine-Country" in self.request.headers.keys(): lng = self.request.headers["X-Appengine-Country"].lower() if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng + return path return path def processRequest( self, path, *args, **kwargs ): #Bring up the enviroment for this request, handle errors From 5a8ea8d860795d1557bc87933a361a1f9c4f7972 Mon Sep 17 00:00:00 2001 From: Jan Max Meyer Date: Mon, 7 Oct 2019 11:41:06 +0200 Subject: [PATCH 4/7] Correctly call bound PeriodicTask functions --- tasks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index 48646c8..e75cbb1 100644 --- a/tasks.py +++ b/tasks.py @@ -176,12 +176,14 @@ def index(self, *args, **kwargs): continue except db.EntityNotFoundError: pass + res = self.findBoundTask( task ) + if res: #Its bound, call it this way :) - t, s = res - t( s ) + res[0]() else: task() #It seems it wasnt bound - call it as a static method + logging.debug("Successfully called task %s" % task.periodicTaskName ) if intervall: # Update its last-call timestamp From 7bc82c15c96ab08ec7c03080b05de8b44893dac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Wed, 4 Dec 2019 12:51:47 +0100 Subject: [PATCH 5/7] changed to simpler split as requested in PR comment --- __init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 5bc63e6..8025fbe 100644 --- a/__init__.py +++ b/__init__.py @@ -379,7 +379,7 @@ def selectLanguage( self, path ): self.language = lng return path elif ";" in lng: - lng, weight = lng.split(";") + lng = lng.split(";")[0] if lng in conf["viur.availableLanguages"] or lng in conf["viur.languageAliasMap"]: self.language = lng return path From e44afc7f425cd3e656a24f511fa900274eba1652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Sun, 4 Jul 2021 23:32:34 +0200 Subject: [PATCH 6/7] needed for btvn --- __init__.py | 16 ++++++++++++++++ bones/textBone.py | 1 - modules/order.py | 2 +- template/editform_bone_select.html | 9 ++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/__init__.py b/__init__.py index 8025fbe..4ba383d 100644 --- a/__init__.py +++ b/__init__.py @@ -400,6 +400,22 @@ def processRequest( self, path, *args, **kwargs ): #Bring up the enviroment for self.args = [] self.kwargs = {} #Add CSP headers early (if any) + + if conf["viur.earlyInterceptionHook"]: + try: + newPath = conf["viur.earlyInterceptionHook"](path) + if newPath != path: + self.response.clear() + self.response.set_status(410, "Gone") + self.response.out.write(newPath) + return + except errors.Redirect as err: + if conf["viur.debug.traceExceptions"]: + raise + logging.debug("early redirect: %r", err.url.encode("UTF-8")) + self.redirect(err.url.encode("UTF-8")) + return + if conf["viur.security.contentSecurityPolicy"] and conf["viur.security.contentSecurityPolicy"]["_headerCache"]: for k,v in conf["viur.security.contentSecurityPolicy"]["_headerCache"].items(): self.response.headers[k] = v diff --git a/bones/textBone.py b/bones/textBone.py index 6bb006a..f84069f 100644 --- a/bones/textBone.py +++ b/bones/textBone.py @@ -48,7 +48,6 @@ def handle_data(self, data): .replace(">", ">") \ .replace("\"", """) \ .replace("'", "'") \ - .replace("\n", "") \ .replace("\0", "") if data.strip(): self.flushCache() diff --git a/modules/order.py b/modules/order.py index d68e4a3..fa5116c 100644 --- a/modules/order.py +++ b/modules/order.py @@ -844,7 +844,7 @@ def archiveOrder(self, order): self.sendOrderArchivedEMail( order.key.urlsafe() ) logging.error("Order archived: "+str( order.key.urlsafe() ) ) - @PeriodicTask(60*24) + # @PeriodicTask(60*24) def startArchiveOrdersTask( self, *args, **kwargs ): self.doArchiveActiveOrdersTask( (datetime.now()-self.archiveDelay).strftime("%d.%m.%Y %H:%M:%S"), None ) self.doArchiveCancelledOrdersTask( (datetime.now()-self.archiveDelay).strftime("%d.%m.%Y %H:%M:%S"), None ) diff --git a/template/editform_bone_select.html b/template/editform_bone_select.html index 30b2b46..01d304f 100644 --- a/template/editform_bone_select.html +++ b/template/editform_bone_select.html @@ -28,14 +28,9 @@ > {%- for key, descr in boneParams["values"].items() %} {% if loop.first %} - + {% endif %} - - + {% endfor -%} {% endif %} From 45a5ef2bf682d671c94605e54fbfe62b9cdad939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Fri, 20 May 2022 11:35:15 +0200 Subject: [PATCH 7/7] fixed a small bug in cart.py --- modules/cart.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/cart.py b/modules/cart.py index efbbf61..9538cd5 100644 --- a/modules/cart.py +++ b/modules/cart.py @@ -91,7 +91,8 @@ def view(self, *args, **kwargs): items = SkelList( self.productSkel ) for skel in items: - skel["amt"] = numericBone( + skel.clone() + skel.amt = numericBone( descr="Quantity", defaultValue=session.current["cart_products"][str(skel["key"].value)]["amount"])