def create_model(): if request.method == "POST": name = request.form['name'] if StoreModel.find_by_name(name): return "Model already exists with name. Try another name" store = StoreModel(name=name, username=session['username']) try: store.save_to_db() except: return "Error creating model" return redirect(url_for(".index")) return render_template("models/new_model.html")
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_db() return {'message': 'store deleted'}
def edit_model(model_id): if request.method == "POST": name = request.form['name'] model = StoreModel.find_by_id(model_id) model.name = name try: model.save_to_db() except: flash('Error renaming model', 'danger') #return "Error renaming model" return redirect(url_for(".index")) # What happens if it's a GET request return render_template("models/edit_model.html", model=StoreModel.find_by_id(model_id))
def index(): model_id = request.args.get('model_id') model = StoreModel.find_by_id(model_id) #print(model) #print(store_list_schema.dump(model.items)) return render_template("items/index.html", items=item_list_schema.dump(model.items), model=model)
def get(self, name): """ :param name: :return: """ store = StoreModel.find_by_name(name) if store: return store.json() return {'message': 'Store not found'}, 404
def post(self, name): if StoreModel.find_by_name(name): return dict(message=f'A store with name {name} already exists'), 400 store = StoreModel(name) try: store.save() except: return dict(message='An error occurred while creating the store'), 500 return store.json(), 201
def mutate(root, info, store_id, tenant, working_hours, is_enabled, address): try: new_store = StoreModel(store_id=store_id, tenant=tenant, working_hours=working_hours, is_enabled=is_enabled, address=address) db_session.add(new_store) db_session.commit() ok = True return CreateStore(ok=ok, store=new_store) except Exception: return CreateStore(ok=False)
def post(self, name): if ItemModel.find_by_name(name): return {'message': "An item with name '{}' already exists.".format(name)}, 400 data = Item.parser.parse_args() item = ItemModel(name, **data) if StoreModel.find_by_id(item.store_id) is None: return {'message': "An Store with id '{}' does not exit.".format(item.store_id)}, 400 try: item.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 return item.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { 'message': 'The store with name {} already exists'.format(name) }, 400 store = StoreModel(name) try: store.save_to_db() except: return {'message': 'Internal server error creating store'}, 500 return store.json(), 200
def post(self, name): if StoreModel.find_by_name(name): return { 'message': "A store with name '{}' already exists.".format(name) }, 400 store = StoreModel(name) try: store.save_to_db() except: {'message': 'An error occured while creating the store.'}, 500 return store.json(), 201
def __init__(self): self.login_model = LoginModel() self.store_model = StoreModel() self.main_action = MainAction(self.login_model, self.store_model) self.last_scene = None
def post(self, name): if StoreModel.find_by_name(name): return {"message": "store already exists"} store = StoreModel(name) store.save_to_db() return store.json()
def get(self, name): return StoreModel.find_by_name(name)
def delete_model(model_id): model = StoreModel.find_by_id(model_id) if model.username == session["username"]: model.delete_from_db() return redirect(url_for(".index"))
def index(): models = StoreModel.find_by_username(session["username"]) #print(store_list_schema.dump(models)) return render_template("models/index.html", models=store_list_schema.dump(models))
def get(self, name): store = StoreModel.find_by_name(name) return store.json() if store else {'message': 'Store not found'}, 404