def test_config_dict_value_from_default__value_key_added(self):
     self.assertNotIn("value", self.config_dict['TEST_A'])
     self.assertNotIn("value", self.config_dict['TEST_B'])
     updated_config_dict = utils.config_dict_value_from_default(self.config_dict)
     self.assertIn("value", updated_config_dict['TEST_A'])
     self.assertIn("value", updated_config_dict['TEST_B'])
     self.assertNotIn("value", self.config_dict['TEST_A'])
     self.assertNotIn("value", self.config_dict['TEST_B'])
 def test_config_dict_value_from_default__value_key_added(self):
     self.assertNotIn("value", self.config_dict['TEST_A'])
     self.assertNotIn("value", self.config_dict['TEST_B'])
     updated_config_dict = utils.config_dict_value_from_default(self.config_dict)
     self.assertIn("value", updated_config_dict['TEST_A'])
     self.assertIn("value", updated_config_dict['TEST_B'])
     self.assertNotIn("value", self.config_dict['TEST_A'])
     self.assertNotIn("value", self.config_dict['TEST_B'])
 def save_model(self, request, obj, form, change):
     if obj.id is None:
         config_lookup = registry.config_registry.get_config_class(
             obj.application.short_name
         )
         default_config = config_lookup[1]().get_default_configs()
         obj.set_config_options(utils.config_dict_value_from_default(default_config), save=False)
     else:
         obj.set_config_options(
             form.cleaned_data.get('options', {}), save=False)
     obj.save()
 def save_model(self, request, obj, form, change):
     if obj.id is None:
         config_lookup = registry.config_registry.get_config_class(
             obj.application.short_name)
         default_config = config_lookup[1]().get_default_configs()
         obj.set_config_options(
             utils.config_dict_value_from_default(default_config),
             save=False)
     else:
         obj.set_config_options(form.cleaned_data.get('options', {}),
                                save=False)
     obj.save()
 def mget(self, config_dict, application_short_name, website_short_name=None):
     # Django 1.9+ registers apps;  this import is needed here to avoid
     # the AppRegistryNotReady exception
     from . import models
     # set a default 'value' in each nested config dict
     config_dict = utils.config_dict_value_from_default(config_dict)
     # lookup the site application
     site_app_list = models.WebsiteApplication.objects.website_applications(
                     website_short_name=website_short_name,
                     application_short_name=application_short_name,
                     )
     if site_app_list.count() == 1:
         site_app = site_app_list[0]
         config_dict = site_app.get_config_options(config_dict)
     return config_dict
 def clean_form(self):
     cleaned_data = super(self.__class__, self).clean()
     if instance and config_class:
         if cleaned_data.get('reset_options'):
             cleaned_data['options'] = utils.config_dict_value_from_default(
                 config_class.get_configs())
         else:
             cleaned_configs = {}
             for k, v in cleaned_data.items():
                 if k in config_fields:
                     cleaned_configs.update(
                         {k: {'value': cleaned_data.pop(k)}}
                     )
             cleaned_data['options'] = utils.update_config_dict(
                 config_class.get_configs(), cleaned_configs)
     return cleaned_data
 def mget(self,
          config_dict,
          application_short_name,
          website_short_name=None):
     # Django 1.9+ registers apps;  this import is needed here to avoid
     # the AppRegistryNotReady exception
     from . import models
     # set a default 'value' in each nested config dict
     config_dict = utils.config_dict_value_from_default(config_dict)
     # lookup the site application
     site_app_list = models.WebsiteApplication.objects.filter(
         website__short_name=website_short_name,
         application__short_name=application_short_name,
     )
     if site_app_list.count() == 1:
         site_app = site_app_list[0]
         config_dict = site_app.get_config_options(config_dict)
     return config_dict
Example #8
0
 def clean_form(self):
     cleaned_data = super(self.__class__, self).clean()
     if instance and config_class:
         if cleaned_data.get('reset_options'):
             cleaned_data['options'] = utils.config_dict_value_from_default(
                 config_class.get_configs())
         else:
             # The previous version of the line below would "pop()" the value from "cleaned_data"
             # as it set that value into "cleaned_configs". This worked under Py2, but caused an
             # error in Py3 as "cleaned_data" was being mutated during iteration.  I fixed it as
             # below but was it important to pop those values from cleaned_data before returning?
             cleaned_configs = {
                 k: {
                     'value': v
                 }
                 for k, v in cleaned_data.items() if k in config_fields
             }
             cleaned_data['options'] = utils.update_config_dict(
                 config_class.get_configs(), cleaned_configs)
     return cleaned_data
 def test_config_dict_value_from_default__default_equals_value(self):
     for k, v in utils.config_dict_value_from_default(self.config_dict).items():
         self.assertEqual(v['default'], v['value'], )
 def test_config_dict_value_from_default__default_equals_value(self):
     for k, v in utils.config_dict_value_from_default(self.config_dict).items():
         self.assertEqual(v['default'], v['value'], )