diff --git a/myte/templates/template-flask-restful-api-moderate/.gitignore b/myte/templates/template-flask-restful-api-moderate/.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/myte/templates/template-flask-restful-api-moderate/README.md b/myte/templates/template-flask-restful-api-moderate/README.md new file mode 100644 index 0000000..7dbb95a --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/README.md @@ -0,0 +1,7 @@ +# myte_simple_flask_restful_api_template + +## Features + +## Contribution + +## Contact diff --git a/myte/templates/template-flask-restful-api-moderate/api/config.py b/myte/templates/template-flask-restful-api-moderate/api/config.py new file mode 100644 index 0000000..2ff999e --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/config.py @@ -0,0 +1,44 @@ +# config.py + +""" +This module defines... +""" + +# imports + +import os + +from dotenv import load_dotenv + +# configurations + +load_dotenv() + +DATABASE_USERNAME = os.getenv('DATABASE_USERNAME') +DATABASE_PASSWORD = os.getenv('DATABASE_PASSWORD') +DATABASE_HOST = os.getenv('DATABASE_HOST') +DATABASE_PORT = os.getenv('DATABASE_PORT') +DATABASE_NAME = os.getenv('DATABASE_NAME') + +DEBUG = True + +# databases +# delete any database you don't want to use + +# postgreSQL - default (pip install psycopg2 (windows users) or psycopg2-binary (linux and mac users)) # noqa + +SQLALCHEMY_DATABASE_URI = f'postgresql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa + +# # mySQL (pip install mysql-connector-python) +# uncomment line 35 to use MySQL DB and comment line 30 + +# SQLALCHEMY_DATABASE_URI = f'mysql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa + +# # SQLite (goto https://www.sqlite.org/download.html, download and install, if you've not) # noqa +# uncomment line 40 to use SQLite DB and comment line 30 + +SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_NAME}.db' + +SQLALCHEMY_TRACK_MODIFICATIONS = False + +SECRET_KEY = os.getenv('SECRETKEY') diff --git a/myte/templates/template-flask-restful-api-moderate/api/models/__init__.py b/myte/templates/template-flask-restful-api-moderate/api/models/__init__.py new file mode 100644 index 0000000..6083a46 --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/models/__init__.py @@ -0,0 +1,8 @@ +# imports +from flask_sqlalchemy import SQLAlchemy + +# configurations +db = SQLAlchemy() + +from .todo import Todo +from .todo_item import TodoItem \ No newline at end of file diff --git a/myte/templates/template-flask-restful-api-moderate/api/models/todo.py b/myte/templates/template-flask-restful-api-moderate/api/models/todo.py new file mode 100644 index 0000000..51fdd29 --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/models/todo.py @@ -0,0 +1,36 @@ +# todo.py + +""" +The model ... +""" + +# imports + +from datetime import datetime + +from . import db + +# pylint: disable=R0903 + + +class Todo(db.Model): + + """ + todo model class representing .... + """ + + __tablename__ = "todos" + + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(), nullable=False) + description = db.Column(db.String(), nullable=True) + status = db.Column(db.Boolean(), nullable=False) + + created_at = db.Column(db.DateTime(), default=datetime.utcnow) + updated_at = db.Column( + db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow, + nullable=True) + + # relationships + + todo_item = db.relationship("TodoItem", backref="todos", lazy=True) diff --git a/myte/templates/template-flask-restful-api-moderate/api/models/todo_item.py b/myte/templates/template-flask-restful-api-moderate/api/models/todo_item.py new file mode 100644 index 0000000..fbb66e2 --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/models/todo_item.py @@ -0,0 +1,37 @@ +# todo_item.py + +""" +The model ... +""" + +# imports + +from datetime import datetime + +from . import db + +# pylint: disable=R0903 + + +class TodoItem(db.Model): + + """ + todo item model class representing .... + """ + + __tablename__ = "todo_items" + + id = db.Column(db.Integer, primary_key=True) + task = db.Column(db.String(), nullable=False) + description = db.Column(db.String(), nullable=True) + status = db.Column(db.Boolean(), nullable=False) + + created_at = db.Column(db.DateTime(), default=datetime.utcnow) + updated_at = db.Column( + db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow, + nullable=True) + + # foreign keys + + todo_id = db.Column(db.Integer, db.ForeignKey( + 'todos.id'), nullable=False) diff --git a/myte/templates/template-flask-restful-api-moderate/api/resources/__init__.py b/myte/templates/template-flask-restful-api-moderate/api/resources/__init__.py new file mode 100644 index 0000000..788eba4 --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/resources/__init__.py @@ -0,0 +1,3 @@ +from .index import Index +from .todo import Todo +from .todo_item import TodoItem diff --git a/myte/templates/template-flask-restful-api-moderate/api/resources/index.py b/myte/templates/template-flask-restful-api-moderate/api/resources/index.py new file mode 100644 index 0000000..ad2777b --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/resources/index.py @@ -0,0 +1,15 @@ +# index.py +""" +The module defines .... +""" + +from flask_restful import Resource + + +class Index(Resource): + """ This class defines... """ + + def get(self): + """ This function defines... """ + + return {'hello': 'world'} diff --git a/myte/templates/template-flask-restful-api-moderate/api/resources/todo.py b/myte/templates/template-flask-restful-api-moderate/api/resources/todo.py new file mode 100644 index 0000000..4a24754 --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/resources/todo.py @@ -0,0 +1,35 @@ +# todo.py +""" +The module defines .... +""" + +from flask_restful import Resource + + +class Todo(Resource): + """ This class defines... """ + + def create(self): + """ This function defines... """ + + return + + def view_all(self): + """ This function defines... """ + + return + + def view_one(self, id): + """ This function defines... """ + + return + + def update(self, id): + """ This function defines... """ + + return + + def delete(self, id): + """ This function defines... """ + + return diff --git a/myte/templates/template-flask-restful-api-moderate/api/resources/todo_item.py b/myte/templates/template-flask-restful-api-moderate/api/resources/todo_item.py new file mode 100644 index 0000000..a60efde --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/resources/todo_item.py @@ -0,0 +1,35 @@ +# todo_item.py +""" +The module defines .... +""" + +from flask_restful import Resource + + +class TodoItem(Resource): + """ This class defines... """ + + def create(self): + """ This function defines... """ + + return + + def view_all(self): + """ This function defines... """ + + return + + def view_one(self, id): + """ This function defines... """ + + return + + def update(self, id): + """ This function defines... """ + + return + + def delete(self, id): + """ This function defines... """ + + return diff --git a/myte/templates/template-flask-restful-api-moderate/api/routes/index.py b/myte/templates/template-flask-restful-api-moderate/api/routes/index.py new file mode 100644 index 0000000..e69de29 diff --git a/myte/templates/template-flask-restful-api-moderate/api/server.py b/myte/templates/template-flask-restful-api-moderate/api/server.py new file mode 100644 index 0000000..19b4d4e --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/api/server.py @@ -0,0 +1,41 @@ +# app.py + +""" +This module defines... +""" + +# imports + +from flask import Flask +from flask_migrate import Migrate +from flask_restful import Api + +import config +from models import db +from resources import Index, Todo + +# configurations + +server = Flask(__name__) + +server.debug = config.DEBUG +server.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI +server.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS # noqa +server.config['SECRET_KEY'] = config.SECRET_KEY + +db.init_app(server) +db.server = server +migrate = Migrate(server, db) +api = Api(server) + +# routes + +api.add_resource(Index, '/') +api.add_resource(Todo, '/todo/', '/todo//') + +# entrypoint + + +if __name__ == "__main__": + server.debug = config.DEBUG + server.run() diff --git a/myte/templates/template-flask-restful-api-moderate/example.env b/myte/templates/template-flask-restful-api-moderate/example.env new file mode 100644 index 0000000..2e2465f --- /dev/null +++ b/myte/templates/template-flask-restful-api-moderate/example.env @@ -0,0 +1,9 @@ +# database +DATABASE_USERNAME = '' +DATABASE_PASSWORD = '' +DATABASE_HOST = '' +DATABASE_PORT = 5432 +DATABASE_NAME = '' + +# security +SECRETKEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' diff --git a/myte/templates/template-flask-robust/src/config.py b/myte/templates/template-flask-robust/src/config.py index 8965f1c..baa7d8b 100644 --- a/myte/templates/template-flask-robust/src/config.py +++ b/myte/templates/template-flask-robust/src/config.py @@ -1,3 +1,5 @@ +# config.py + """ This module define all important variables, connection to DB """ diff --git a/myte/templates/template-flask-robust/src/resources/index.py b/myte/templates/template-flask-robust/src/resources/index.py index 0e4ed63..d4f6138 100644 --- a/myte/templates/template-flask-robust/src/resources/index.py +++ b/myte/templates/template-flask-robust/src/resources/index.py @@ -1,3 +1,5 @@ +# server.py + """ This module defines the resource for the index page """ diff --git a/myte/templates/template-flask-robust/src/routes/index.py b/myte/templates/template-flask-robust/src/routes/index.py index 21f88a8..37eecdc 100644 --- a/myte/templates/template-flask-robust/src/routes/index.py +++ b/myte/templates/template-flask-robust/src/routes/index.py @@ -1,3 +1,5 @@ +# index.py + """ This defines the routes for Homepage """ diff --git a/myte/templates/template-flask-robust/src/server.py b/myte/templates/template-flask-robust/src/server.py index 68d7977..038d7e7 100644 --- a/myte/templates/template-flask-robust/src/server.py +++ b/myte/templates/template-flask-robust/src/server.py @@ -1,3 +1,5 @@ +# server.py + """ This module defines the server configuration required to run the app successfully. @@ -10,17 +12,17 @@ CSRF Protection Error Handling """ -# imports +# imports -from flask import Blueprint, Flask -from flask_migrate import Migrate -from flask_cors import CORS import config import routes -from models import db +from flask import Blueprint, Flask +from flask_cors import CORS +from flask_migrate import Migrate from forms import csrf +from models import db # configurations diff --git a/myte/templates/template-flask-robust/src/utils/errors.py b/myte/templates/template-flask-robust/src/utils/errors.py index 6aa5d0b..a460e08 100644 --- a/myte/templates/template-flask-robust/src/utils/errors.py +++ b/myte/templates/template-flask-robust/src/utils/errors.py @@ -1,8 +1,7 @@ -""" -## Module Name: error.py +# error.py +""" This module contains error handling configurations. - """