mirror of
https://github.com/Manuel83/craftbeerpi3
synced 2026-08-09 18:52:40 +02:00
Add new Config Parameter via cbpi api
This commit is contained in:
@@ -9,6 +9,8 @@ from flask_classy import FlaskView, route
|
||||
|
||||
from time import localtime, strftime
|
||||
from functools import wraps, update_wrapper
|
||||
|
||||
|
||||
from props import *
|
||||
|
||||
from hardware import *
|
||||
@@ -246,6 +248,12 @@ class CraftBeerPi(ActorAPI, SensorAPI):
|
||||
else:
|
||||
return cfg.value
|
||||
|
||||
def add_config_parameter(self, name, value, type, description, options=None):
|
||||
from modules.config import Config
|
||||
with self.app.app_context():
|
||||
Config.insert(**{"name":name, "value": value, "type": type, "description": description, "options": options})
|
||||
|
||||
|
||||
def clear_cache(self, key, is_array=False):
|
||||
if is_array:
|
||||
self.cache[key] = []
|
||||
|
||||
@@ -76,6 +76,22 @@ class DBModel(object):
|
||||
def insert(cls, **kwargs):
|
||||
cur = get_db().cursor()
|
||||
|
||||
|
||||
if cls.__priamry_key__ is not None and kwargs.has_key(cls.__priamry_key__):
|
||||
query = "INSERT INTO %s (%s, %s) VALUES (?, %s)" % (
|
||||
cls.__table_name__,
|
||||
cls.__priamry_key__,
|
||||
', '.join("'%s'" % str(x) for x in cls.__fields__),
|
||||
', '.join(['?'] * len(cls.__fields__)))
|
||||
data = ()
|
||||
data = data + (kwargs.get(cls.__priamry_key__),)
|
||||
for f in cls.__fields__:
|
||||
if f in cls.__json_fields__:
|
||||
data = data + (json.dumps(kwargs.get(f)),)
|
||||
else:
|
||||
data = data + (kwargs.get(f),)
|
||||
else:
|
||||
|
||||
query = 'INSERT INTO %s (%s) VALUES (%s)' % (
|
||||
cls.__table_name__,
|
||||
', '.join("'%s'" % str(x) for x in cls.__fields__),
|
||||
@@ -88,6 +104,7 @@ class DBModel(object):
|
||||
else:
|
||||
data = data + (kwargs.get(f),)
|
||||
|
||||
print query, data
|
||||
cur.execute(query, data)
|
||||
get_db().commit()
|
||||
i = cur.lastrowid
|
||||
|
||||
Reference in New Issue
Block a user