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 time import localtime, strftime
|
||||||
from functools import wraps, update_wrapper
|
from functools import wraps, update_wrapper
|
||||||
|
|
||||||
|
|
||||||
from props import *
|
from props import *
|
||||||
|
|
||||||
from hardware import *
|
from hardware import *
|
||||||
@@ -246,6 +248,12 @@ class CraftBeerPi(ActorAPI, SensorAPI):
|
|||||||
else:
|
else:
|
||||||
return cfg.value
|
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):
|
def clear_cache(self, key, is_array=False):
|
||||||
if is_array:
|
if is_array:
|
||||||
self.cache[key] = []
|
self.cache[key] = []
|
||||||
|
|||||||
+27
-10
@@ -76,18 +76,35 @@ class DBModel(object):
|
|||||||
def insert(cls, **kwargs):
|
def insert(cls, **kwargs):
|
||||||
cur = get_db().cursor()
|
cur = get_db().cursor()
|
||||||
|
|
||||||
query = 'INSERT INTO %s (%s) VALUES (%s)' % (
|
|
||||||
cls.__table_name__,
|
|
||||||
', '.join("'%s'" % str(x) for x in cls.__fields__),
|
|
||||||
', '.join(['?'] * len(cls.__fields__)))
|
|
||||||
|
|
||||||
data = ()
|
if cls.__priamry_key__ is not None and kwargs.has_key(cls.__priamry_key__):
|
||||||
for f in cls.__fields__:
|
query = "INSERT INTO %s (%s, %s) VALUES (?, %s)" % (
|
||||||
if f in cls.__json_fields__:
|
cls.__table_name__,
|
||||||
data = data + (json.dumps(kwargs.get(f)),)
|
cls.__priamry_key__,
|
||||||
else:
|
', '.join("'%s'" % str(x) for x in cls.__fields__),
|
||||||
data = data + (kwargs.get(f),)
|
', '.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__),
|
||||||
|
', '.join(['?'] * len(cls.__fields__)))
|
||||||
|
|
||||||
|
data = ()
|
||||||
|
for f in cls.__fields__:
|
||||||
|
if f in cls.__json_fields__:
|
||||||
|
data = data + (json.dumps(kwargs.get(f)),)
|
||||||
|
else:
|
||||||
|
data = data + (kwargs.get(f),)
|
||||||
|
|
||||||
|
print query, data
|
||||||
cur.execute(query, data)
|
cur.execute(query, data)
|
||||||
get_db().commit()
|
get_db().commit()
|
||||||
i = cur.lastrowid
|
i = cur.lastrowid
|
||||||
|
|||||||
Reference in New Issue
Block a user