diff --git a/app/filter.py b/app/filter.py index 012ed91..cd6feb6 100644 --- a/app/filter.py +++ b/app/filter.py @@ -53,7 +53,6 @@ class Filter: self.fix_question_section() self.update_styling(soup) - for img in [_ for _ in soup.find_all('img') if 'src' in _.attrs]: self.update_element_src(img, 'image/png') diff --git a/app/models/config.py b/app/models/config.py index 6cfe18f..e69e037 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -325,3 +325,39 @@ class Config: def __contains__(self, name): return hasattr(self, name) + + def is_safe_key(self, key) -> bool: + """Establishes a group of config options that are safe to set + in the url. + + Args: + key (str) -- the key to check against + + Returns: + bool -- True/False depending on if the key is in the "safe" + array + """ + + return key in [ + 'lang_search', + 'lang_interface', + 'ctry', + 'dark' + ] + + def from_params(self, params) -> 'Config': + """Modify user config with search parameters. This is primarily + used for specifying configuration on a search-by-search basis on + public instances. + + Args: + params -- the url arguments (can be any deemed safe by is_safe()) + + Returns: + Config -- a modified config object + """ + for param_key in params.keys(): + if not self.is_safe_key(param_key): + continue + self[param_key] = params.get(param_key) + return self diff --git a/app/routes.py b/app/routes.py index d1734a3..d205283 100644 --- a/app/routes.py +++ b/app/routes.py @@ -161,6 +161,9 @@ def search(): # Reset element counter app.user_elements[session['uuid']] = 0 + # Update user config if specified in search args + g.user_config = g.user_config.from_params(g.request_params) + search_util = RoutingUtils(request, g.user_config, session, cookies_disabled=g.cookies_disabled) query = search_util.new_search_query() diff --git a/app/templates/header.html b/app/templates/header.html index 034b591..e99e38e 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -3,7 +3,7 @@