Skip to content

Commit

Permalink
Add new Config Parameter via cbpi api
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel83 authored and Manuel83 committed Jun 15, 2017
1 parent 37d8c7b commit c07e3f4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
8 changes: 8 additions & 0 deletions modules/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from time import localtime, strftime
from functools import wraps, update_wrapper


from props import *

from hardware import *
Expand Down Expand Up @@ -246,6 +248,12 @@ def get_config_parameter(self, key, default):
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] = []
Expand Down
37 changes: 27 additions & 10 deletions modules/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,35 @@ def delete(cls, id):
def insert(cls, **kwargs):
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 = ()
for f in cls.__fields__:
if f in cls.__json_fields__:
data = data + (json.dumps(kwargs.get(f)),)
else:
data = data + (kwargs.get(f),)
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__),
', '.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)
get_db().commit()
i = cur.lastrowid
Expand Down

0 comments on commit c07e3f4

Please sign in to comment.