mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 22:50:26 +00:00
6c8a3ac36c
For a setting to be useful, the code has to be able to make sense of it anyway. For this reason it makes sense, that the available settings are defined within the code, rather than in the database, where a missing row has previously caused problems. Instead, settings are now written to the database, when they are changed. So instead of relying on the database initialization process to create all available settings for us in the database, the supported settings and their defaults are now in a `defaults` dict in the Setting class. With this in place, we can stop populating the `setting` table as a part of database initialization and it will be much easier to support new settings in the future (we no longer need to do anything to the database, to achieve that). Another benefit is that any changes to default values will take effect automatically, unless the admin has already modified that setting to his/her liking. To make it easier to get the value of a setting, falling back to defaults etc, a new function `get` has been added to the Setting class. Call it as `Setting().get('setting_name'), and it will take care of returning a setting from the database or return the default value for that setting, if nothing was found. The `get` function returns `None`, if the setting passed to the function, does not exist in the `Setting.defaults` dict - Indicating that we don't know of a setting by that name.
21 lines
637 B
Python
Executable File
21 lines
637 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from app import app, db
|
|
from app.models import Role, Setting, DomainTemplate
|
|
|
|
admin_role = Role(name='Administrator', description='Administrator')
|
|
user_role = Role(name='User', description='User')
|
|
|
|
template_1 = DomainTemplate(name='basic_template_1', description='Basic Template #1')
|
|
template_2 = DomainTemplate(name='basic_template_2', description='Basic Template #2')
|
|
template_3 = DomainTemplate(name='basic_template_3', description='Basic Template #3')
|
|
|
|
db.session.add(admin_role)
|
|
db.session.add(user_role)
|
|
|
|
db.session.add(template_1)
|
|
db.session.add(template_2)
|
|
db.session.add(template_3)
|
|
|
|
db.session.commit()
|