From f14e8780f8e3ba4b7575dd45925385b73cf1ce04 Mon Sep 17 00:00:00 2001 From: ferfissimo Date: Wed, 26 May 2021 23:36:58 +0000 Subject: [PATCH] init --- Development%2FBackend.md | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Development%2FBackend.md diff --git a/Development%2FBackend.md b/Development%2FBackend.md new file mode 100644 index 0000000..7c2587b --- /dev/null +++ b/Development%2FBackend.md @@ -0,0 +1,90 @@ +# Backend Development + +* [General code style](Development#python) +* [Plugin Development]() +* [Tips and Tricks]() + +## Plugin Development +### File Structure + flaschengeist-example-plugin + |> __init__.py + |> model.py + |> setup.py + +### Files +#### \_\_init\_\_.py + from flask import Blueprint + from flaschengeist.modules import Plugin + + + example_bp = Blueprint("example", __name__, url_prefix="/example") + permissions = ["example_hello"] + + class PluginExample(Plugin): + def __init__(self, conf): + super().__init__(blueprint=example_bp, permissions=permissions) + + def install(self): + from flaschengeist.system.database import db + import .model + db.create_all() + db.session.commit() + + + @example_bp.route("/hello", methods=['GET']) + @login_required(roles=['example_hello']) + def __hello(id, **kwargs): + return "Hello" + +#### model.py +Optional, only needed if you need your own models (database) + + from flaschengeist.system.database import db + + + class ExampleModel(db.Model): + """Example Model""" + __tablename__ = 'example' + id = db.Column(db.Integer, primary_key=True) + description = db.Column(db.String(240)) + +#### setup.py + from setuptools import setup, find_packages + + setup( + name="flaschengeist-example-plugin", + version="0.0.0-dev", + packages=find_packages(), + install_requires=[ + "flaschengeist >= 2", + ], + entry_points={ + "flaschengeist.plugin": [ + "example = flaschengeist-example-plugin:ExampleModel" + ] + }, + ) + +## Tips and Tricks +### Code formatting +We use [Black](https://github.com/psf/black) as the code formatter. + +Installation: + + $ pip install black + +Usage: + + $ black -l 120 DIRECTORY_OR_FILE + + +### Git blame +When using `git blame` use this to ignore the code formatting commits: + + $ git blame FILE.py --ignore-revs-file .git-blame-ignore-revs +Or if you just want to use `git blame`, configure git like this: + + $ git config blame.ignoreRevsFile .git-blame-ignore-revs + +#### Ignore changes on config + git update-index --assume-unchanged flaschengeist/flaschengeist.toml