From e02f002f7e5c1be4cf9447ee6e68d5301884fba2 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Thu, 26 Mar 2020 09:17:17 +0100 Subject: [PATCH] update bootstrap --- oshipka.sh | 17 ++++++++++++++--- oshipka/webapp/views.py | 26 ++++++++++++++++++++++++++ requirements.txt | 8 +++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/oshipka.sh b/oshipka.sh index 65e195c..e28a468 100755 --- a/oshipka.sh +++ b/oshipka.sh @@ -8,11 +8,13 @@ echo "oshipka is at: $OSHIPKA_PATH" #!/usr/bin/env bash HELP=" -Usage $0 [ bootstrap | worker | web ] +Usage $0 [ bootstrap | worker | web | venv | install ] bootstrap [PROJECT_PATH] Create a new project in PROJECT_PATH worker Start worker web Start webapp + venv Init venv + install Install requirements " worker () { @@ -64,7 +66,10 @@ bootstrap() { mkdir -p ${PROJECT_PATH} cp -r ${OSHIPKA_PATH}/bootstrap/* ${PROJECT_PATH}/ cp ${OSHIPKA_PATH}/bootstrap/.gitignore ${PROJECT_PATH}/.gitignore + cd ${PROJECT_PATH} init_venv + source venv/bin/activate + pip install -e ${OSHIPKA_PATH} } command_main() { @@ -74,7 +79,13 @@ command_main() { ;; worker) worker "$@" ;; - web) web "$@" + web) web "$@" + ;; + venv) init_venv "$@" + ;; + install) install_reqs "$@" + ;; + link) install_reqs "$@" ;; *) >&2 echo -e "${HELP}" return 1 @@ -83,4 +94,4 @@ command_main() { return $? } -command_main "$@" \ No newline at end of file +command_main "$@" diff --git a/oshipka/webapp/views.py b/oshipka/webapp/views.py index 013b7fc..4be3449 100644 --- a/oshipka/webapp/views.py +++ b/oshipka/webapp/views.py @@ -1,3 +1,5 @@ +from uuid import uuid4 + import inflect from flask import flash, render_template, redirect, request, url_for @@ -50,6 +52,24 @@ def update_view(model_view, template): return inner +def create_view(model_view, template): + def inner(): + if request.method == "GET": + return render_template(template) + serialized_form = serialize_form() + + _next = serialized_form.pop('_next') if '_next' in serialized_form else None + + serialized_form['uuid'] = str(uuid4()) + instance = model_view.model(**serialized_form) + db.session.add(instance) + db.session.commit() + flash("Created {}".format(model_view.model_name)) + return redirect(_next or request.referrer or url_for('home')) + + return inner + + def delete_view(model_view): def inner(uuid): model = model_view.model @@ -81,6 +101,12 @@ class ModelView(object): self.model_name = model.__name__.lower() self.model_name_pl = p.plural(self.model_name) + def register_create(self, list_template): + url = '/{}/create'.format(self.model_name_pl) + self.app.add_url_rule(url, methods=["GET", "POST"], + endpoint='create_{}'.format(self.model_name), + view_func=create_view(self, list_template)) + def register_list(self, list_template): url = '/{}'.format(self.model_name_pl) self.app.add_url_rule(url, diff --git a/requirements.txt b/requirements.txt index fb12e80..d72d744 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,20 @@ +Babel==2.8.0 click==7.1.1 filelock==3.0.12 Flask==1.1.1 +Flask-Babel==1.0.0 Flask-SQLAlchemy==2.4.1 Flask-Table==0.5.0 +importlib-metadata==1.5.2 inflect==4.1.0 itsdangerous==1.1.0 Jinja2==2.11.1 MarkupSafe==1.1.1 pathtools==0.1.2 -pkg-resources==0.0.0 +pytz==2019.3 +six==1.14.0 SQLAlchemy==1.3.15 +SQLAlchemy-Utils==0.36.3 watchdog==0.10.2 Werkzeug==1.0.0 +zipp==3.1.0