Better constant value management (#1335)

* Starts work on #929 
* Adds Enum classes that can be accessed from JS, Jinja, and Python code. This allows for the sharing of constant values between the three major codebases in CTFd.
This commit is contained in:
Kevin Chung
2020-04-23 10:48:09 -04:00
committed by GitHub
parent fa434c4bdd
commit 1f87efb6c1
3 changed files with 137 additions and 0 deletions

View File

@@ -12,6 +12,21 @@ manager = Manager(app)
manager.add_command("db", MigrateCommand)
def jsenums():
from CTFd.constants import JS_ENUMS
import json
import os
path = os.path.join(app.root_path, "themes/core/assets/js/constants.js")
with open(path, "w+") as f:
for k, v in JS_ENUMS.items():
f.write("const {} = Object.freeze({});".format(k, json.dumps(v)))
BUILD_COMMANDS = {"jsenums": jsenums}
@manager.command
def get_config(key):
with app.app_context():
@@ -24,5 +39,12 @@ def set_config(key, value):
print(set_config_util(key, value).value)
@manager.command
def build(cmd):
with app.app_context():
cmd = BUILD_COMMANDS.get(cmd)
cmd()
if __name__ == "__main__":
manager.run()