.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, 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
 get_value (self)
 

Public Attributes

 choices = choices
 
list value = data.split(',')
 
 locked
 
- Public Attributes inherited from searx.preferences.Setting
 value = default_value
 
 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 95 of file preferences.py.

Constructor & Destructor Documentation

◆ __init__()

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

Reimplemented from searx.preferences.Setting.

Definition at line 98 of file preferences.py.

98 def __init__(self, default_value: List[str], choices: Iterable[str], locked=False):
99 super().__init__(default_value, locked)
100 self.choices = choices
101 self._validate_selections(self.value)
102

References searx.preferences.MultipleChoiceSetting.__init__().

Referenced by searx.preferences.MultipleChoiceSetting.__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 103 of file preferences.py.

103 def _validate_selections(self, selections: List[str]):
104 for item in selections:
105 if item not in self.choices:
106 raise ValidationException('Invalid value: "{0}"'.format(selections))
107

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

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

108 def parse(self, data: str):
109 """Parse and validate ``data`` and store the result at ``self.value``"""
110 if data == '':
111 self.value = []
112 return
113
114 elements = data.split(',')
115 self._validate_selections(elements)
116 self.value = elements
117

References searx.preferences.MultipleChoiceSetting._validate_selections(), searx.preferences.BooleanSetting.value, searx.preferences.EnumStringSetting.value, searx.preferences.MapSetting.value, searx.preferences.MultipleChoiceSetting.value, searx.preferences.SearchLanguageSetting.value, 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 118 of file preferences.py.

118 def parse_form(self, data: List[str]):
119 if self.locked:
120 return
121
122 self.value = []
123 for choice in data:
124 if choice in self.choices and choice not in self.value:
125 self.value.append(choice)
126

◆ 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 127 of file preferences.py.

127 def save(self, name: str, resp: flask.Response):
128 """Save cookie ``name`` in the HTTP response object"""
129 resp.set_cookie(name, ','.join(self.value), max_age=COOKIE_MAX_AGE)
130
131

References searx.preferences.BooleanSetting.value, searx.preferences.EnumStringSetting.value, searx.preferences.MapSetting.value, searx.preferences.MultipleChoiceSetting.value, searx.preferences.SearchLanguageSetting.value, and searx.preferences.Setting.value.

Member Data Documentation

◆ choices

◆ locked

searx.preferences.MultipleChoiceSetting.locked

Definition at line 119 of file preferences.py.

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

◆ value


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