update bootstrap

This commit is contained in:
Daniel Tsvetkov 2020-03-26 09:17:17 +01:00
parent 9559d029bf
commit e02f002f7e
3 changed files with 47 additions and 4 deletions

View File

@ -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() {
@ -76,6 +81,12 @@ command_main() {
;;
web) web "$@"
;;
venv) init_venv "$@"
;;
install) install_reqs "$@"
;;
link) install_reqs "$@"
;;
*) >&2 echo -e "${HELP}"
return 1
;;

View File

@ -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,

View File

@ -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