Guest User

Untitled

a guest
Nov 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. @app.route('/newevent', methods=['GET', 'POST']) #TAGGED
  2. @login_required
  3. def newevent():
  4. form = NewEvent()
  5. msgs = ''
  6. if request.method=='POST' and form.validate_on_submit():
  7. check = Event.query.filter_by(eventid=form.eventid.data).first()
  8. if check is None:
  9. db.session.add(Event(eventid=form.eventid.data, eventName=form.eventName.data, eventDate=form.eventDate.data, allocation=form.allocation.data, Event_orgCode=current_user.orgCode))
  10. db.session.commit()
  11. return redirect(url_for('adminevents'))
  12. elif check.eventid == form.eventid.data:
  13. msgs = 'Event already exists!'
  14. return render_template('events_new.html', form=form, msgs=msgs)
  15. return render_template('events_new.html', form=form, msgs=msgs)
  16.  
  17. {% block content %}
  18. {% with msg = get_flashed_messages() %}
  19. <h1>Create New Event</h1>
  20. <h3> {{ msgs }} </h3>
  21. <div class="input-event">
  22. <form class="form form-horizontal" action="{{ url_for('newevent') }}" method="POST" role="form">
  23. <dl>
  24. {{ form.hidden_tag() }}
  25. {{ form.csrf_token }}
  26. {{ wtf.form_field(form.eventid, placeholder="Pick a 4-digit ID e.g., 0042") }}
  27. {{ wtf.form_field(form.eventName, placeholder="Name your event") }}
  28. {{ wtf.form_field(form.eventDate) }}
  29. {{ wtf.form_field(form.allocation, placeholder="Enter budget allocation") }}
  30. </dl>
  31. <input class="btn btn-success" type="submit" value="Add">
  32. <input class="btn btn-primary" type="button" value="Back" onclick="window.location.href='/adminevents'">
  33. </form>
  34.  
  35. </div>
  36. {% endwith %}
  37. {% endblock %}
Add Comment
Please, Sign In to add comment