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)
| 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 |
no test coverage detected