]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/base.py
sponsors: Have an attempt at the index page
[ipfire.org.git] / src / web / base.py
index fa4193792aafdcfa96eb376be06b3e5031bbcca9..18af52c404cb6122cc9f39515e8b99d48610db3b 100644 (file)
@@ -194,6 +194,27 @@ class BaseHandler(tornado.web.RequestHandler):
 
                return account
 
+       # Currency
+
+       def get_preferred_currency(self):
+               currency = self.get_argument("currency", None)
+
+               if currency in ("EUR", "USD"):
+                       return currency
+
+               elif not currency:
+                       if self.current_user:
+                               country = self.current_user.country_code
+                       else:
+                               country = self.current_country_code
+
+                       if country in ("US", "CA", "MX"):
+                               return "USD"
+
+                       return "EUR"
+
+               raise tornado.web.HTTPError(400, "Unsupported currency chosen: %s" % currency)
+
        @property
        def backend(self):
                return self.application.backend