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

Function update

web/pgadmin/preferences/__init__.py:323–367  ·  view source on GitHub ↗

Update a specific preference.

()

Source from the content-addressed store, hash-verified

321@blueprint.route("/update", methods=["PUT"], endpoint="update_pref")
322@pga_login_required
323def update():
324 """
325 Update a specific preference.
326 """
327 pref_data = get_data()
328 pref_data = json.loads(pref_data['pref_data'])
329
330 # Check once whether the user is explicitly setting default_provider
331 # in this save, so auto-selection doesn't override their choice.
332 _provider_map = {
333 'anthropic_api_key_file': 'anthropic',
334 'openai_api_key_file': 'openai',
335 'ollama_api_url': 'ollama',
336 'docker_api_url': 'docker',
337 }
338 explicit_provider_choice = any(
339 item.get('name') == 'default_provider' for item in pref_data
340 )
341
342 for data in pref_data:
343 if data['name'] in ['vw_edt_tab_title_placeholder',
344 'qt_tab_title_placeholder',
345 'debugger_tab_title_placeholder'] \
346 and data['value'].isspace():
347 data['value'] = ''
348
349 pref_module = Preferences.module(data['module'])
350 pref = pref_module.preference(data['name'])
351 # set user preferences
352 pref.set(data['value'])
353
354 # Auto-select the default LLM provider when an API key/URL is
355 # configured and no provider has been selected yet.
356 if not explicit_provider_choice and \
357 data['name'] in _provider_map and data['value']:
358 ai_module = Preferences.module('ai')
359 if ai_module:
360 dp_pref = ai_module.preference('default_provider')
361 if dp_pref and not dp_pref.get():
362 dp_pref.set(_provider_map[data['name']])
363
364 return make_json_response(
365 data={'data': 'Success'},
366 status=200
367 )
368
369
370@blueprint.route("/", methods=['DELETE'], endpoint="reset_prefs")

Callers

nothing calls this directly

Calls 6

make_json_responseFunction · 0.90
moduleMethod · 0.80
preferenceMethod · 0.80
get_dataFunction · 0.70
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected