Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/thisdb/option.py

58 lines
1.9 KiB

6 months ago
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
6 months ago
import os
import json
6 months ago
import core.mw as mw
5 months ago
def getOption(name,type='common',default=None) -> str:
6 months ago
'''
获取配置的值
:name -> str 名称 (必填)
:type -> str 类型 (可选|默认common)
:default -> str 默认值 (可选)
'''
data = mw.M('option').field('name').where('name=? and type=?',(name, type,)).getField('value')
6 months ago
if data is None:
6 months ago
return default
6 months ago
return data
5 months ago
def getOptionByJson(name,type='common',default=None) -> object:
6 months ago
'''
获取配置的值,返回对象类型
:name -> str 名称 (必填)
:type -> str 类型 (可选|默认common)
:default -> str 默认值 (可选)
'''
data = mw.M('option').field('name').where('name=? and type=?',(name, type,)).getField('value')
6 months ago
if data is None:
6 months ago
return default
if data is not None:
return json.loads(data)
5 months ago
def setOption(name, value, type = 'common') -> bool:
6 months ago
'''
设置配置的值
:name -> str 名称 (必填)
:value -> object值 (必填)
:type -> str 类型 (可选|默认common)
'''
6 months ago
data = mw.M('option').field('name,type,value').where('name=? and type=?',(name, type,)).find()
if data is not None:
mw.M('option').field('name').where('name=? and type=?',(name, type,)).setField('value', value)
return True
add_option = {
'name':name,
'type':type,
'value':value
}
6 months ago
return mw.M('option').insert(add_option)