Expand conversion of config<->url params
Config settings can now be translated to and from URL params using a predetermined set of "safe" keys (i.e. config settings that easily translate to URL params).
This commit is contained in:
parent
3c06519130
commit
b7798c9382
|
@ -17,7 +17,7 @@ class Config:
|
||||||
self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '')
|
self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '')
|
||||||
self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '')
|
self.block_title = os.getenv('WHOOGLE_CONFIG_BLOCK_TITLE', '')
|
||||||
self.block_url = os.getenv('WHOOGLE_CONFIG_BLOCK_URL', '')
|
self.block_url = os.getenv('WHOOGLE_CONFIG_BLOCK_URL', '')
|
||||||
self.ctry = os.getenv('WHOOGLE_CONFIG_COUNTRY', 'US')
|
self.country = os.getenv('WHOOGLE_CONFIG_COUNTRY', 'US')
|
||||||
self.theme = os.getenv('WHOOGLE_CONFIG_THEME', 'system')
|
self.theme = os.getenv('WHOOGLE_CONFIG_THEME', 'system')
|
||||||
self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE')
|
self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE')
|
||||||
self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated
|
self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') # deprecated
|
||||||
|
@ -33,9 +33,11 @@ class Config:
|
||||||
self.safe_keys = [
|
self.safe_keys = [
|
||||||
'lang_search',
|
'lang_search',
|
||||||
'lang_interface',
|
'lang_interface',
|
||||||
'ctry',
|
'country',
|
||||||
'dark',
|
'theme',
|
||||||
'theme'
|
'alts',
|
||||||
|
'new_tab',
|
||||||
|
'safe'
|
||||||
]
|
]
|
||||||
|
|
||||||
# Skip setting custom config if there isn't one
|
# Skip setting custom config if there isn't one
|
||||||
|
@ -107,3 +109,17 @@ class Config:
|
||||||
continue
|
continue
|
||||||
self[param_key] = params.get(param_key)
|
self[param_key] = params.get(param_key)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def to_params(self) -> str:
|
||||||
|
"""Generates a set of safe params for using in Whoogle URLs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str -- a set of URL parameters
|
||||||
|
"""
|
||||||
|
param_str = ''
|
||||||
|
for safe_key in self.safe_keys:
|
||||||
|
if not self[safe_key]:
|
||||||
|
continue
|
||||||
|
param_str = param_str + f'&{safe_key}={self[safe_key]}'
|
||||||
|
|
||||||
|
return param_str
|
||||||
|
|
|
@ -120,7 +120,7 @@ def gen_query(query, args, config, near_city=None) -> str:
|
||||||
if 'chips' in args:
|
if 'chips' in args:
|
||||||
param_dict['chips'] = '&chips=' + args.get('chips')
|
param_dict['chips'] = '&chips=' + args.get('chips')
|
||||||
|
|
||||||
param_dict['gl'] = ('&gl=' + config.ctry) if config.ctry else ''
|
param_dict['gl'] = ('&gl=' + config.country) if config.country else ''
|
||||||
param_dict['hl'] = '&hl=' + (
|
param_dict['hl'] = '&hl=' + (
|
||||||
config.lang_interface.replace('lang_', '')
|
config.lang_interface.replace('lang_', '')
|
||||||
if config.lang_interface else ''
|
if config.lang_interface else ''
|
||||||
|
|
|
@ -176,3 +176,10 @@ details summary {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mobile styles */
|
||||||
|
@media (max-width: 1000px) {
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -85,15 +85,15 @@
|
||||||
<div class="config-fields">
|
<div class="config-fields">
|
||||||
<form id="config-form" action="config" method="post">
|
<form id="config-form" action="config" method="post">
|
||||||
<div class="config-options">
|
<div class="config-options">
|
||||||
<div class="config-div config-div-ctry">
|
<div class="config-div config-div-country">
|
||||||
<label for="config-ctry">{{ translation['config-country'] }}: </label>
|
<label for="config-country">{{ translation['config-country'] }}: </label>
|
||||||
<select name="ctry" id="config-ctry">
|
<select name="country" id="config-country">
|
||||||
{% for ctry in countries %}
|
{% for country in countries %}
|
||||||
<option value="{{ ctry.value }}"
|
<option value="{{ country.value }}"
|
||||||
{% if ctry.value in config.ctry %}
|
{% if country.value in config.country %}
|
||||||
selected
|
selected
|
||||||
{% endif %}>
|
{% endif %}>
|
||||||
{{ ctry.name }}
|
{{ country.name }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -9,7 +9,7 @@ demo_config = {
|
||||||
'nojs': str(random.getrandbits(1)),
|
'nojs': str(random.getrandbits(1)),
|
||||||
'lang_interface': random.choice(app.config['LANGUAGES'])['value'],
|
'lang_interface': random.choice(app.config['LANGUAGES'])['value'],
|
||||||
'lang_search': random.choice(app.config['LANGUAGES'])['value'],
|
'lang_search': random.choice(app.config['LANGUAGES'])['value'],
|
||||||
'ctry': random.choice(app.config['COUNTRIES'])['value']
|
'country': random.choice(app.config['COUNTRIES'])['value']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user