Пример #1
0
def group_email():
    global current_user
    global current_event
    if not current_user:
        add_output('You have to log in first. \n')
    event_id = event_id_input.get()
    current_event = EventController.retrieve_event(event_id)
    if current_event == Errors.MISSING.name:
        add_output('No such event. \n')
        current_event = None
        return
    elif current_event == Errors.FAILURE.name:
        return_failure()
        current_event = None
        return
    if current_user.uid != current_event.hosts:
        add_output('You have to be the host to send a group email. \n')
        current_event = None
        return

    message = email_message_input.get()
    user_list = current_event.attendees
    EventController.print_event(current_event)
    for user_id in user_list:
        sent = False
        try:
            temp_user = UserController.retrieve_user(UserFields.userid.name,
                                                     user_id)
            send_email(message, temp_user.email)
            sent = True
        finally:
            if not sent:
                add_output('Unable to send email to ' + temp_user.email +
                           '. \n')
    return
Пример #2
0
def join_event():
    global current_event
    global current_user
    event_id = event_id_input.get()
    current_event = EventController.retrieve_event(event_id)
    if current_event == Errors.MISSING.name:
        add_output('Event not found. \n')
        current_event = None
        return
    elif current_event == Errors.FAILURE.name:
        add_output('Failed to join event. \n')
        current_event = None
        return
    if not current_user:
        add_output('You have to login first to join events. \n')
        current_event = None
        return

    result = EventController.join_event(current_user, current_event)
    if result == Errors.DUPLICATE.name:
        add_output('You have already joined the event. \n')
    elif result == Errors.FAILURE.name:
        return_failure()
        current_event = None
        return
    else:
        add_output('You have joined event #' + current_event.eid +
                   '. User ID: ' + current_user.uid + '. \n')

    EventController.print_event(current_event)
    return
Пример #3
0
def remove_user():
    global current_user
    global current_event
    if not current_user:
        add_output('You have to log in first. \n')
    event_id = event_id_input.get()
    current_event = EventController.retrieve_event(event_id)
    if current_event == Errors.MISSING.name:
        add_output('No such event. \n')
        current_event = None
        return
    elif current_event == Errors.FAILURE.name:
        return_failure()
        current_event = None
        return
    if current_user.uid != current_event.hosts:
        add_output('You have to be the host to remove attendees. \n')
        current_event = None
        return

    user_id = user_id_input.get()
    result = EventController.remove_user(user_id, current_event)
    if result == Errors.MISSING.name:
        add_output('User did not attend. \n')
        current_event = None
        return
    elif result == Errors.FAILURE.name:
        return_failure()
        current_event = None
        return
    add_output('User #' + result[0] + ' removed from event #' + result[1] +
               '. \n')
    return
Пример #4
0
def update_event():
    global current_event
    global current_user
    event_id = event_id_input.get()
    current_event = read_event()
    current_event.eid = event_id
    host_id = None
    temp_event = EventController.retrieve_event(event_id)
    if temp_event == Errors.MISSING.name:
        add_output('No such event. \n')
        current_event = None
        return
    if type(temp_event) == type(current_event):
        host_id = str(EventController.retrieve_event(event_id).hosts)
    if current_user.uid != host_id:
        add_output('You have to be the owner to update event #' + event_id +
                   ' . \n')
        current_event = None
        return

    result = EventController.edit_event(current_event)

    if result == Errors.MISSING.name:
        add_output('No such event exists. \n')
        current_event = None
        EventController.print_event(current_event)
        return
    elif result == Errors.SUCCESS.name:
        add_output('Event #' + event_id + ' changed. \n')
        current_event = EventController.retrieve_event(event_id)
        EventController.print_event(current_event)
    else:
        add_output('Update failed, please try again. \n')
        current_event = None
        EventController.print_event(current_event)
        return
Пример #5
0
def request_event(data):
    event = EventController.retrieve_event(data)
    if event == 'FAILURE':
        return event, None
    response = {
        'id': event.eid,
        'title': event.title,
        'description': event.description,
        'address': event.address,
        'location': event.location,
        'image': event.image,
        'tags': event.tags,
        'event_date': event.event_date,
        'expire_date': event.expire_date,
        'host': event.hosts,
        'join': event.attendees
    }
    return 'OK', response