use enums
This commit is contained in:
parent
e6986e3587
commit
435cddc4e4
3 changed files with 22 additions and 22 deletions
|
@ -1,10 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
import profig
|
import profig
|
||||||
|
|
||||||
|
|
||||||
class ConfigParameter:
|
class ConfigParameter(Enum):
|
||||||
DB_URL = "main.db_url"
|
DB_URL = "main.db_url"
|
||||||
DB_BACKUP_JSON_FILE = "main.db_backup_json_file"
|
DB_BACKUP_JSON_FILE = "main.db_backup_json_file"
|
||||||
LANG = "main.lang"
|
LANG = "main.lang"
|
||||||
|
@ -47,18 +48,18 @@ class Config:
|
||||||
config._params.update(cfg)
|
config._params.update(cfg)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def exists(self, key):
|
def exists(self, key: ConfigParameter):
|
||||||
return key in self._params
|
return key.value in self._params
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key: ConfigParameter):
|
||||||
return self._params[key] if key in self._params else None
|
return self._params[key.value] if key.value in self._params else None
|
||||||
|
|
||||||
def put(self, key, value):
|
def put(self, key: ConfigParameter, value):
|
||||||
self._params[key] = value
|
self._params[key.value] = value
|
||||||
|
|
||||||
def get_int(self, key):
|
def get_int(self, key: ConfigParameter):
|
||||||
return int(self._params[key])
|
return int(self._params[key.value])
|
||||||
|
|
||||||
def get_bool(self, key):
|
def get_bool(self, key: ConfigParameter):
|
||||||
return self._params[key].lower() in ("yes", "true")
|
return self._params[key.value].lower() in ("yes", "true")
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ class Database:
|
||||||
db.connect()
|
db.connect()
|
||||||
|
|
||||||
from stacosys.model.comment import Comment
|
from stacosys.model.comment import Comment
|
||||||
|
|
||||||
db.create_tables([Comment], safe=True)
|
db.create_tables([Comment], safe=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
|
||||||
class Templater:
|
class Template(Enum):
|
||||||
def __init__(self, template_path):
|
|
||||||
self._env = Environment(loader=FileSystemLoader(template_path))
|
|
||||||
|
|
||||||
def get_template(self, lang, name):
|
|
||||||
return self._env.get_template(lang + "/" + name + ".tpl")
|
|
||||||
|
|
||||||
|
|
||||||
class Template:
|
|
||||||
DROP_COMMENT = "drop_comment"
|
DROP_COMMENT = "drop_comment"
|
||||||
APPROVE_COMMENT = "approve_comment"
|
APPROVE_COMMENT = "approve_comment"
|
||||||
NEW_COMMENT = "new_comment"
|
NEW_COMMENT = "new_comment"
|
||||||
NOTIFY_MESSAGE = "notify_message"
|
NOTIFY_MESSAGE = "notify_message"
|
||||||
RSS_TITLE_MESSAGE = "rss_title_message"
|
RSS_TITLE_MESSAGE = "rss_title_message"
|
||||||
|
|
||||||
|
|
||||||
|
class Templater:
|
||||||
|
def __init__(self, template_path):
|
||||||
|
self._env = Environment(loader=FileSystemLoader(template_path))
|
||||||
|
|
||||||
|
def get_template(self, lang, template: Template):
|
||||||
|
return self._env.get_template(lang + "/" + template.value + ".tpl")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue