.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.preferences.BooleanChoices Class Reference
+ Inheritance diagram for searx.preferences.BooleanChoices:

Public Member Functions

 __init__ (self, str name, Dict[str, bool] choices, bool locked=False)
 
 transform_form_items (self, items)
 
 transform_values (self, values)
 
 parse_cookie (self, str data_disabled, str data_enabled)
 
 parse_form (self, List[str] items)
 
 enabled (self)
 
 disabled (self)
 
 save (self, flask.Response resp)
 
 get_disabled (self)
 
 get_enabled (self)
 

Public Attributes

 name = name
 
 choices = choices
 
 locked = locked
 
 default_choices = dict(choices)
 
 disabled
 
 enabled
 

Detailed Description

Maps strings to booleans that are either true or false.

Definition at line 236 of file preferences.py.

Constructor & Destructor Documentation

◆ __init__()

searx.preferences.BooleanChoices.__init__ ( self,
str name,
Dict[str, bool] choices,
bool locked = False )

Definition at line 239 of file preferences.py.

239 def __init__(self, name: str, choices: Dict[str, bool], locked: bool = False):
240 self.name = name
241 self.choices = choices
242 self.locked = locked
243 self.default_choices = dict(choices)
244

Member Function Documentation

◆ disabled()

searx.preferences.BooleanChoices.disabled ( self)

Definition at line 273 of file preferences.py.

273 def disabled(self):
274 return (k for k, v in self.choices.items() if not v)
275

References choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, and searx.preferences.SearchLanguageSetting.choices.

◆ enabled()

searx.preferences.BooleanChoices.enabled ( self)

Definition at line 269 of file preferences.py.

269 def enabled(self):
270 return (k for k, v in self.choices.items() if v)
271

References choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, and searx.preferences.SearchLanguageSetting.choices.

◆ get_disabled()

searx.preferences.BooleanChoices.get_disabled ( self)

Definition at line 283 of file preferences.py.

283 def get_disabled(self):
284 return self.transform_values(list(self.disabled))
285

◆ get_enabled()

searx.preferences.BooleanChoices.get_enabled ( self)

Definition at line 286 of file preferences.py.

286 def get_enabled(self):
287 return self.transform_values(list(self.enabled))
288
289

◆ parse_cookie()

searx.preferences.BooleanChoices.parse_cookie ( self,
str data_disabled,
str data_enabled )

Definition at line 251 of file preferences.py.

251 def parse_cookie(self, data_disabled: str, data_enabled: str):
252 for disabled in data_disabled.split(','):
253 if disabled in self.choices:
254 self.choices[disabled] = False
255
256 for enabled in data_enabled.split(','):
257 if enabled in self.choices:
258 self.choices[enabled] = True
259

References choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, and searx.preferences.SearchLanguageSetting.choices.

◆ parse_form()

searx.preferences.BooleanChoices.parse_form ( self,
List[str] items )

Definition at line 260 of file preferences.py.

260 def parse_form(self, items: List[str]):
261 if self.locked:
262 return
263
264 disabled = self.transform_form_items(items)
265 for setting in self.choices:
266 self.choices[setting] = setting not in disabled
267

References choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, searx.preferences.SearchLanguageSetting.choices, locked, searx.preferences.MultipleChoiceSetting.locked, searx.preferences.SetSetting.locked, searx.preferences.Setting.locked, and transform_form_items().

+ Here is the call graph for this function:

◆ save()

searx.preferences.BooleanChoices.save ( self,
flask.Response resp )
Save cookie in the HTTP response object

Definition at line 276 of file preferences.py.

276 def save(self, resp: flask.Response):
277 """Save cookie in the HTTP response object"""
278 disabled_changed = (k for k in self.disabled if self.default_choices[k])
279 enabled_changed = (k for k in self.enabled if not self.default_choices[k])
280 resp.set_cookie('disabled_{0}'.format(self.name), ','.join(disabled_changed), max_age=COOKIE_MAX_AGE)
281 resp.set_cookie('enabled_{0}'.format(self.name), ','.join(enabled_changed), max_age=COOKIE_MAX_AGE)
282

References default_choices, disabled, enabled, searx.engines.wikidata.WDAmountAttribute.name, searx.engines.wikidata.WDAttribute.name, searx.engines.wikidata.WDDateAttribute.name, searx.engines.wikidata.WDGeoAttribute.name, searx.engines.wikidata.WDLabelAttribute.name, and name.

◆ transform_form_items()

searx.preferences.BooleanChoices.transform_form_items ( self,
items )

Reimplemented in searx.preferences.EnginesSetting, and searx.preferences.PluginsSetting.

Definition at line 245 of file preferences.py.

245 def transform_form_items(self, items):
246 return items
247

Referenced by parse_form().

+ Here is the caller graph for this function:

◆ transform_values()

searx.preferences.BooleanChoices.transform_values ( self,
values )

Reimplemented in searx.preferences.EnginesSetting.

Definition at line 248 of file preferences.py.

248 def transform_values(self, values):
249 return values
250

Member Data Documentation

◆ choices

searx.preferences.BooleanChoices.choices = choices

Definition at line 241 of file preferences.py.

Referenced by disabled(), enabled(), parse_cookie(), and parse_form().

◆ default_choices

searx.preferences.BooleanChoices.default_choices = dict(choices)

Definition at line 243 of file preferences.py.

Referenced by save().

◆ disabled

searx.preferences.BooleanChoices.disabled

Definition at line 284 of file preferences.py.

Referenced by save().

◆ enabled

searx.preferences.BooleanChoices.enabled

Definition at line 287 of file preferences.py.

Referenced by save().

◆ locked

searx.preferences.BooleanChoices.locked = locked

Definition at line 242 of file preferences.py.

Referenced by parse_form().

◆ name

searx.preferences.BooleanChoices.name = name

The documentation for this class was generated from the following file: