summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frest/__init__.py4
-rw-r--r--frest/app.py57
-rw-r--r--frest/auth/__init__.py (renamed from src/frest/auth/__init__.py)0
-rw-r--r--frest/auth/forms.py (renamed from src/frest/auth/forms.py)0
-rw-r--r--frest/auth/models.py (renamed from src/frest/auth/models.py)0
-rw-r--r--frest/auth/routes.py (renamed from src/frest/auth/routes.py)2
-rw-r--r--frest/database.py (renamed from src/frest/database.py)0
-rw-r--r--frest/decorators.py (renamed from src/frest/decorators.py)0
-rw-r--r--frest/forms.py (renamed from src/frest/forms.py)0
-rw-r--r--frest/mail.py (renamed from src/frest/mail.py)0
-rw-r--r--frest/manage/__init__.py (renamed from src/frest/manage/__init__.py)0
-rw-r--r--frest/manage/bcolors.py (renamed from src/frest/manage/bcolors.py)0
-rw-r--r--frest/manage/utils.py (renamed from src/frest/manage/utils.py)8
-rw-r--r--frest/templates/form.txt (renamed from src/frest/templates/form.txt)0
-rw-r--r--frest/templates/models.txt (renamed from src/frest/templates/models.txt)0
-rw-r--r--frest/templates/routes.txt (renamed from src/frest/templates/routes.txt)0
-rw-r--r--frest/utils.py (renamed from src/frest/utils.py)2
-rw-r--r--frest/wsgi.py4
-rw-r--r--src/frest/manage.py23
19 files changed, 72 insertions, 28 deletions
diff --git a/frest/__init__.py b/frest/__init__.py
new file mode 100644
index 0000000..dda6153
--- /dev/null
+++ b/frest/__init__.py
@@ -0,0 +1,4 @@
+from .forms import *
+from .utils import *
+from .mail import *
+from .database import *
diff --git a/frest/app.py b/frest/app.py
new file mode 100644
index 0000000..ca46277
--- /dev/null
+++ b/frest/app.py
@@ -0,0 +1,57 @@
+from flask import Flask
+from auth.routes import api as api_users
+from flask import make_response, jsonify
+from database import db
+from database import config as db_config
+from mail import mail
+from mail import config as mail_config
+from flask_sqlalchemy import SQLAlchemy
+from utils import http_call
+from flask_cors import CORS
+import os
+
+app = Flask(__name__)
+app.config["SQLALCHEMY_DATABASE_URI"] = db_config["DATABASE_URI"]
+app.config["DEBUG"] = os.getenv("FREST_DEBUG", True)
+app.config["CORS_HEADERS"] = "Content-Type"
+app.config["MAIL_SERVER"] = mail_config["SERVER"]
+app.config["MAIL_PORT"] = mail_config["PORT"]
+app.config["MAIL_USE_TLS"] = mail_config["USE_TLS"]
+app.config["MAIL_USERNAME"] = mail_config["USERNAME"]
+app.config["MAIL_DEFAULT_SENDER"] = mail_config["DEFAULT_SENDER"]
+app.config["MAIL_PASSWORD"] = mail_config["PASSWORD"]
+
+cors = CORS(app, resources={r"/.*": {"origins": "*"}})
+db.app = app
+db.init_app(app)
+mail.init_app(app)
+app.register_blueprint(api_users)
+
+
+@app.errorhandler(404)
+def not_found(error):
+ return http_call("Not found", 404)
+
+
+@app.errorhandler(400)
+def bad_request(error):
+ return http_call("Bad request", 400)
+
+
+@app.errorhandler(405)
+def method_not_allowed(error):
+ return http_call("Method not allowed", 405)
+
+
+@app.errorhandler(403)
+def forbiddend(error):
+ return http_call("Forbidden", 403)
+
+
+@app.errorhandler(500)
+def internal(error):
+ return http_call("Internal error", 500)
+
+
+if __name__ == "__main__":
+ app.run(host="0.0.0.0", port=5000)
diff --git a/src/frest/auth/__init__.py b/frest/auth/__init__.py
index e69de29..e69de29 100644
--- a/src/frest/auth/__init__.py
+++ b/frest/auth/__init__.py
diff --git a/src/frest/auth/forms.py b/frest/auth/forms.py
index abc2f49..abc2f49 100644
--- a/src/frest/auth/forms.py
+++ b/frest/auth/forms.py
diff --git a/src/frest/auth/models.py b/frest/auth/models.py
index ea79def..ea79def 100644
--- a/src/frest/auth/models.py
+++ b/frest/auth/models.py
diff --git a/src/frest/auth/routes.py b/frest/auth/routes.py
index 66bd8f5..27f00ec 100644
--- a/src/frest/auth/routes.py
+++ b/frest/auth/routes.py
@@ -164,7 +164,7 @@ def edit_user(userId):
abort(400)
if form.get("password"):
- psw = True
+ psw = True
else:
psw = False
diff --git a/src/frest/database.py b/frest/database.py
index 176cd52..176cd52 100644
--- a/src/frest/database.py
+++ b/frest/database.py
diff --git a/src/frest/decorators.py b/frest/decorators.py
index 7ce79d7..7ce79d7 100644
--- a/src/frest/decorators.py
+++ b/frest/decorators.py
diff --git a/src/frest/forms.py b/frest/forms.py
index 8ce2e95..8ce2e95 100644
--- a/src/frest/forms.py
+++ b/frest/forms.py
diff --git a/src/frest/mail.py b/frest/mail.py
index e553525..e553525 100644
--- a/src/frest/mail.py
+++ b/frest/mail.py
diff --git a/src/frest/manage/__init__.py b/frest/manage/__init__.py
index e69de29..e69de29 100644
--- a/src/frest/manage/__init__.py
+++ b/frest/manage/__init__.py
diff --git a/src/frest/manage/bcolors.py b/frest/manage/bcolors.py
index eb8b803..eb8b803 100644
--- a/src/frest/manage/bcolors.py
+++ b/frest/manage/bcolors.py
diff --git a/src/frest/manage/utils.py b/frest/manage/utils.py
index f8e76d1..6634e05 100644
--- a/src/frest/manage/utils.py
+++ b/frest/manage/utils.py
@@ -1,8 +1,10 @@
import os
from .bcolors import COLORS
+import re
ENDC = len(COLORS) - 1
+TEMPLATE_PATH = os.path.join(frest.__path__[0], "templates")
def logging(text, _type=ENDC, end=""):
@@ -134,7 +136,7 @@ def create_model_cli(name):
"\t", " " * 4
)
- with open("templates/models.txt") as f:
+ with open(os.path.join(TEMPLATE_PATH, "models.txt")) as f:
modeltext = "".join(f.readlines())
modeltext = modeltext.replace("%%NAME%%", name.capitalize())
@@ -151,7 +153,7 @@ def create_model_cli(name):
def create_forms(name):
- with open("templates/form.txt") as f:
+ with open(os.path.join(TEMPLATE_PATH, "form.txt")) as f:
formstext = "".join(f.readlines())
formstext = formstext.replace("%%NAME%%", name.capitalize())
@@ -176,7 +178,7 @@ def create_routes(name, fields):
"'", '"'
).replace("\t", " " * 4)
- with open("templates/routes.txt") as f:
+ with open(os.path.join(TEMPLATE_PATH, "routes.txt")) as f:
routestext = "".join(f.readlines())
routestext = routestext.replace("%%NAME%%", name.capitalize())
diff --git a/src/frest/templates/form.txt b/frest/templates/form.txt
index ed1017e..ed1017e 100644
--- a/src/frest/templates/form.txt
+++ b/frest/templates/form.txt
diff --git a/src/frest/templates/models.txt b/frest/templates/models.txt
index af80963..af80963 100644
--- a/src/frest/templates/models.txt
+++ b/frest/templates/models.txt
diff --git a/src/frest/templates/routes.txt b/frest/templates/routes.txt
index 11ba63a..11ba63a 100644
--- a/src/frest/templates/routes.txt
+++ b/frest/templates/routes.txt
diff --git a/src/frest/utils.py b/frest/utils.py
index 934aec4..ef673a7 100644
--- a/src/frest/utils.py
+++ b/frest/utils.py
@@ -1,6 +1,6 @@
from flask import make_response, jsonify, request, render_template
from flask_mail import Message
-from mail import mail
+from frest.mail import mail
from datetime import datetime
import os
diff --git a/frest/wsgi.py b/frest/wsgi.py
new file mode 100644
index 0000000..6026b0f
--- /dev/null
+++ b/frest/wsgi.py
@@ -0,0 +1,4 @@
+from app import app
+
+if __name__ == "__main__":
+ app.run()
diff --git a/src/frest/manage.py b/src/frest/manage.py
deleted file mode 100644
index 1164d70..0000000
--- a/src/frest/manage.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import argparse
-from manage.utils import logo, create_app
-from manage.utils import logging, logging_arg
-import os
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--startapp", "-s", type=str, help="create new app")
- args = parser.parse_args()
-
- if args.startapp:
- if not os.path.exists("scheme"):
- logging_arg("Create {}... ", "scheme/")
- logging("OK", 3, "\n")
- os.mkdir("scheme")
-
- create_app(args.startapp)
-
-
-if __name__ == "__main__":
- logo()
- main()