|
@@ -14,39 +14,41 @@ from flaskbb.forum.models import Post, Topic, Forum, Category
|
|
|
|
|
|
|
|
|
def delete_settings_from_fixture(fixture):
|
|
|
- """
|
|
|
- Deletes the settings from a fixture from the database.
|
|
|
+ """Deletes the settings from a fixture from the database.
|
|
|
+
|
|
|
+ :param fixture: The fixture that should be deleted.
|
|
|
"""
|
|
|
for settingsgroup in fixture:
|
|
|
group = SettingsGroup.query.filter_by(key=settingsgroup[0]).first()
|
|
|
|
|
|
- for settings in settingsgroup[1]['settings']:
|
|
|
+ for settings in settingsgroup[1]["settings"]:
|
|
|
setting = Setting.query.filter_by(key=settings[0]).first()
|
|
|
setting.delete()
|
|
|
group.delete()
|
|
|
|
|
|
|
|
|
def create_settings_from_fixture(fixture):
|
|
|
- """
|
|
|
- Inserts the settings from a fixture into the database.
|
|
|
+ """Inserts the settings from a fixture into the database.
|
|
|
+
|
|
|
+ :param fixture: The fixture which should inserted.
|
|
|
"""
|
|
|
for settingsgroup in fixture:
|
|
|
group = SettingsGroup(
|
|
|
key=settingsgroup[0],
|
|
|
- name=settingsgroup[1]['name'],
|
|
|
- description=settingsgroup[1]['description']
|
|
|
+ name=settingsgroup[1]["name"],
|
|
|
+ description=settingsgroup[1]["description"]
|
|
|
)
|
|
|
|
|
|
group.save()
|
|
|
|
|
|
- for settings in settingsgroup[1]['settings']:
|
|
|
+ for settings in settingsgroup[1]["settings"]:
|
|
|
setting = Setting(
|
|
|
key=settings[0],
|
|
|
- value=settings[1]['value'],
|
|
|
- value_type=settings[1]['value_type'],
|
|
|
- name=settings[1]['name'],
|
|
|
- description=settings[1]['description'],
|
|
|
- extra=settings[1].get('extra', ""), # Optional field
|
|
|
+ value=settings[1]["value"],
|
|
|
+ value_type=settings[1]["value_type"],
|
|
|
+ name=settings[1]["name"],
|
|
|
+ description=settings[1]["description"],
|
|
|
+ extra=settings[1].get("extra", ""), # Optional field
|
|
|
|
|
|
settingsgroup=group.key
|
|
|
)
|
|
@@ -55,9 +57,18 @@ def create_settings_from_fixture(fixture):
|
|
|
|
|
|
def update_settings_from_fixture(fixture, overwrite_group=False,
|
|
|
overwrite_setting=False):
|
|
|
- """
|
|
|
- Updates the database settings from a fixture.
|
|
|
+ """Updates the database settings from a fixture.
|
|
|
Returns the number of updated groups and settings.
|
|
|
+
|
|
|
+ :param fixture: The fixture which should be inserted/updated.
|
|
|
+
|
|
|
+ :param overwrite_group: Set this to ``True`` if you want to overwrite
|
|
|
+ the group if it already exists.
|
|
|
+ Defaults to ``False``.
|
|
|
+
|
|
|
+ :param overwrite_setting: Set this to ``True`` if you want to overwrite the
|
|
|
+ setting if it already exists.
|
|
|
+ Defaults to ``False``.
|
|
|
"""
|
|
|
groups_count = 0
|
|
|
settings_count = 0
|
|
@@ -65,47 +76,59 @@ def update_settings_from_fixture(fixture, overwrite_group=False,
|
|
|
|
|
|
group = SettingsGroup.query.filter_by(key=settingsgroup[0]).first()
|
|
|
|
|
|
- if group is not None and overwrite_group or group is None:
|
|
|
+ if (group is not None and overwrite_group) or group is None:
|
|
|
groups_count += 1
|
|
|
- group = SettingsGroup(
|
|
|
- key=settingsgroup[0],
|
|
|
- name=settingsgroup[1]['name'],
|
|
|
- description=settingsgroup[1]['description']
|
|
|
- )
|
|
|
+
|
|
|
+ if group is not None:
|
|
|
+ group.name = settingsgroup[1]["name"]
|
|
|
+ group.description = settingsgroup[1]["description"]
|
|
|
+ else:
|
|
|
+ group = SettingsGroup(
|
|
|
+ key=settingsgroup[0],
|
|
|
+ name=settingsgroup[1]["name"],
|
|
|
+ description=settingsgroup[1]["description"]
|
|
|
+ )
|
|
|
|
|
|
group.save()
|
|
|
|
|
|
- for settings in settingsgroup[1]['settings']:
|
|
|
+ for settings in settingsgroup[1]["settings"]:
|
|
|
|
|
|
setting = Setting.query.filter_by(key=settings[0]).first()
|
|
|
|
|
|
- if setting is not None and overwrite_setting or setting is None:
|
|
|
+ if (setting is not None and overwrite_setting) or setting is None:
|
|
|
settings_count += 1
|
|
|
- setting = Setting(
|
|
|
- key=settings[0],
|
|
|
- value=settings[1]['value'],
|
|
|
- value_type=settings[1]['value_type'],
|
|
|
- name=settings[1]['name'],
|
|
|
- description=settings[1]['description'],
|
|
|
- extra=settings[1].get('extra', ""),
|
|
|
- settingsgroup=group.key
|
|
|
- )
|
|
|
+
|
|
|
+ if setting is not None:
|
|
|
+ setting.value = settings[1]["value"]
|
|
|
+ setting.value_type = settings[1]["value_type"]
|
|
|
+ setting.name = settings[1]["name"]
|
|
|
+ setting.description = settings[1]["description"]
|
|
|
+ setting.extra = settings[1].get("extra", "")
|
|
|
+ setting.settingsgroup = group.key
|
|
|
+ else:
|
|
|
+ setting = Setting(
|
|
|
+ key=settings[0],
|
|
|
+ value=settings[1]["value"],
|
|
|
+ value_type=settings[1]["value_type"],
|
|
|
+ name=settings[1]["name"],
|
|
|
+ description=settings[1]["description"],
|
|
|
+ extra=settings[1].get("extra", ""),
|
|
|
+ settingsgroup=group.key
|
|
|
+ )
|
|
|
+
|
|
|
setting.save()
|
|
|
+
|
|
|
return groups_count, settings_count
|
|
|
|
|
|
|
|
|
def create_default_settings():
|
|
|
- """
|
|
|
- Creates the default settings
|
|
|
- """
|
|
|
+ """Creates the default settings."""
|
|
|
from flaskbb.fixtures.settings import fixture
|
|
|
create_settings_from_fixture(fixture)
|
|
|
|
|
|
|
|
|
def create_default_groups():
|
|
|
- """
|
|
|
- This will create the 5 default groups
|
|
|
- """
|
|
|
+ """This will create the 5 default groups."""
|
|
|
from flaskbb.fixtures.groups import fixture
|
|
|
result = []
|
|
|
for key, value in fixture.items():
|
|
@@ -120,9 +143,15 @@ def create_default_groups():
|
|
|
|
|
|
|
|
|
def create_admin_user(username, password, email):
|
|
|
+ """Creates the administrator user.
|
|
|
+
|
|
|
+ :param username: The username of the user.
|
|
|
+
|
|
|
+ :param password: The password of the user.
|
|
|
+
|
|
|
+ :param email: The email address of the user.
|
|
|
"""
|
|
|
- Creates the administrator user
|
|
|
- """
|
|
|
+
|
|
|
admin_group = Group.query.filter_by(admin=True).first()
|
|
|
user = User()
|
|
|
|
|
@@ -135,10 +164,8 @@ def create_admin_user(username, password, email):
|
|
|
|
|
|
|
|
|
def create_welcome_forum():
|
|
|
- """
|
|
|
- This will create the `welcome forum` that nearly every
|
|
|
- forum software has after the installation process is finished
|
|
|
- """
|
|
|
+ """This will create the `welcome forum` with a welcome topic."""
|
|
|
+
|
|
|
if User.query.count() < 1:
|
|
|
raise "You need to create the admin user first!"
|
|
|
|
|
@@ -158,9 +185,8 @@ def create_welcome_forum():
|
|
|
|
|
|
|
|
|
def create_test_data():
|
|
|
- """
|
|
|
- Creates 5 users, 2 categories and 2 forums in each category. It also opens
|
|
|
- a new topic topic in each forum with a post.
|
|
|
+ """Creates 5 users, 2 categories and 2 forums in each category.
|
|
|
+ It also creates a new topic topic in each forum with a post.
|
|
|
"""
|
|
|
create_default_groups()
|
|
|
create_default_settings()
|
|
@@ -208,8 +234,7 @@ def create_test_data():
|
|
|
|
|
|
|
|
|
def insert_mass_data(topics=100, posts=100):
|
|
|
- """
|
|
|
- Creates 100 topics in the first forum and each topic has 100 posts.
|
|
|
+ """Creates 100 topics in the first forum and each topic has 100 posts.
|
|
|
Returns ``True`` if the topics and posts were successfully created.
|
|
|
|
|
|
:param topics: The amount of topics in the forum.
|