Пример #1
0
def index():
    form = RegisterSessionForm()
    if form.validate_on_submit():
        attendee = Attendee.query.filter_by(name=form.attendee.data).first()
        # Still need to implement instructor check
        #        print('Checking instructor')
        #        instructor = Attendee.query.filter_by(name=form.instructor.data).first_or_404()
        #        put a pin in that until I have decided how training sessions gets defined.
        query = db.session.query(Attendee).filter(
            Attendee.name == form.instructor.data, Attendee.instructor == True)

        if attendee is None:
            attendee = Attendee(name=form.attendee.data)
            db.session.add(attendee)

        weapon_class = form.weapon_class.data
        date = form.date.data
        today = date.today()

        if date > today:
            flash('Can\'t register a date in the future')

            return redirect(url_for('main.index'))


#        training_session = TrainingSession.query.filter(
#            and_(TrainingSession.date == date,
#                 TrainingSession.weapon_class == weapon_class)).first_or_404()

        query = db.session.query(TrainingSession).filter(
            TrainingSession.date == date,
            TrainingSession.weapon_class == weapon_class)
        training_session = TrainingSession()

        if query is None:
            training_session = TrainingSession(date=date,
                                               attendee=attendee,
                                               weapon_class=weapon_class,
                                               instructor=instructor.id)
        else:
            training_session.date = date
            training_session.weapon_class = weapon_class
            training_session.set_instructor = form.instructor.data

        attendee.attending.append(training_session)

        db.session.add(training_session)
        db.session.commit()
        flash('Your training session is now registered!')
        return redirect(url_for('main.index'))
    registered_attendees = Attendee.query.filter(
        Attendee.name == form.attendee.data, )

    return render_template('main/index.html',
                           title='Home',
                           form=form,
                           registered_attendees=registered_attendees)
Пример #2
0
def registration():
    if request.method == 'POST':
        attendee = Attendee()
        attendee.first_name = request.form['first_name']
        attendee.last_name = request.form['last_name']
        attendee.email = request.form['email']
        attendee.job_position = request.form['job_position']
        attendee.company = request.form['company']
        attendee.city = request.form['city']
        attendee.state = request.form['state']
        attendee.interests = request.form['interest']
        attendee.comments = request.form['message']
        attendee.conference_id = app.config.get('CONFERENCE_ID')

        try:
            db.session.add(attendee)
            db.session.commit()
            session['message'] = 'Thank you, {} {}, for registering!'.format(
                attendee.first_name, attendee.last_name)
            return redirect('/Registration')
        except:
            logging.error('Error occured while saving your information')

    else:
        if 'message' in session:
            message = session['message']
            session.pop('message', None)
            return render_template('registration.html', message=message)
        else:
            return render_template('registration.html')