.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
 __init__ (self, default_value, bool locked=False)
 
 get_value (self)
 

Public Attributes

 choices = choices
 
- 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 98 of file preferences.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 101 of file preferences.py.

101 def __init__(self, default_value: List[str], choices: Iterable[str], locked=False):
102 super().__init__(default_value, locked)
103 self.choices = choices
104 self._validate_selections(self.value)
105

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

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

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

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

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

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

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

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

References searx.preferences.Setting.value.

Member Data Documentation

◆ choices


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