Exemplo n.º 1
0
def post_event():
    global current_event
    global current_user
    current_event = read_event()
    if not current_user:
        add_output("You have to login first to post events. \n")
    else:
        result = EventController.add_event(current_user, current_event)
        if result == Errors.DUPLICATE.name:
            current_event.eid = None
            add_output("The same event already exists. \n")
        elif result == Errors.FAILURE.name:
            current_event.eid = None
            return_failure()
        add_output('Event #' + str(result) + ' has been posted. \n')
        current_event.eid = result

        result = EventController.host_event(current_user, current_event)
        if result == Errors.DUPLICATE.name:
            current_event.eid = None
            add_output("You have already hosted this event. \n")
        elif result == Errors.FAILURE.name:
            current_event.eid = None
            return_failure()
        add_output("You are the host of event " + str(current_event.eid) +
                   " now. \n")
        current_event.hosts = current_user.uid
        current_user.host_events.append(current_event.eid)
        print('User #' + current_event.hosts + ' posted event #' +
              str(current_event.eid) + '. \n')
        EventController.print_event(current_event)
    return
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
    def test_host_event(self):
        UserController.add_user(self.user_1)
        user_2 = UserController.retrieve_user('email', 'email_1')

        event_id = EventController.add_event(self.event_1)
        self.event_1.eventid = event_id

        self.assertIsNotNone(EventController.host_event(user_2, self.event_1))

        UserController.delete_user('nickname_1', 'email_1')
Exemplo n.º 6
0
    def test_add_event(self):
        invalid_date = '2018.12.31'
        invalid_event_1 = EventModel(1, 'event_title_1', 'tags_1',
                                     'description_1', 'image_1', [], [],
                                     invalid_date, 'location_1', 'address1',
                                     '5')
        event_id_1 = EventController.add_event(self.event_1)

        self.assertIsNotNone(event_id_1)
        self.assertIsNotNone(EventController.add_event(invalid_event_1))
Exemplo n.º 7
0
def update_event(data):
    event = EventModel(data['id'], data['title'], data['tags'],
                       data['description'], data['image'], data['hosts'], [],
                       data['event_date'], data['state'], data['address'],
                       data['register_period'])
    EventController.print_event(event)

    result = EventController.edit_event(event)

    if result == Errors.MISSING.name:
        return Errors.MISSING.name
    elif result == Errors.SUCCESS.name:
        return Errors.SUCCESS.name
    else:
        return Errors.FAILURE.name
Exemplo n.º 8
0
def post_event():
    global current_event
    global current_user
    current_event = read_event()
    if not current_user:
        add_output("You have to login first! \n")
    else:
        result = EventController.post_event(current_user, current_event)
        if result == Errors.DUPLICATE.name:
            add_output("A same event already exists! \n")
        elif result == Errors.FAILURE.name:
            return_failure()
        current_event.eid = result
        result = EventController.host_event(current_user, current_event)
        if result == Errors.DUPLICATE.name:
            add_output("A same event already exists! \n")
        elif result == Errors.FAILURE.name:
            return_failure()
    return
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
0
def post_event(data):
    event = EventModel(0, data['title'], data['tags'], data['description'],
                       data['image'], data['hosts'], [], data['event_date'],
                       data['state'], data['address'], data['register_period'])

    EventController.print_event(event)
    result = EventController.add_event(event)
    if result == Errors.DUPLICATE.name:
        event.eid = None
        return Errors.DUPLICATE.name, None
    elif result == Errors.FAILURE.name:
        event.eid = None
        return Errors.FAILURE.name, None
    print('Event #' + str(result) + ' has been posted. \n')
    event.eid = result

    result = EventController.host_event(event.hosts, event)
    if result == Errors.DUPLICATE.name:
        current_event.eid = None
        print("You have already hosted this event. \n")
        return Errors.DUPLICATE.name
    elif result == Errors.FAILURE.name:
        current_event.eid = None
        return Errors.FAILURE.name

    EventController.print_event(event)
    data = {
        'eid': event.eid,
        'title': event.title,
        'tags': event.tags,
        'description': event.description,
        'hosts': event.hosts,
        'event_date': event.event_date,
        'state': event.location,
        'address': event.address,
        'image': event.image,
        'register_period': event.register_period,
        'expire_date': event.expire_date
    }
    return 'OK', data
Exemplo n.º 12
0
 def test_post_event(self):
     event_id_1 = EventController.add_event(self.user_1, self.event_1)
     self.assertIsNotNone(event_id_1)
Exemplo n.º 13
0
def get_events(data):
    return EventController.get_events(data)
Exemplo n.º 14
0
def remove_user(data):
    result = EventController.remove_user(data)
    return result
Exemplo n.º 15
0
def attend_event(data):
    result = EventController.join_event(data)
    return result