]> git.ipfire.org Git - ipfire.org.git/blob - www/webapp/datastore/config.py
Create a global webapp database connection and create a config class.
[ipfire.org.git] / www / webapp / datastore / config.py
1 #/usr/bin/python
2
3 class Config(object):
4 def __init__(self, application):
5 self.application = application
6
7 @property
8 def db(self):
9 return self.application.db.config
10
11 def delete(self, key):
12 self.db.execute("DELETE FROM settings WHERE key = %s", key)
13
14 def get(self, key, default=None):
15 return self.db.get("SELECT key FROM settings WHERE key = %s", key) or default
16
17 def set(self, key, value):
18 self.delete(key)
19 self.db.execute("INSERT INTO settings(key, value) VALUES(%s, %s)", key, value)