From d880d90e6d6d0cade731ae43ab40934928c20ba4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 20 Mar 2020 12:15:21 +0100 Subject: chore: rename templates in txt --- src/frest/templates/form.rst | 10 ----- src/frest/templates/form.txt | 10 +++++ src/frest/templates/models.rst | 26 ------------- src/frest/templates/models.txt | 26 +++++++++++++ src/frest/templates/route.rst | 88 ------------------------------------------ src/frest/templates/routes.txt | 88 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 124 deletions(-) delete mode 100644 src/frest/templates/form.rst create mode 100644 src/frest/templates/form.txt delete mode 100644 src/frest/templates/models.rst create mode 100644 src/frest/templates/models.txt delete mode 100644 src/frest/templates/route.rst create mode 100644 src/frest/templates/routes.txt (limited to 'src') diff --git a/src/frest/templates/form.rst b/src/frest/templates/form.rst deleted file mode 100644 index f4b2c14..0000000 --- a/src/frest/templates/form.rst +++ /dev/null @@ -1,10 +0,0 @@ -from .models import %%NAME%% -from src.forms import ModelForm - - -class %%NAME%%Form(ModelForm): - model = %%NAME%% - - def __init__(self, data): - super().__init__(self.model) - self.data = data diff --git a/src/frest/templates/form.txt b/src/frest/templates/form.txt new file mode 100644 index 0000000..f4b2c14 --- /dev/null +++ b/src/frest/templates/form.txt @@ -0,0 +1,10 @@ +from .models import %%NAME%% +from src.forms import ModelForm + + +class %%NAME%%Form(ModelForm): + model = %%NAME%% + + def __init__(self, data): + super().__init__(self.model) + self.data = data diff --git a/src/frest/templates/models.rst b/src/frest/templates/models.rst deleted file mode 100644 index af80963..0000000 --- a/src/frest/templates/models.rst +++ /dev/null @@ -1,26 +0,0 @@ -from database import db -from datetime import datetime -from pytz import timezone -import os - - -class %%NAME%%(db.Model): - %%name%%Id = db.Column(db.Integer, primary_key=True) - %%params_model%% - created_at = db.Column(db.DateTime) - updated_at = db.Column(db.DateTime) - - def __init__(self, **kwargs): - %%params_model_init%% - self.created_at = datetime.now( - timezone(os.getenv("FREST_TIMEZONE", "Europe/Rome")) - ) - self.updated_at = datetime.now( - timezone(os.getenv("FREST_TIMEZONE", "Europe/Rome")) - ) - - def __repr__(self): - return f"<%%NAME%% '{self.%%name%%Id}'>" - - def __str__(self): - return f"{self.%%name%%Id}" diff --git a/src/frest/templates/models.txt b/src/frest/templates/models.txt new file mode 100644 index 0000000..af80963 --- /dev/null +++ b/src/frest/templates/models.txt @@ -0,0 +1,26 @@ +from database import db +from datetime import datetime +from pytz import timezone +import os + + +class %%NAME%%(db.Model): + %%name%%Id = db.Column(db.Integer, primary_key=True) + %%params_model%% + created_at = db.Column(db.DateTime) + updated_at = db.Column(db.DateTime) + + def __init__(self, **kwargs): + %%params_model_init%% + self.created_at = datetime.now( + timezone(os.getenv("FREST_TIMEZONE", "Europe/Rome")) + ) + self.updated_at = datetime.now( + timezone(os.getenv("FREST_TIMEZONE", "Europe/Rome")) + ) + + def __repr__(self): + return f"<%%NAME%% '{self.%%name%%Id}'>" + + def __str__(self): + return f"{self.%%name%%Id}" diff --git a/src/frest/templates/route.rst b/src/frest/templates/route.rst deleted file mode 100644 index a24a3b1..0000000 --- a/src/frest/templates/route.rst +++ /dev/null @@ -1,88 +0,0 @@ -from flask import Blueprint, request, abort -from fapi.utils import http_call, model_serialize -from fapi.decorators import check_token, admin_required -from .models import %%NAME%% -from .forms import %%NAME%%Form -from database import db -import json -from datetime import datetime -from pytz import timezone - -api = Blueprint("%%name%%s", __name__) - - -@api.route("/api/%%name%%") -def all_%%name%%s(): - return http_call( - [ - model_serialize(i, params="%%params%%") - for i in %%NAME%%.query.all() - ], - 200, - ) - - -@api.route("/api/%%name%%/<%%name%%Id>") -def get_%%name%%(%%name%%Id): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() - if not %%first_char%%: - abort(404) - - return http_call(model_serialize(%%first_char%%, params="%%params%%"), 200) - - -@api.route("/api/%%name%%/<%%name%%Id>", methods=["DELETE"]) -@check_token -def delete_%%name%%(%%name%%Id): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id) - if not %%first_char%%: - abort(404) - - deleted = %%first_char%%.delete() - db.session.commit() - - return http_call({"delete": deleted}, 200) - - -@api.route("/api/%%name%%", methods=["POST"]) -@check_token -def new_%%name%%(): - if not request.json: - abort(400) - - form = %%NAME%%Form(request.json) - - if form.is_valid(): - %%first_char%% = %%NAME%%( - %%params_form%% - ) - db.session.add(%%first_char%%) - - db.session.commit() - - return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 201) - - abort(400) - - -@api.route("/api/%%name%%/<%%name%%Id>", methods=["PUT"]) -@check_token -def edit_%%name%%(%%name%%Id): - if not request.json: - abort(400) - - form = %%NAME%%Form(request.json) - - if form.is_valid(): - %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() - if not %%first_char%%: - abort(404) - - %%params_put%% - %%first_char%%.updated_at = datetime.now(timezone("Europe/Rome")) - - db.session.commit() - - return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 200) - - abort(400) diff --git a/src/frest/templates/routes.txt b/src/frest/templates/routes.txt new file mode 100644 index 0000000..a24a3b1 --- /dev/null +++ b/src/frest/templates/routes.txt @@ -0,0 +1,88 @@ +from flask import Blueprint, request, abort +from fapi.utils import http_call, model_serialize +from fapi.decorators import check_token, admin_required +from .models import %%NAME%% +from .forms import %%NAME%%Form +from database import db +import json +from datetime import datetime +from pytz import timezone + +api = Blueprint("%%name%%s", __name__) + + +@api.route("/api/%%name%%") +def all_%%name%%s(): + return http_call( + [ + model_serialize(i, params="%%params%%") + for i in %%NAME%%.query.all() + ], + 200, + ) + + +@api.route("/api/%%name%%/<%%name%%Id>") +def get_%%name%%(%%name%%Id): + %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() + if not %%first_char%%: + abort(404) + + return http_call(model_serialize(%%first_char%%, params="%%params%%"), 200) + + +@api.route("/api/%%name%%/<%%name%%Id>", methods=["DELETE"]) +@check_token +def delete_%%name%%(%%name%%Id): + %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id) + if not %%first_char%%: + abort(404) + + deleted = %%first_char%%.delete() + db.session.commit() + + return http_call({"delete": deleted}, 200) + + +@api.route("/api/%%name%%", methods=["POST"]) +@check_token +def new_%%name%%(): + if not request.json: + abort(400) + + form = %%NAME%%Form(request.json) + + if form.is_valid(): + %%first_char%% = %%NAME%%( + %%params_form%% + ) + db.session.add(%%first_char%%) + + db.session.commit() + + return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 201) + + abort(400) + + +@api.route("/api/%%name%%/<%%name%%Id>", methods=["PUT"]) +@check_token +def edit_%%name%%(%%name%%Id): + if not request.json: + abort(400) + + form = %%NAME%%Form(request.json) + + if form.is_valid(): + %%first_char%% = %%NAME%%.query.filter_by(%%name%%Id=%%name%%Id).first() + if not %%first_char%%: + abort(404) + + %%params_put%% + %%first_char%%.updated_at = datetime.now(timezone("Europe/Rome")) + + db.session.commit() + + return http_call({"%%name%%Id": %%first_char%%.%%name%%Id}, 200) + + abort(400) -- cgit v1.2.3-18-g5258