mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
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:
22
manage.py
22
manage.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user