refactor templates

This commit is contained in:
null 2024-03-08 23:29:52 +01:00
parent 5323204789
commit ae707720bc
5 changed files with 8 additions and 4 deletions

View File

@ -17,6 +17,10 @@ class Strategy():
def get_route_prefix(cls): def get_route_prefix(cls):
return "/strategies/" + cls.__name__.lower() return "/strategies/" + cls.__name__.lower()
@classmethod
def get_template_prefix(cls):
return "/strategies"
@staticmethod @staticmethod
def get_computed_properties(): def get_computed_properties():
return ["id", "createdAt"] return ["id", "createdAt"]

View File

@ -1,7 +1,7 @@
from db import get_connection, getRethinkDB from db import get_connection, getRethinkDB
from dataclasses import fields from dataclasses import fields
from typing import List, Type from typing import List, Type
from flask import jsonify, request, redirect, render_template from flask import request, render_template
r = getRethinkDB() r = getRethinkDB()
def get_bool_attribute_names(cls: Type) -> List[str]: def get_bool_attribute_names(cls: Type) -> List[str]:
@ -21,7 +21,7 @@ def create_routes(cls, app):
cursor = r.table(table_name).run(get_connection()) cursor = r.table(table_name).run(get_connection())
fields = list(cursor) fields = list(cursor)
return render_template(cls.get_route_prefix() + "/index.html", data={ return render_template(cls.get_template_prefix() + "/index.html", data={
"title": cls.__name__, "title": cls.__name__,
"fields": [cls.format(field) for field in fields], "fields": [cls.format(field) for field in fields],
"prefix": cls.get_route_prefix(), "prefix": cls.get_route_prefix(),
@ -31,7 +31,7 @@ def create_routes(cls, app):
@app.route(cls.get_route_prefix() + "/create", methods=['GET']) @app.route(cls.get_route_prefix() + "/create", methods=['GET'])
def get_create(): def get_create():
return render_template(cls.get_route_prefix() + "/create.html", data={ return render_template(cls.get_template_prefix() + "/create.html", data={
"name": cls.__name__, "name": cls.__name__,
"prefix": cls.get_route_prefix(), "prefix": cls.get_route_prefix(),
"computed": cls.get_computed_properties(), "computed": cls.get_computed_properties(),
@ -55,7 +55,7 @@ def create_routes(cls, app):
def get_update(id): def get_update(id):
cursor = r.table(table_name).get(id).run(get_connection()) cursor = r.table(table_name).get(id).run(get_connection())
return render_template(cls.get_route_prefix() + "/update.html", data={ return render_template(cls.get_template_prefix() + "/update.html", data={
"name": cls.__name__, "name": cls.__name__,
"field": cursor, "field": cursor,
"fields": {field.name: field.type.__name__ for field in fields(cls)}, "fields": {field.name: field.type.__name__ for field in fields(cls)},