Exemple #1
0
def create_settings_from_fixture(fixture):
    """Inserts the settings from a fixture into the database.
    Returns the created groups and settings.

    :param fixture: The fixture which should inserted.
    """
    created_settings = {}
    for settingsgroup in fixture:
        group = SettingsGroup(
            key=settingsgroup[0],
            name=settingsgroup[1]["name"],
            description=settingsgroup[1]["description"]
        )
        group.save()
        created_settings[group] = []

        for settings in settingsgroup[1]["settings"]:
            value = pickle.dumps(settings[1]["value"])

            extra = settings[1].get("extra", "")
            if extra:
                extra = pickle.dumps(extra)
            setting = Setting(
                key=settings[0],
                value=value,
                value_type=settings[1]["value_type"],
                name=settings[1]["name"],
                description=settings[1]["description"],
                extra=extra,     # Optional field

                settingsgroup=group.key
            )
            if setting:
                setting.save()
                created_settings[group].append(setting)

    return created_settings
Exemple #2
0
 def __len__(self):
     return len(Setting.as_dict())
Exemple #3
0
 def __iter__(self):
     return iter(Setting.as_dict())
Exemple #4
0
 def __setitem__(self, key, value):
     Setting.update({key.lower(): value})
Exemple #5
0
 def __getitem__(self, key):
     return pickle.loads(Setting.as_dict()[key])