Commit 590008f8 authored by Willard's avatar Willard

Merge views.py from stash

parent bbc5e9c1
...@@ -54,11 +54,12 @@ def register(): ...@@ -54,11 +54,12 @@ def register():
return render_template('register.html', form=form) return render_template('register.html', form=form)
class StallView(MethodView): class StallView(MethodView):
def valid_stall(f): def valid_stall(f):
@wraps(f) @wraps(f)
def decorated_function(*args, **kwargs): def decorated_function(*args, **kwargs):
stall_id = kwargs.get('stall_id') stall_id = kwargs.get('stall_id')
kwargs.pop('stall_id')
kwargs['stall'] = None
if stall_id is None: if stall_id is None:
return f(*args, **kwargs) return f(*args, **kwargs)
...@@ -66,13 +67,14 @@ class StallView(MethodView): ...@@ -66,13 +67,14 @@ class StallView(MethodView):
if stall is None or stall.owner != current_user: if stall is None or stall.owner != current_user:
return redirect(url_for('stalls')) return redirect(url_for('stalls'))
kwargs['stall'] = stall
return f(*args, **kwargs) return f(*args, **kwargs)
return decorated_function return decorated_function
decorators = [login_required, valid_stall] decorators = [login_required, valid_stall]
def get(self, stall_id): def get(self, stall):
if stall_id is None: if stall is None:
return render_template('stalls.html', owner=current_user, stalls=current_user.stalls.all()) return render_template('stalls.html', owner=current_user, stalls=current_user.stalls.all())
else: else:
dishes = stall.dishes.all() dishes = stall.dishes.all()
...@@ -90,7 +92,7 @@ class StallView(MethodView): ...@@ -90,7 +92,7 @@ class StallView(MethodView):
flash_form_errors(form) flash_form_errors(form)
return redirect(url_for('new_stall')) return redirect(url_for('new_stall'))
def put(self, stall_id): def put(self, stall):
form = StallRegisterForm() form = StallRegisterForm()
form.location.choices = [(loc.id, loc.name) for loc in Location.query.all()] form.location.choices = [(loc.id, loc.name) for loc in Location.query.all()]
if form.validate(editing=True): if form.validate(editing=True):
...@@ -101,9 +103,9 @@ class StallView(MethodView): ...@@ -101,9 +103,9 @@ class StallView(MethodView):
return redirect(url_for('stalls')) return redirect(url_for('stalls'))
else: else:
flash_form_errors(form) 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.delete(stall)
db.session.commit() db.session.commit()
return redirect(url_for('stalls')) 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