Skip to content

Instantly share code, notes, and snippets.

@abhisuri97
Created November 27, 2017 00:34
Show Gist options
  • Save abhisuri97/ffe4e2133e7e325c0840440f951bd20c to your computer and use it in GitHub Desktop.
Save abhisuri97/ffe4e2133e7e325c0840440f951bd20c to your computer and use it in GitHub Desktop.
@main.route('/submit-review/<int:club_id>', methods=['GET', 'POST'])
@login_required
def submit_review(club_id):
class F(Form):
pass
for field in Question.query.all():
setattr(F, '{}_q'.format(field.id),
SelectField(
'{}. Pick from {} to {}'.format(field.content, 1,
field.max_rating),
choices=[('{}'.format(x + 1), x + 1)
for x in range(field.max_rating)]))
if field.free_response:
setattr(F, '{}_resp'.format(field.id),
TextAreaField('Please feel free to elaborate'))
setattr(F, 'submit', SubmitField('Submit Rating'))
form = F()
if form.validate_on_submit():
for x in form:
if x.name.find('_q') > -1:
if (x.name.find('_q')):
q_id = x.name.split('_')[0]
answer = form['{}_resp'.format(
q_id)].data if '{}_resp'.format(q_id) in form else ''
rating = x.data
Answer.newAnswer(answer, rating, current_user.id, q_id,
club_id)
flash('Club Review successfully added', 'form-success')
return render_template('main/submit-review.html', form=form)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment