diff --git a/projectroles/forms.py b/projectroles/forms.py index b98f02aa..afe8cb81 100644 --- a/projectroles/forms.py +++ b/projectroles/forms.py @@ -71,9 +71,6 @@ SETTING_SOURCE_ONLY_MSG = '[Only editable on source site]' -# TODO: Remove redundant s_key fields (not needed) - - # Base Classes and Mixins ------------------------------------------------------ @@ -390,13 +387,12 @@ def _init_remote_sites(self): required=False, ) - def _set_app_setting_field(self, plugin_name, s_field, s_key, s_def): + def _set_app_setting_field(self, plugin_name, s_field, s_def): """ Internal helper for setting app setting field, widget and value. :param plugin_name: App plugin name :param s_field: Form field name - :param s_key: Setting key :param s_def: PluginAppSettingDef object """ s_widget_attrs = s_def.widget_attrs @@ -406,7 +402,7 @@ def _set_app_setting_field(self, plugin_name, s_field, s_key, s_def): s_widget_attrs['placeholder'] = s_def.placeholder setting_kwargs = { 'required': False, - 'label': s_def.label or '{}.{}'.format(plugin_name, s_key), + 'label': s_def.label or '{}.{}'.format(plugin_name, s_def.name), 'help_text': s_def.description, } @@ -477,7 +473,7 @@ def _set_app_setting_field(self, plugin_name, s_field, s_key, s_def): # Set initial value value = self.app_settings.get( plugin_name=plugin_name, - setting_name=s_key, + setting_name=s_def.name, project=self.instance if self.instance.pk else None, ) if s_def.type == APP_SETTING_TYPE_JSON: @@ -532,10 +528,10 @@ def _init_app_settings(self): plugin_name=plugin_name, **self.p_kwargs ) - for s_key, s_def in s_defs.items(): - s_field = 'settings.{}.{}'.format(plugin_name, s_key) + for s_def in s_defs.values(): + s_field = 'settings.{}.{}'.format(plugin_name, s_def.name) # Set field, widget and value - self._set_app_setting_field(plugin_name, s_field, s_key, s_def) + self._set_app_setting_field(plugin_name, s_field, s_def) # Set label notes self._set_app_setting_notes(s_field, s_def, plugin) @@ -562,12 +558,12 @@ def _validate_app_settings( ) p_settings = {} - for s_key, s_def in s_defs.items(): - s_field = '.'.join(['settings', p_name, s_key]) - p_settings[s_key] = cleaned_data.get(s_field) + for s_def in s_defs.values(): + s_field = '.'.join(['settings', p_name, s_def.name]) + p_settings[s_def.name] = cleaned_data.get(s_field) if s_def.type == APP_SETTING_TYPE_JSON: - if not p_settings[s_key]: + if not p_settings[s_def.name]: cleaned_data[s_field] = '{}' try: cleaned_data[s_field] = json.loads( diff --git a/projectroles/views.py b/projectroles/views.py index f03c723c..2189da0e 100644 --- a/projectroles/views.py +++ b/projectroles/views.py @@ -976,14 +976,14 @@ def _get_app_settings(data, instance, user): APP_SETTING_SCOPE_PROJECT, plugin_name=name, **p_kwargs ) - for s_key, s_def in p_settings.items(): - s_name = 'settings.{}.{}'.format(name, s_key) + for s_def in p_settings.values(): + s_name = 'settings.{}.{}'.format(name, s_def.name) s_data = data.get(s_name) if instance.type not in s_def.project_types: continue if s_data is None and not instance: - s_data = app_settings.get_default(name, s_key) + s_data = app_settings.get_default(name, s_def.name) if s_def.type == APP_SETTING_TYPE_JSON: if s_data is None: s_data = {} diff --git a/userprofile/forms.py b/userprofile/forms.py index 54576ed6..530d6991 100644 --- a/userprofile/forms.py +++ b/userprofile/forms.py @@ -34,27 +34,23 @@ APP_SETTING_TYPE_STRING = SODAR_CONSTANTS['APP_SETTING_TYPE_STRING'] -# TODO: Remove redundant s_key fields (not needed) - - class UserSettingsForm(SODARForm): """Form for configuring user settings""" - def _set_app_setting_field(self, plugin_name, s_field, s_key, s_def): + def _set_app_setting_field(self, plugin_name, s_field, s_def): """ Set user app setting field, widget and value. :param plugin_name: App plugin name :param s_field: Form field name - :param s_key: Setting key - :param s_def: PluginAppSettingDef + :param s_def: PluginAppSettingDef object """ s_widget_attrs = s_def.widget_attrs if s_def.placeholder is not None: s_widget_attrs['placeholder'] = s_def.placeholder setting_kwargs = { 'required': False, - 'label': s_def.label or '{}.{}'.format(plugin_name, s_key), + 'label': s_def.label or '{}.{}'.format(plugin_name, s_def.name), 'help_text': s_def.description, } # Disable global user settings if on target site @@ -116,7 +112,7 @@ def _set_app_setting_field(self, plugin_name, s_field, s_key, s_def): # Modify initial value and attributes self.fields[s_field].widget.attrs.update(s_widget_attrs) value = app_settings.get( - plugin_name=plugin_name, setting_name=s_key, user=self.user + plugin_name=plugin_name, setting_name=s_def.name, user=self.user ) if s_def.type == APP_SETTING_TYPE_JSON: value = json.dumps(value) @@ -132,20 +128,20 @@ def __init__(self, *args, **kwargs): for plugin in self.app_plugins + [None]: if plugin: - name = plugin.name + plugin_name = plugin.name s_defs = app_settings.get_definitions( APP_SETTING_SCOPE_USER, plugin=plugin, user_modifiable=True ) else: - name = 'projectroles' + plugin_name = 'projectroles' s_defs = app_settings.get_definitions( APP_SETTING_SCOPE_USER, - plugin_name=name, + plugin_name=plugin_name, user_modifiable=True, ) - for s_key, s_def in s_defs.items(): - s_field = 'settings.{}.{}'.format(name, s_key) - self._set_app_setting_field(name, s_field, s_key, s_def) + for s_def in s_defs.values(): + s_field = 'settings.{}.{}'.format(plugin_name, s_def.name) + self._set_app_setting_field(plugin_name, s_field, s_def) self.fields[s_field].label = self.get_app_setting_label( plugin, self.fields[s_field].label ) @@ -165,9 +161,9 @@ def clean(self): ) p_settings = {} - for s_key, s_def in s_defs.items(): - s_field = '.'.join(['settings', p_name, s_key]) - p_settings[s_key] = self.cleaned_data.get(s_field) + for s_def in s_defs.values(): + s_field = '.'.join(['settings', p_name, s_def.name]) + p_settings[s_def.name] = self.cleaned_data.get(s_field) if s_def.type == APP_SETTING_TYPE_JSON: if not self.cleaned_data.get(s_field):