.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)
 
bool choices = False
 
 disabled
 
 enabled
 

Detailed Description

Maps strings to booleans that are either true or false.

Definition at line 233 of file preferences.py.

Constructor & Destructor Documentation

◆ __init__()

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

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

Definition at line 236 of file preferences.py.

236 def __init__(self, name: str, choices: Dict[str, bool], locked: bool = False):
237 self.name = name
238 self.choices = choices
239 self.locked = locked
240 self.default_choices = dict(choices)
241

Member Function Documentation

◆ disabled()

searx.preferences.BooleanChoices.disabled ( self)

Definition at line 270 of file preferences.py.

270 def disabled(self):
271 return (k for k, v in self.choices.items() if not v)
272

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

Referenced by searx.preferences.BooleanChoices.save().

+ Here is the caller graph for this function:

◆ enabled()

searx.preferences.BooleanChoices.enabled ( self)

Definition at line 266 of file preferences.py.

266 def enabled(self):
267 return (k for k, v in self.choices.items() if v)
268

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

Referenced by searx.preferences.BooleanChoices.save().

+ Here is the caller graph for this function:

◆ get_disabled()

searx.preferences.BooleanChoices.get_disabled ( self)

Definition at line 280 of file preferences.py.

280 def get_disabled(self):
281 return self.transform_values(list(self.disabled))
282

◆ get_enabled()

searx.preferences.BooleanChoices.get_enabled ( self)

Definition at line 283 of file preferences.py.

283 def get_enabled(self):
284 return self.transform_values(list(self.enabled))
285
286

◆ parse_cookie()

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

Definition at line 248 of file preferences.py.

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

◆ parse_form()

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

Definition at line 257 of file preferences.py.

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

References searx.preferences.BooleanChoices.choices, searx.preferences.EnumStringSetting.choices, searx.preferences.MultipleChoiceSetting.choices, searx.preferences.SearchLanguageSetting.choices, searx.preferences.BooleanChoices.locked, searx.preferences.MultipleChoiceSetting.locked, searx.preferences.SetSetting.locked, searx.preferences.Setting.locked, searx.preferences.BooleanChoices.transform_form_items(), searx.preferences.EnginesSetting.transform_form_items(), and searx.preferences.PluginsSetting.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 273 of file preferences.py.

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

References searx.preferences.BooleanChoices.default_choices, searx.preferences.BooleanChoices.disabled(), searx.preferences.BooleanChoices.disabled, searx.preferences.BooleanChoices.enabled(), searx.preferences.BooleanChoices.enabled, searx.format, 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, searx.preferences.BooleanChoices.name, and searx.search.models.EngineRef.name.

+ Here is the call graph for this function:

◆ transform_form_items()

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

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

Definition at line 242 of file preferences.py.

242 def transform_form_items(self, items):
243 return items
244

Referenced by searx.preferences.BooleanChoices.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 245 of file preferences.py.

245 def transform_values(self, values):
246 return values
247

Member Data Documentation

◆ choices [1/2]

◆ choices [2/2]

◆ default_choices

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

Definition at line 240 of file preferences.py.

Referenced by searx.preferences.BooleanChoices.save().

◆ disabled

searx.preferences.BooleanChoices.disabled

Definition at line 281 of file preferences.py.

Referenced by searx.preferences.BooleanChoices.save().

◆ enabled

searx.preferences.BooleanChoices.enabled

Definition at line 284 of file preferences.py.

Referenced by searx.preferences.BooleanChoices.save().

◆ locked

searx.preferences.BooleanChoices.locked = locked

Definition at line 239 of file preferences.py.

Referenced by searx.preferences.BooleanChoices.parse_form().

◆ name


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