pawamoy / django-appsettings

Application settings helper for Django apps.
ISC License
15 stars 5 forks source link

Mapping setting #94

Open ziima opened 3 years ago

ziima commented 3 years ago

We have a DictSetting and a NestedDictSetting, but we lack a setting which would define a dictionary with specific values, but various keys, such as CACHES and DATABASES.

I suggest a name MappingSetting, example:

class MySettings(appsettings.AppSettings):
    my_map = appsettings.MappingSetting(appsettings.StringSetting(), default=None)

MY_MAP = {
    'question': 'unknown',
    'answer': '42',
}
stinovlas commented 3 years ago

I think this is too similar to DictSetting. Why not just expand DictSetting to handle complex value types? It can already handle simple type check.

ziima commented 3 years ago

The complex type is another Setting, which has completely different interface than just generic type.

Or do you have any particular solution in mind?

stinovlas commented 3 years ago

The interface of the inner type is different, that's true. But I think we don't have to make the appsettings API more complicated. It seems to be quite confusing to have DictSetting and MappingSetting that do basically the same thing and differ only in their values types.

ziima commented 3 years ago

The MappingSetting is a form of a nested setting. It might be more adequate to modify NestedDictSetting instead, but it requires changes in the core anyway.

stinovlas commented 3 years ago

NestedDictSetting is different, because it restricts the key set, unlike the setting you want. On the other hand, DictSetting does not restrict the key set. DictSetting is much more similar to what you want from the API point of view (the implementation would need to change a lot, I agree).

ziima commented 3 years ago

NestedDictSetting unlike DictSetting is designed to contain another Setting within. In my opinion that's quite close also from the API point of view.