コード例 #1
0
ファイル: configuration.py プロジェクト: Simple2B/shopify.app
    def set_common_value(name: str, value):
        value_type = "str"
        if isinstance(value, bool):
            value_type = "bool"
        elif isinstance(value, float):
            value_type = "float"
        elif isinstance(value, int):
            value_type = "int"
        elif isinstance(value, datetime):
            value_type = "datetime"
            value = value.isoformat()

        conf = (
            Configuration.query.filter(
                Configuration.shop_id == None)  # noqa E711
            .filter(Configuration.name == name).first())
        if conf:
            if Configuration.get_typed_value(conf.value,
                                             conf.value_type) != value:
                conf.value = str(value)
                conf.value_type = value_type
                conf.save()
        else:
            Configuration(
                name=name,
                value=str(value),
                value_type=value_type,
            ).save()
コード例 #2
0
ファイル: configuration.py プロジェクト: Simple2B/shopify.app
    def set_value(shop_id: int, name: str, value, path="/"):
        value_type = "str"
        if isinstance(value, bool):
            value_type = "bool"
        elif isinstance(value, float):
            value_type = "float"
        elif isinstance(value, int):
            value_type = "int"

        conf = (Configuration.query.filter(
            Configuration.shop_id == shop_id).filter(
                Configuration.name == name).filter(
                    Configuration.path == path).first())
        if conf:
            if Configuration.get_typed_value(conf.value,
                                             conf.value_type) != value:
                conf.value = str(value)
                conf.value_type = value_type
                conf.save()
        else:
            Configuration(
                shop_id=shop_id,
                name=name,
                value=str(value),
                value_type=value_type,
                path=path,
            ).save()