From 8ee07ec9edfb0c84b0643fcad707d13e153e7e69 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Thu, 14 Jan 2021 18:45:06 +0100 Subject: [PATCH] use enums --- stacosys/conf/config.py | 23 ++++++++++++----------- stacosys/core/database.py | 1 - stacosys/core/templater.py | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/stacosys/conf/config.py b/stacosys/conf/config.py index bb2316e..5962f4c 100644 --- a/stacosys/conf/config.py +++ b/stacosys/conf/config.py @@ -1,10 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from enum import Enum import profig -class ConfigParameter: +class ConfigParameter(Enum): DB_URL = "main.db_url" DB_BACKUP_JSON_FILE = "main.db_backup_json_file" LANG = "main.lang" @@ -47,18 +48,18 @@ class Config: config._params.update(cfg) return config - def exists(self, key): - return key in self._params + def exists(self, key: ConfigParameter): + return key.value in self._params - def get(self, key): - return self._params[key] if key in self._params else None + def get(self, key: ConfigParameter): + return self._params[key.value] if key.value in self._params else None - def put(self, key, value): - self._params[key] = value + def put(self, key: ConfigParameter, value): + self._params[key.value] = value - def get_int(self, key): - return int(self._params[key]) + def get_int(self, key: ConfigParameter): + return int(self._params[key.value]) - def get_bool(self, key): - return self._params[key].lower() in ("yes", "true") + def get_bool(self, key: ConfigParameter): + return self._params[key.value].lower() in ("yes", "true") diff --git a/stacosys/core/database.py b/stacosys/core/database.py index bac46e1..1de6db4 100644 --- a/stacosys/core/database.py +++ b/stacosys/core/database.py @@ -25,7 +25,6 @@ class Database: db.connect() from stacosys.model.comment import Comment - db.create_tables([Comment], safe=True) diff --git a/stacosys/core/templater.py b/stacosys/core/templater.py index 025645b..d3d4564 100644 --- a/stacosys/core/templater.py +++ b/stacosys/core/templater.py @@ -1,22 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - +from enum import Enum from jinja2 import Environment, FileSystemLoader -class Templater: - 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: +class Template(Enum): DROP_COMMENT = "drop_comment" APPROVE_COMMENT = "approve_comment" NEW_COMMENT = "new_comment" NOTIFY_MESSAGE = "notify_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") +