Commit da1dcb2d authored by Willard's avatar Willard

Reorganize stall_views.py

parent 976825e0
...@@ -12,17 +12,6 @@ class StallListView(View): ...@@ -12,17 +12,6 @@ class StallListView(View):
def dispatch_request(self): def dispatch_request(self):
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())
app.add_url_rule('/stalls', view_func=StallListView.as_view('stalls'), methods=['GET'])
class StallView(View):
decorators = [login_required, stall_validate]
def dispatch_request(self, stall_id):
stall = Stall.query.get(stall_id)
dishes = stall.dishes.all()
return render_template('viewstall.html', stall=stall, dishes=dishes, upload_folder=app.config['UPLOAD_FOLDER'])
app.add_url_rule('/stalls/<int:stall_id>', view_func=StallView.as_view('view_stall'), methods=['GET'])
class NewStallView(FormView): class NewStallView(FormView):
decorators = [login_required] decorators = [login_required]
def render_post(self): def render_post(self):
...@@ -38,7 +27,12 @@ class NewStallView(FormView): ...@@ -38,7 +27,12 @@ class NewStallView(FormView):
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()]
return form return form
app.add_url_rule('/stalls/new', view_func=NewStallView.as_view('new_stall')) class StallView(View):
decorators = [login_required, stall_validate]
def dispatch_request(self, stall_id):
stall = Stall.query.get(stall_id)
dishes = stall.dishes.all()
return render_template('viewstall.html', stall=stall, dishes=dishes, upload_folder=app.config['UPLOAD_FOLDER'])
class EditStallView(FormView): class EditStallView(FormView):
decorators = [login_required, stall_validate] decorators = [login_required, stall_validate]
...@@ -64,8 +58,6 @@ class EditStallView(FormView): ...@@ -64,8 +58,6 @@ class EditStallView(FormView):
form.editing = True form.editing = True
return form return form
app.add_url_rule('/stalls/<int:stall_id>/edit', view_func=EditStallView.as_view('edit_stall'))
class DeleteStallView(View): class DeleteStallView(View):
decorators = [login_required, stall_validate] decorators = [login_required, stall_validate]
def dispatch_request(self, stall_id): def dispatch_request(self, stall_id):
...@@ -74,4 +66,8 @@ class DeleteStallView(View): ...@@ -74,4 +66,8 @@ class DeleteStallView(View):
db.session.commit() db.session.commit()
return redirect(url_for('view_stall'), stall_id=stall_id) return redirect(url_for('view_stall'), stall_id=stall_id)
app.add_url_rule('/stalls', view_func=StallListView.as_view('stalls'), methods=['GET'])
app.add_url_rule('/stalls/new', view_func=NewStallView.as_view('new_stall'))
app.add_url_rule('/stalls/<int:stall_id>', view_func=StallView.as_view('view_stall'), methods=['GET'])
app.add_url_rule('/stalls/<int:stall_id>/edit', view_func=EditStallView.as_view('edit_stall'))
app.add_url_rule('/stalls/<int:stall_id>/delete', view_func=DeleteStallView.as_view('delete_stall'), methods=['POST']) app.add_url_rule('/stalls/<int:stall_id>/delete', view_func=DeleteStallView.as_view('delete_stall'), methods=['POST'])
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