save_cli Validate and update the value for the preference in the configuration database for the given user (used by the CLI). :param mid: Module ID :param cid: Category ID :param pid: Preference ID :param user_id: User to set the preference f
(cls, mid, cid, pid, user_id, value)
| 600 | |
| 601 | @classmethod |
| 602 | def save_cli(cls, mid, cid, pid, user_id, value): |
| 603 | """ |
| 604 | save_cli |
| 605 | Validate and update the value for the preference in the |
| 606 | configuration database for the given user (used by the CLI). |
| 607 | |
| 608 | :param mid: Module ID |
| 609 | :param cid: Category ID |
| 610 | :param pid: Preference ID |
| 611 | :param user_id: User to set the preference for |
| 612 | :param value: Value for the options |
| 613 | """ |
| 614 | # Find the entry for this module in the configuration database. |
| 615 | module = ModulePrefTable.query.filter_by(id=mid).first() |
| 616 | |
| 617 | if module is None: |
| 618 | return False, gettext("Could not find the specified module.") |
| 619 | |
| 620 | m = cls.modules.get(module.name) |
| 621 | if m is None: |
| 622 | return False, gettext( |
| 623 | "Module '{0}' is no longer in use." |
| 624 | ).format(module.name) |
| 625 | |
| 626 | category = None |
| 627 | for c in m.categories: |
| 628 | cat = m.categories[c] |
| 629 | if cid == cat['id']: |
| 630 | category = cat |
| 631 | break |
| 632 | |
| 633 | if category is None: |
| 634 | return False, gettext( |
| 635 | "Module '{0}' does not have category with id '{1}'" |
| 636 | ).format(module.name, cid) |
| 637 | |
| 638 | preference = None |
| 639 | for p in category['preferences']: |
| 640 | pref = (category['preferences'])[p] |
| 641 | if pref.pid == pid: |
| 642 | preference = pref |
| 643 | break |
| 644 | |
| 645 | if preference is None: |
| 646 | return False, gettext("Could not find the specified preference.") |
| 647 | |
| 648 | # Delegate to set() so the value is validated against the |
| 649 | # preference type, just like the GUI path. |
| 650 | return preference.set(value, user_id=user_id) |
| 651 | |
| 652 | @classmethod |
| 653 | def save(cls, mid, cid, pid, value): |