def __init__(self, *args, **kwargs): super(SettingsForm, self).__init__(*args, **kwargs) conf = self.read_settings() self.fields['settings'].initial = conf params = SFTP.get_params(conf.split('\n')) for p in params: setattr(settings, str(p[0]).upper(), p[1])
def save(self, commit=True): instance = super(SettingsForm, self).save(commit=commit) if self.is_valid(): conf = self.cleaned_data.get('settings') self.write_settings(self.cleaned_data.get('settings')) params = SFTP.get_params(conf.split('\n')) for p in params: setattr(settings, str(p[0]).upper(), p[1]) return instance
import os from dispatch_service import settings from utils.sftp import SFTP path = os.path.realpath(os.path.join(settings.DJANGO_PROJECT_ROOT, 'conf.ini')) params = [] if SFTP.validate_conf(path): with open(path, 'r') as conf_file: params = SFTP.get_params(conf_file.read().split('\n')) for p in params: setattr(settings, str(p[0]).upper(), p[1])