Changeset 1601
- Timestamp:
- 05/28/08 13:35:42 (22 months ago)
- Location:
- trunk/pylucid/PyLucid
- Files:
-
- 2 modified
-
models/Plugin.py (modified) (2 diffs)
-
system/exceptions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/models/Plugin.py
r1585 r1601 27 27 from PyLucid.tools.newforms_utils import get_init_dict, setup_help_text 28 28 from PyLucid.tools.data_eval import data_eval, DataEvalError 29 from PyLucid.system.exceptions import PluginPreferencesError 29 30 30 31 preference_cache = {} … … 81 82 # Special methods 82 83 83 def init_pref_form(self, pref_form ):84 def init_pref_form(self, pref_form, debug=False): 84 85 """ 85 86 Set self.pref_data_string from the given newforms form and his initial 86 87 values. 88 Before we save the data dict into the database, we validate it with 89 preferences newform class. This is needed for two cased: 90 - A plugin developer has inserted a wrong initial value 91 - The initial value must be cleaned. e.g. admin_menu_cfg.WeightField 87 92 """ 88 93 init_dict = get_init_dict(pref_form) 89 preference_cache[self.plugin_name] = init_dict 90 self.set_pref_data_string(init_dict) 94 95 # Validate the init_dict 96 unbound_form = self.get_pref_form(debug) 97 form = unbound_form(init_dict) 98 if form.is_valid(): 99 cleaned_data_dict = form.cleaned_data 100 else: 101 msg = ( 102 "Can't save preferences into the database!" 103 " Newforms validate error: %r" 104 ) % form.errors 105 raise PluginPreferencesError(msg) 106 107 preference_cache[self.plugin_name] = cleaned_data_dict 108 self.set_pref_data_string(cleaned_data_dict) 91 109 92 110 #__________________________________________________________________________ -
trunk/pylucid/PyLucid/system/exceptions.py
r1545 r1601 39 39 """ 40 40 pass 41 42 class PluginPreferencesError(Exception): 43 pass