def new(): if request.method == 'POST': event_name = request.form['name'] date_format = "%Y-%m-%d" start_time = request.form['start_time'] end_time = request.form['end_time'] early_time = request.form['early_time'] fee = request.form['fee'] location = request.form['location'] description = request.form['description'] max_num = request.form['max_numbers'] type_event = request.form['type'] user = system.get_user_by_id(current_user.get_id()) event = system.add_event(event_name, early_time, start_time, end_time, max_num, location, user, fee, description, type_event) if not isinstance(event,Event): return render_template('new.html', message = event) user.add_event_posted(event) return render_template('event_create_confirm.html', event= event) return render_template('new.html')
def session(eid, sid): event = system.get_event_by_id(eid) session = event.get_session_by_id(sid) user = system.get_user_by_id(current_user.get_id()) if request.method == "POST": if 'be_speaker' in request.form and current_user.what_type() != "Student" and not event.check_attendee(user): session.speaker = user return render_template('sessions.html', session = session)
def dashboard(): r_events = [] p_events = [] c_events = [] user = system.get_user_by_id(current_user.get_id()) r_events = user.get_event_registered() if user.what_type() == 'Staff': p_events = user.get_event_posted() c_events = user.get_event_cancelled() return render_template('dashboard.html', user = user)
def book(rego): car = system.get_car(rego) if car is None: abort(404) if request.method == 'POST': date_format = "%Y-%m-%d" start_date = datetime.strptime(request.form['start_date'], date_format) end_date = datetime.strptime(request.form['end_date'], date_format) diff = end_date - start_date if 'check' in request.form: fee = car.get_fee(diff.days) return render_template('booking_form.html', confirmation=True, form=request.form, car=car, fee=fee) elif 'confirm' in request.form: location = Location(request.form['start'], request.form['end']) booking = system.make_booking( system.get_user_by_id(current_user.get_id()), diff, car, location) return render_template('booking_confirm.html', booking=booking) return render_template('booking_form.html', car=car)
def event(eid): event = system.get_event_by_id(eid) user = system.get_user_by_id(current_user.get_id()) if not event.is_course(): sessions = event.get_sessions() fee = None if current_user.what_type() == 'Guest': if event.is_discount(): fee = int(event.fee) * 0.5 else: fee = event.fee if request.method == 'POST': if 'register' in request.form: mark = [] if not event.is_course(): for c in sessions: checked = request.form.get(c.name) if checked: mark.append(c.name) message = system.register_event(eid, user, mark) if not isinstance(message, Event): return render_template('events.html',event = event, confirmation = False, fee = fee, error = message) return render_template('event_de_re_confirm.html', event = event, info = 'registered',fee = fee) else: message = system.register_event(eid, user, mark) if not isinstance(message, Event): return render_template('events.html',event = event, confirmation = False, fee = fee, error = message) return render_template('event_de_re_confirm.html', event = event, info = 'registered',fee = fee) if 'deregister' in request.form and event.can_cancell() and event.check_attendee(user): event.del_attendee(user) user.del_event_registered(event) if not event.is_course(): for c in sessions: for f in c.get_attendee(): if f.email == user.email: c.del_attendee(user) return render_template('event_de_re_confirm.html', event = event, info = 'de-registered') if 'cancel' in request.form and user.email == event.convenor.email: event.status = "cancelled" user.add_event_cancelled(event) user.del_event_posted(event) for c in event.get_attendee(): c.add_event_closed(event) c.del_event_registered(event) return render_template('event_de_re_confirm.html', event = event, info = 'cancelled') if 'add_session' in request.form: if user.email == event.convenor.email: return render_template('events.html',event = event, confirmation = True) return render_template('events.html',event = event, error = 'Only convenor have the right to add sessions.') if 'submit' in request.form: session_name = request.form['name'] location = request.form['location'] start_time = request.form['start_time'] end_time = request.form['end_time'] capacity = request.form['capacity'] message = event.add_sessions(session_name, capacity, location, start_time, end_time) if not isinstance(message, Session): return render_template('events.html',event = event, confirmation = True, fee = fee, error = message) return render_template('events.html',event = event, confirmation = False, error = 'New session created successfully') return render_template('events.html',event = event, confirmation = False, fee = fee)