Fetch all/or requested preferences of pgAdmin IV.
(module=None, preference=None)
| 73 | @blueprint.route("/<module>/<preference>", endpoint='get_by_name') |
| 74 | @pga_login_required |
| 75 | def preferences(module=None, preference=None): |
| 76 | """Fetch all/or requested preferences of pgAdmin IV.""" |
| 77 | |
| 78 | if module is not None and preference is not None: |
| 79 | try: |
| 80 | m = Preferences.module(module, create=False) |
| 81 | if m is None: |
| 82 | return Response(status=404) |
| 83 | |
| 84 | p = m.preference(preference) |
| 85 | if p is None: |
| 86 | return Response(status=404) |
| 87 | |
| 88 | return ajax_response( |
| 89 | response=p.to_json(), |
| 90 | status=200 |
| 91 | ) |
| 92 | |
| 93 | except Exception as e: |
| 94 | return internal_server_error(errormsg=str(e)) |
| 95 | |
| 96 | # Load Preferences |
| 97 | pref = Preferences.preferences() |
| 98 | res = [] |
| 99 | |
| 100 | def label(p): |
| 101 | return gettext(p['label']) |
| 102 | |
| 103 | _group_pref_by_categories(pref, res, label) |
| 104 | |
| 105 | return ajax_response( |
| 106 | response=sorted(res, key=label), |
| 107 | status=200 |
| 108 | ) |
| 109 | |
| 110 | |
| 111 | def _group_pref_by_categories(pref, res, label): |
no test coverage detected