def __get__(self, instance=None, type=None): if instance == None: raise AttributeError, "%r is only accessible from %s instances." % (self.attribute_name, type.__name__) try: storage = get_setting_storage(*self.key) return self.to_python(storage.value) except: return None
def install_settings(app, created_models, verbosity=2): printed = False for class_name, attribute_name, value in defaults: if not get_setting_storage(app.__name__, class_name, attribute_name): if verbosity >= 2 and not printed: # Print this message only once, and only if applicable print "Installing default settings for %s" % app_label printed = True try: set_setting_value(app.__name__, class_name, attribute_name, value) except: raise ImproperlyConfigured("%s requires dbsettings." % app_label)
def customized_editor(user, settings): "Customize the setting editor based on the current user and setting list" base_fields = SortedDict() for setting in settings: perm = '%s.can_edit_%s_settings' % ( setting.module_name.split('.')[-2], setting.class_name.lower() ) if user.has_perm(perm): # Add the field to the customized field list storage = get_setting_storage(*setting.key) kwargs = { 'label': setting.description, 'help_text': setting.help_text, # Provide current setting values for initializing the form 'initial': setting.to_editor(storage.value), } if setting.choices: field = forms.ChoiceField(choices=setting.choices, **kwargs) else: field = setting.field(**kwargs) base_fields['%s__%s__%s' % setting.key] = field return type('SettingsEditor', (SettingsEditor,), {'base_fields': base_fields})