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

Public Member Functions

 __init__ (self, list[str] default_value, Iterable[str] choices, bool locked=False)
 parse (self, str data)
 parse_form (self, list[str] data)
 save (self, str name, flask.Response resp)
Public Member Functions inherited from searx.preferences.Setting
 __init__ (self, t.Any default_value, bool locked=False)
 get_value (self)

Public Attributes

Iterable[str] choices = choices
Public Attributes inherited from searx.preferences.Setting
t.Any value = default_value
bool locked = locked

Protected Member Functions

 _validate_selections (self, list[str] selections)

Detailed Description

Setting of values which can only come from the given choices

Definition at line 102 of file preferences.py.

Constructor & Destructor Documentation

◆ __init__()

searx.preferences.MultipleChoiceSetting.__init__ ( self,
list[str] default_value,
Iterable[str] choices,
bool locked = False )

Definition at line 105 of file preferences.py.

105 def __init__(self, default_value: list[str], choices: Iterable[str], locked: bool = False):
106 super().__init__(default_value, locked)
107 self.choices: Iterable[str] = choices
108 self._validate_selections(self.value)
109

References __init__().

Referenced by __init__().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _validate_selections()

searx.preferences.MultipleChoiceSetting._validate_selections ( self,
list[str] selections )
protected

Definition at line 110 of file preferences.py.

110 def _validate_selections(self, selections: list[str]):
111 for item in selections:
112 if item not in self.choices:
113 raise ValidationException('Invalid value: "{0}"'.format(selections))
114

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

Referenced by parse().

Here is the caller graph for this function:

◆ parse()

searx.preferences.MultipleChoiceSetting.parse ( self,
str data )
Parse and validate ``data`` and store the result at ``self.value``

Reimplemented from searx.preferences.Setting.

Definition at line 115 of file preferences.py.

115 def parse(self, data: str):
116 """Parse and validate ``data`` and store the result at ``self.value``"""
117 if data == '':
118 self.value: list[str] = []
119 return
120
121 elements = data.split(',')
122 self._validate_selections(elements)
123 self.value = elements
124

References _validate_selections(), and searx.preferences.Setting.value.

Here is the call graph for this function:

◆ parse_form()

searx.preferences.MultipleChoiceSetting.parse_form ( self,
list[str] data )

Definition at line 125 of file preferences.py.

125 def parse_form(self, data: list[str]):
126 if self.locked:
127 return
128
129 self.value = []
130 for choice in data:
131 if choice in self.choices and choice not in self.value:
132 self.value.append(choice)
133

◆ save()

searx.preferences.MultipleChoiceSetting.save ( self,
str name,
flask.Response resp )
Save cookie ``name`` in the HTTP response object

Reimplemented from searx.preferences.Setting.

Definition at line 134 of file preferences.py.

134 def save(self, name: str, resp: flask.Response):
135 """Save cookie ``name`` in the HTTP response object"""
136 resp.set_cookie(name, ','.join(self.value), max_age=COOKIE_MAX_AGE)
137
138

References searx.preferences.Setting.value.

Member Data Documentation

◆ choices


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