Commit b58e050f authored by Willard's avatar Willard

Place editing field in form class

parent fbc4c82f
...@@ -49,13 +49,14 @@ class StallRegisterForm(FlaskForm): ...@@ -49,13 +49,14 @@ class StallRegisterForm(FlaskForm):
description = TextAreaField('Description', [DataRequired()]) description = TextAreaField('Description', [DataRequired()])
image = FileField('Image') image = FileField('Image')
location = SelectField(coerce=int) location = SelectField(coerce=int)
editing = False
def validate(self, editing=False): def validate(self, editing=False):
if not FlaskForm.validate(self): if not FlaskForm.validate(self):
return False return False
stall = Stall.query.filter_by(name=self.name.data).first() stall = Stall.query.filter_by(name=self.name.data).first()
if not editing: if not self.editing:
if stall is not None: if stall is not None:
flash('Stall name is taken!') flash('Stall name is taken!')
return False return False
......
...@@ -42,10 +42,11 @@ def new_stall(): ...@@ -42,10 +42,11 @@ def new_stall():
def edit_stall(stall_id): def edit_stall(stall_id):
stall = Stall.query.get(stall_id) stall = Stall.query.get(stall_id)
form = StallRegisterForm() form = StallRegisterForm()
form.editing = True
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 request.method == 'POST': if request.method == 'POST':
if form.validate(editing=True): if form.validate():
stall.name = form.name.data stall.name = form.name.data
stall.description = form.description.data stall.description = form.description.data
stall.location_id = form.location.data stall.location_id = form.location.data
......
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