MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / save

Function save

web/pgadmin/preferences/__init__.py:226–299  ·  view source on GitHub ↗

Save a specific preference.

()

Source from the content-addressed store, hash-verified

224@blueprint.route("/", methods=["PUT"], endpoint="update")
225@pga_login_required
226def save():
227 """
228 Save a specific preference.
229 """
230 pref_data = get_data()
231
232 # Check once whether the user is explicitly setting default_provider
233 # in this save, so auto-selection doesn't override their choice.
234 _provider_map = {
235 'anthropic_api_key_file': 'anthropic',
236 'openai_api_key_file': 'openai',
237 'ollama_api_url': 'ollama',
238 'docker_api_url': 'docker',
239 }
240 explicit_provider_choice = any(
241 item.get('name') == 'default_provider' for item in pref_data
242 )
243
244 for data in pref_data:
245 if data['name'] in ['vw_edt_tab_title_placeholder',
246 'qt_tab_title_placeholder',
247 'debugger_tab_title_placeholder'] \
248 and data['value'].isspace():
249 data['value'] = ''
250
251 res, msg = Preferences.save(
252 data['mid'], data['category_id'], data['id'], data['value'])
253 sgm.get_nodes(sgm)
254
255 if data['name'] == 'save_app_state' and not data['value']:
256 delete_tool_data()
257
258 # Auto-select the default LLM provider when an API key/URL is
259 # configured and no provider has been selected yet.
260 if res and not explicit_provider_choice and \
261 data['name'] in _provider_map and data['value']:
262 ai_module = Preferences.module('ai')
263 if ai_module:
264 dp_pref = ai_module.preference('default_provider')
265 if dp_pref and not dp_pref.get():
266 dp_pref.set(_provider_map[data['name']])
267
268 if not res:
269 return internal_server_error(errormsg=msg)
270
271 response = success_return()
272
273 # Set cookie & session for language settings.
274 # This will execute every time as could not find the better way to know
275 # that which preference is getting updated.
276
277 misc_preference = Preferences.module('misc')
278 user_languages = misc_preference.preference(
279 'user_language'
280 )
281
282 language = 'en'
283 if user_languages:

Callers

nothing calls this directly

Calls 11

delete_tool_dataFunction · 0.90
internal_server_errorFunction · 0.90
success_returnFunction · 0.90
moduleMethod · 0.80
preferenceMethod · 0.80
set_cookieMethod · 0.80
get_dataFunction · 0.70
getMethod · 0.45
saveMethod · 0.45
get_nodesMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected