Example #1
0
def test_legal_create_seminar_convenor_is_speaker():
    #legal
    assert isinstance(u, Staff)
    se = SeminarEvent(name='test',
                      description='test',
                      start_time=datetime.now(),
                      end_time=datetime.now(),
                      convenor=u)
    s1 = Session(name='s1 test',
                 start_time=datetime.now(),
                 end_time=datetime.now() + timedelta(days=1),
                 deregister_timeframe=days_before_date(datetime.now(), 3),
                 early_bird=days_before_date(datetime.now(), 2),
                 speaker=u,
                 capacity=10,
                 venue=venue,
                 event=se)
    s2 = Session(name='s2 test',
                 start_time=datetime.now(),
                 end_time=datetime.now() + timedelta(days=1),
                 deregister_timeframe=days_before_date(datetime.now(), 3),
                 early_bird=days_before_date(datetime.now(), 2),
                 speaker=u,
                 capacity=10,
                 venue=venue,
                 event=se)
Example #2
0
 def make(sess, evt_id, context, req_context, sess_type):
     return Session(name=sess['name'],
                    start_time=sess['start_time'],
                    end_time=sess['end_time'],
                    capacity=sess['cap'],
                    speaker_id=sess['speaker'],
                    event_id=evt_id,
                    deregister_timeframe=days_before_date(
                        sess['start_time'], req_context['deregister']))
Example #3
0
def test_legal_create_seminar_multiple_speakers():
    #legal way -> seminar with 3 sessions -> 3 guest speakers AND unique convenor
    assert isinstance(u, Staff)
    se = SeminarEvent(name='test',
                      description='test',
                      start_time=datetime.now(),
                      end_time=datetime.now(),
                      convenor=u)
    s1 = Session(name='s1 test',
                 start_time=datetime.now(),
                 end_time=datetime.now() + timedelta(days=1),
                 deregister_timeframe=days_before_date(datetime.now(), 3),
                 early_bird=days_before_date(datetime.now(), 2),
                 speaker=g1,
                 capacity=10,
                 venue=venue,
                 event=se)
    s2 = Session(name='s2 test',
                 start_time=datetime.now(),
                 end_time=datetime.now() + timedelta(days=1),
                 deregister_timeframe=days_before_date(datetime.now(), 3),
                 early_bird=days_before_date(datetime.now(), 2),
                 speaker=g2,
                 capacity=10,
                 venue=venue,
                 event=se)
    s3 = Session(name='s3 test',
                 start_time=datetime.now(),
                 end_time=datetime.now() + timedelta(days=1),
                 deregister_timeframe=days_before_date(datetime.now(), 3),
                 early_bird=days_before_date(datetime.now(), 2),
                 speaker=g3,
                 capacity=10,
                 venue=venue,
                 event=se)
    assert len(se.event_sessions) == 3
    assert isinstance(se.convenor, Staff)
    assert isinstance(s1.speaker, Guest)
    assert isinstance(s2.speaker, Guest)
    assert isinstance(s3.speaker, Guest)
Example #4
0
def add_event():
    if not isinstance(current_user._get_current_object(), Staff):
        return redirect(url_for('index'))

    if request.method == "POST":
        session_dat = json.loads(request.form['session'])

        if (request.form['type'] == 'seminar'):
            event = SeminarEvent(name=request.form['name'],
                                 description=request.form['desc'],
                                 start_time=datetime.now(),
                                 end_time=datetime.now(),
                                 convenor=current_user)
            sessions = []

            for s in session_dat:
                usr = ems.user_manager.get_user_by_id(int(s['speaker']))
                venue = ems.get_venue_by_id(id=int(s['venue']))
                s = event.add_session(name=s['sessname'],
                                      start_time=string_to_date(s['start']),
                                      end_time=string_to_date(s['end']),
                                      deregister_timeframe=days_before_date(
                                          string_to_date(s['start']),
                                          request.form['deregister']),
                                      early_bird=days_before_date(
                                          string_to_date(s['start']),
                                          request.form['earlybird']),
                                      speaker=usr,
                                      capacity=s['sesscap'],
                                      venue=venue)
                s.add_attendee(usr)

            event.calculate_start_end()
            db.session.add(event)
        else:
            s = json.loads(request.form['session'])[0]

            venue = ems.get_venue_by_id(id=int(s['venue']))

            event = CourseEvent(name=request.form['name'],
                                description=request.form['desc'],
                                start_time=string_to_date(s['start']),
                                end_time=string_to_date(s['end']),
                                convenor=current_user)
            event.add_session(name=request.form['name'],
                              start_time=string_to_date(s['start']),
                              end_time=string_to_date(s['end']),
                              deregister_timeframe=days_before_date(
                                  string_to_date(s['start']),
                                  request.form['deregister']),
                              early_bird=days_before_date(
                                  string_to_date(s['start']),
                                  request.form['earlybird']),
                              speaker=current_user,
                              capacity=s['sesscap'],
                              venue=venue)

            db.session.add(event)

        db.session.commit()

        if len(request.files) > 0:
            if 'cover' in request.files:
                Event.register_cover(request.files['cover'], event.id)
            if 'album[]' in request.files:
                Event.register_album(request.files.getlist('album[]'),
                                     event.id)

        # todo: make this more restful
        return jsonify({'status': 'success', 'evt': event.id})
    else:
        return render_template('add_event.html', venues=ems.get_all_venues())