Commit 590008f8 authored by Willard's avatar Willard

Merge views.py from stash

parent bbc5e9c1
......@@ -54,11 +54,12 @@ def register():
return render_template('register.html', form=form)
class StallView(MethodView):
def valid_stall(f):
@wraps(f)
def decorated_function(*args, **kwargs):
stall_id = kwargs.get('stall_id')
kwargs.pop('stall_id')
kwargs['stall'] = None
if stall_id is None:
return f(*args, **kwargs)
......@@ -66,13 +67,14 @@ class StallView(MethodView):
if stall is None or stall.owner != current_user:
return redirect(url_for('stalls'))
kwargs['stall'] = stall
return f(*args, **kwargs)
return decorated_function
decorators = [login_required, valid_stall]
def get(self, stall_id):
if stall_id is None:
def get(self, stall):
if stall is None:
return render_template('stalls.html', owner=current_user, stalls=current_user.stalls.all())
else:
dishes = stall.dishes.all()
......@@ -90,7 +92,7 @@ class StallView(MethodView):
flash_form_errors(form)
return redirect(url_for('new_stall'))
def put(self, stall_id):
def put(self, stall):
form = StallRegisterForm()
form.location.choices = [(loc.id, loc.name) for loc in Location.query.all()]
if form.validate(editing=True):
......@@ -101,9 +103,9 @@ class StallView(MethodView):
return redirect(url_for('stalls'))
else:
flash_form_errors(form)
return redirect(url_for('edit_stall', values=[('stall_id', stall_id)]))
return redirect(url_for('edit_stall', values=[('stall_id', stall.id)]))
def delete(self, stall_id):
def delete(self, stall):
db.session.delete(stall)
db.session.commit()
return redirect(url_for('stalls'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment