当前位置: 首页>>代码示例>>Python>>正文


Python Setting.save方法代码示例

本文整理汇总了Python中flaskbb.management.models.Setting.save方法的典型用法代码示例。如果您正苦于以下问题:Python Setting.save方法的具体用法?Python Setting.save怎么用?Python Setting.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flaskbb.management.models.Setting的用法示例。


在下文中一共展示了Setting.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_settings_from_fixture

# 需要导入模块: from flaskbb.management.models import Setting [as 别名]
# 或者: from flaskbb.management.models.Setting import save [as 别名]
def create_settings_from_fixture(fixture):
    """
    Inserts the settings from a fixture into the database.
    """
    for settingsgroup in fixture:
        group = SettingsGroup(
            key=settingsgroup[0],
            name=settingsgroup[1]['name'],
            description=settingsgroup[1]['description']
        )

        group.save()

        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

                settingsgroup=group.key
            )
            setting.save()
开发者ID:aregsar,项目名称:flaskbb,代码行数:27,代码来源:populate.py

示例2: create_settings_from_fixture

# 需要导入模块: from flaskbb.management.models import Setting [as 别名]
# 或者: from flaskbb.management.models.Setting import save [as 别名]
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"]:
            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

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

    return created_settings
开发者ID:djsilcock,项目名称:flaskbb,代码行数:34,代码来源:populate.py

示例3: update_settings_from_fixture

# 需要导入模块: from flaskbb.management.models import Setting [as 别名]
# 或者: from flaskbb.management.models.Setting import save [as 别名]
def update_settings_from_fixture(fixture, overwrite_group=False,
                                 overwrite_setting=False):
    """
    Updates the database settings from a fixture.
    Returns the number of updated groups and settings.
    """
    groups_count = 0
    settings_count = 0
    for settingsgroup in fixture:

        group = SettingsGroup.query.filter_by(key=settingsgroup[0]).first()

        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']
            )

            group.save()

        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:
                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
                )
                setting.save()
    return groups_count, settings_count
开发者ID:centime,项目名称:xss-paper,代码行数:41,代码来源:populate.py

示例4: update_settings_from_fixture

# 需要导入模块: from flaskbb.management.models import Setting [as 别名]
# 或者: from flaskbb.management.models.Setting import save [as 别名]
def update_settings_from_fixture(fixture, overwrite_group=False,
                                 overwrite_setting=False):
    """Updates the database settings from a fixture.
    Returns the 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``.
    """
    updated_settings = {}

    for settingsgroup in fixture:

        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:
                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"]:

            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:
                    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()
                updated_settings[group] = []
                updated_settings[group].append(setting)
    return updated_settings
开发者ID:djsilcock,项目名称:flaskbb,代码行数:63,代码来源:populate.py


注:本文中的flaskbb.management.models.Setting.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。