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

Method save

web/pgadmin/utils/preferences.py:653–711  ·  view source on GitHub ↗

save Update the value for the preference in the configuration database. :param mid: Module ID :param cid: Category ID :param pid: Preference ID :param value: Value for the options

(cls, mid, cid, pid, value)

Source from the content-addressed store, hash-verified

651
652 @classmethod
653 def save(cls, mid, cid, pid, value):
654 """
655 save
656 Update the value for the preference in the configuration database.
657
658 :param mid: Module ID
659 :param cid: Category ID
660 :param pid: Preference ID
661 :param value: Value for the options
662 """
663 # Find the entry for this module in the configuration database.
664 module = ModulePrefTable.query.filter_by(id=mid).first()
665
666 # Can't find the reference for it in the configuration database,
667 # create on for it.
668 if module is None:
669 return False, gettext("Could not find the specified module.")
670
671 m = cls.modules[module.name]
672
673 if m is None:
674 return False, gettext(
675 "Module '{0}' is no longer in use."
676 ).format(module.name)
677
678 category = None
679
680 for c in m.categories:
681 cat = m.categories[c]
682 if cid == cat['id']:
683 category = cat
684 break
685
686 if category is None:
687 return False, gettext(
688 "Module '{0}' does not have category with id '{1}'"
689 ).format(module.name, cid)
690
691 preference = None
692
693 for p in category['preferences']:
694 pref = (category['preferences'])[p]
695
696 if pref.pid == pid:
697 preference = pref
698 break
699
700 if preference is None:
701 return False, gettext(
702 "Could not find the specified preference."
703 )
704
705 try:
706 pref.set(value)
707 except Exception as e:
708 current_app.logger.exception(e)
709 return False, str(e)
710

Callers 2

saveFunction · 0.45
_registration_viewMethod · 0.45

Calls 3

gettextFunction · 0.85
firstMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected