Beispiel #1
0
    def update_settings(self, settings, verbosity=1):
        """
        Loop through the settings and add or update them
        """
        required_keys = [
            'scope',
            'scope_category',
            'name'
        ]
        for setting in settings:
            # check the required fields
            req_list = [k for k in setting.keys() if k in required_keys]
            if len(req_list) != len(required_keys):
                print 'Setting does not have the required fields ... skipping.'
                continue

            try:
                current_setting = Setting.objects.filter(**{
                    'name': setting['name'],
                    'scope': setting['scope'],
                    'scope_category': setting['scope_category']
                })[0]
            except:
                current_setting = None

            # update the setting
            if (current_setting):
                # skip the value for the existing setting
                if setting.has_key('value'):
                    del setting['value']
                current_setting.__dict__.update(setting)
                current_setting.save()
                print '%s (%s)  - updated.' % (
                    setting['name'],
                    setting['scope_category']
                )
            else:
                # insert
                new_setting = Setting(**setting)
                new_setting.save()
                #if verbosity >= 2:
                print '%s (%s)  - added.' % (
                    setting['name'],
                    setting['scope_category']
                )
Beispiel #2
0
    def add_settings(self, settings):
        """
        Loop through the settings and add them
        """
        for setting in settings:
            new_setting = Setting(**setting)

            exists = Setting.objects.filter(
                **{
                    'name': new_setting.name,
                    'scope': new_setting.scope,
                    'scope_category': new_setting.scope_category
                }).exists()

            if (exists):
                print '%s (%s) already exists ... skipping.' % (
                    new_setting.name, new_setting.scope_category)
            else:
                print '%s (%s) ... done.' % (new_setting.name,
                                             new_setting.scope_category)
                new_setting.save()
Beispiel #3
0
    def update_settings(self, settings, verbosity=1):
        """
        Loop through the settings and add or update them
        """
        required_keys = ['scope', 'scope_category', 'name']
        for setting in settings:
            # check the required fields
            req_list = [k for k in setting.keys() if k in required_keys]
            if len(req_list) != len(required_keys):
                print 'Setting does not have the required fields ... skipping.'
                continue

            try:
                current_setting = Setting.objects.filter(
                    **{
                        'name': setting['name'],
                        'scope': setting['scope'],
                        'scope_category': setting['scope_category']
                    })[0]
            except:
                current_setting = None

            # update the setting
            if (current_setting):
                # skip the value for the existing setting
                if setting.has_key('value'):
                    del setting['value']
                current_setting.__dict__.update(setting)
                current_setting.save()
                print '%s (%s)  - updated.' % (setting['name'],
                                               setting['scope_category'])
            else:
                # insert
                new_setting = Setting(**setting)
                new_setting.save()
                #if verbosity >= 2:
                print '%s (%s)  - added.' % (setting['name'],
                                             setting['scope_category'])
Beispiel #4
0
    def add_settings(self, settings):
        """
        Loop through the settings and add them
        """
        for setting in settings:
            new_setting = Setting(**setting)

            exists = Setting.objects.filter(**{
                'name': new_setting.name,
                'scope': new_setting.scope,
                'scope_category': new_setting.scope_category
            }).exists()

            if (exists):
                print '%s (%s) already exists ... skipping.' % (
                    new_setting.name,
                    new_setting.scope_category
                )
            else:
                print '%s (%s) ... done.' % (
                    new_setting.name,
                    new_setting.scope_category
                )
                new_setting.save()