Esempio n. 1
0
class ListEventsHelper(object):
    def __init__(self, user_id):
        self.__user_id = user_id
        self.db_event = EventDBOperation()
        self.aws_event = Event()

    def get_all_updated_events_list(self):
        event_id_list = self.db_event.get_updated_event_id_list(self.__user_id)
        comments_dict = self.db_event.get_comments_by_event_id_list(event_id_list)
        print(comments_dict)
        event_info_list = self.aws_event.batch_query_by_event_id_list(event_id_list)
        result_list = []
        for event_info in event_info_list:
            event_id = event_info['event_id']
            if event_id in comments_dict:
                comments = comments_dict[event_id]
            else:
                comments = []
            result_list.append(dict(
                event_id=event_id,
                info=event_info['info'],
                comments=comments
            ))
        return result_list

    def get_all_pending_events_list(self):
        pass

    def get_all_events_by_page(self):
        pass

    def get_event_info(self, event_id):
        event_info = self.aws_event.get_event_info_by_event_id(event_id)
        comments_dict = self.db_event.get_comments_by_event_id_list([event_id])
        if event_id in comments_dict:
            comments = comments_dict[event_id]
        else:
            comments = []
        result_dict = dict(
            event_id=event_id,
            info=event_info,
            comments=comments
        )
        return result_dict
Esempio n. 2
0
class ListEventsHelper(object):
    def __init__(self, user_id):
        self.__user_id = user_id
        self.db_event = EventDBOperation()
        self.aws_event = Event()

    def get_all_updated_events_list(self):
        event_id_list = self.db_event.get_updated_event_id_list(self.__user_id)
        comments_dict = self.db_event.get_comments_by_event_id_list(
            event_id_list)
        print(comments_dict)
        event_info_list = self.aws_event.batch_query_by_event_id_list(
            event_id_list)
        result_list = []
        for event_info in event_info_list:
            event_id = event_info['event_id']
            if event_id in comments_dict:
                comments = comments_dict[event_id]
            else:
                comments = []
            result_list.append(
                dict(event_id=event_id,
                     info=event_info['info'],
                     comments=comments))
        return result_list

    def get_all_pending_events_list(self):
        pass

    def get_all_events_by_page(self):
        pass

    def get_event_info(self, event_id):
        event_info = self.aws_event.get_event_info_by_event_id(event_id)
        comments_dict = self.db_event.get_comments_by_event_id_list([event_id])
        if event_id in comments_dict:
            comments = comments_dict[event_id]
        else:
            comments = []
        result_dict = dict(event_id=event_id,
                           info=event_info,
                           comments=comments)
        return result_dict
Esempio n. 3
0
class TopicOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def invite_members_to_topic(self, members):
        current_members = self.event_item['info']['members']
        new_members = current_members + members
        topic_name = self.event_item['info']['topic_name']
        self.event_item['info']['members'] = new_members
        self.event_item.partial_save()
        self.db_event.bulk_create_new_event_per_user(self.__event_id, EVENT_TYPE, members)
        self.db_event.update_event_to_new(self.__event_id)
        return topic_name

    def exit_topic(self):
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
Esempio n. 4
0
class ActivityOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def invite_members_to_activity(self, members):
        current_members = self.event_item['info']['members']
        new_members = current_members + members
        self.event_item['info']['members'] = new_members
        self.event_item.partial_save()
        self.db_event.bulk_create_new_event_per_user(self.__event_id, EVENT_TYPE, members)
        self.db_event.update_event_to_new(self.__event_id)

    def exit_topic(self):
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)

    def post_notification(self, notification_content):
        members = self.event_item['info']['members']
        current_time = int(time.time())
        temp_list = self.event_item['info']['notification_list']
        temp_list.append(dict(
            created_time=current_time,
            content=notification_content,
            editor_id=self.__user_id
        ))
        self.event_item['info']['notification_list'] = temp_list
        self.event_item.partial_save()
        return members
Esempio n. 5
0
class ActivityOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def invite_members_to_activity(self, members):
        current_members = self.event_item['info']['members']
        new_members = current_members + members
        self.event_item['info']['members'] = new_members
        self.event_item.partial_save()
        self.db_event.bulk_create_new_event_per_user(self.__event_id,
                                                     EVENT_TYPE, members)
        self.db_event.update_event_to_new(self.__event_id)

    def exit_topic(self):
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)

    def post_notification(self, notification_content):
        members = self.event_item['info']['members']
        current_time = int(time.time())
        temp_list = self.event_item['info']['notification_list']
        temp_list.append(
            dict(created_time=current_time,
                 content=notification_content,
                 editor_id=self.__user_id))
        self.event_item['info']['notification_list'] = temp_list
        self.event_item.partial_save()
        return members
Esempio n. 6
0
 def __init__(self, user_id):
     self.__user_id = user_id
     self.db_event = EventDBOperation()
     self.aws_event = Event()
Esempio n. 7
0
 def __create(self, event_info, members):
     aws_api.Event().create_new_event(self.__event_id, event_info)
     user_id_list = members + [self.__creator_id]
     EventDBOperation().bulk_create_new_event_per_user(
         self.__event_id, self.__event_type, user_id_list)
Esempio n. 8
0
 def __init__(self, user_id):
     self.__user_id = user_id
     self.db_event = EventDBOperation()
     self.aws_event = Event()
Esempio n. 9
0
 def __init__(self, user_id, event_id):
     self.__user_id = user_id
     self.__event_id = event_id
     self.table = Table('Event')
     self.event_item = self.table.get_item(event_id=event_id)
     self.db_event = EventDBOperation()
Esempio n. 10
0
class ReminderOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def change_receivers(self, receivers):
        current_receivers = self.event_item['info']['receivers']
        self.event_item['info']['receivers'] = receivers
        self.event_item['info']['receiver_status'] = dict.fromkeys(
            receivers, 0)
        self.event_item.partial_save()
        self.db_event.remove_event_by_user_id_list(self.__event_id,
                                                   current_receivers)
        self.db_event.bulk_create_new_event_per_user(self.__event_id,
                                                     EVENT_TYPE, receivers)
        self.db_event.update_event_to_new(self.__event_id)

    def complete_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 1
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id,
                                               self.__user_id,
                                               action=1,
                                               content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id

    def revoke_reminder_by_creator(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        receivers = self.event_item['info']['receivers']
        self.event_item['info']['status'] = 5
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id,
                                               self.__user_id,
                                               action=5,
                                               content=message)
        user_id_list = receivers + [self.__user_id]
        self.db_event.remove_event_per_user(self.__event_id, user_id_list)
        return creator_id

    def delay_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 2
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id,
                                               self.__user_id,
                                               action=2,
                                               content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id

    def reject_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 3
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id,
                                               self.__user_id,
                                               action=3,
                                               content=message)
        self.db_event.update_event_to_new(self.__event_id)
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        return creator_id

    def resend_reminder_by_creator(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['status'] = 6
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id,
                                               self.__user_id,
                                               action=6,
                                               content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id
Esempio n. 11
0
 def __init__(self, user_id, event_id):
     self.__user_id = user_id
     self.__event_id = event_id
     self.table = Table('Event')
     self.event_item = self.table.get_item(event_id=event_id)
     self.db_event = EventDBOperation()
Esempio n. 12
0
class TaskOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def invite_members_to_task(self, members):
        current_members = self.event_item['info']['members']
        member_status = self.event_item['info']['member_status']
        temp = member_status.copy()
        temp.update(dict.fromkeys(members, 0))
        new_members = current_members + members
        task_name = self.event_item['info']['task_name']
        self.event_item['info']['members'] = new_members
        self.event_item['info']['member_status'] = temp
        self.event_item.partial_save()
        self.db_event.bulk_create_new_event_per_user(self.__event_id,
                                                     EVENT_TYPE, members)
        return task_name

    def accept_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 1
        self.event_item.partial_save()
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)

    def reject_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 2
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)

    def exit_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 3
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)
Esempio n. 13
0
class ReminderOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def change_receivers(self, receivers):
        current_receivers = self.event_item['info']['receivers']
        self.event_item['info']['receivers'] = receivers
        self.event_item['info']['receiver_status'] = dict.fromkeys(receivers, 0)
        self.event_item.partial_save()
        self.db_event.remove_event_by_user_id_list(self.__event_id, current_receivers)
        self.db_event.bulk_create_new_event_per_user(self.__event_id, EVENT_TYPE, receivers)
        self.db_event.update_event_to_new(self.__event_id)

    def complete_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 1
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id, self.__user_id, action=1, content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id

    def revoke_reminder_by_creator(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        receivers = self.event_item['info']['receivers']
        self.event_item['info']['status'] = 5
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id, self.__user_id, action=5, content=message)
        user_id_list = receivers + [self.__user_id]
        self.db_event.remove_event_per_user(self.__event_id, user_id_list)
        return creator_id

    def delay_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 2
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id, self.__user_id, action=2, content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id

    def reject_reminder_by_receiver(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['receiver_status'][self.__user_id] = 3
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id, self.__user_id, action=3, content=message)
        self.db_event.update_event_to_new(self.__event_id)
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        return creator_id

    def resend_reminder_by_creator(self, message=None):
        creator_id = self.event_item['info']['creator_id']
        self.event_item['info']['status'] = 6
        self.event_item.partial_save()
        self.db_event.save_comment_by_event_id(self.__event_id, self.__user_id, action=6, content=message)
        self.db_event.update_event_to_new(self.__event_id)
        return creator_id
Esempio n. 14
0
class TaskOperation(object):
    def __init__(self, user_id, event_id):
        self.__user_id = user_id
        self.__event_id = event_id
        self.table = Table('Event')
        self.event_item = self.table.get_item(event_id=event_id)
        self.db_event = EventDBOperation()

    def invite_members_to_task(self, members):
        current_members = self.event_item['info']['members']
        member_status = self.event_item['info']['member_status']
        temp = member_status.copy()
        temp.update(dict.fromkeys(members, 0))
        new_members = current_members + members
        task_name = self.event_item['info']['task_name']
        self.event_item['info']['members'] = new_members
        self.event_item['info']['member_status'] = temp
        self.event_item.partial_save()
        self.db_event.bulk_create_new_event_per_user(self.__event_id, EVENT_TYPE, members)
        return task_name

    def accept_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 1
        self.event_item.partial_save()
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)

    def reject_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 2
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)

    def exit_task(self, message=None):
        self.event_item['info']['member_status'][self.__user_id] = 3
        members = self.event_item['info']['members']
        if self.__user_id in members:
            members.remove(self.__user_id)
        self.event_item['info']['members'] = members
        self.event_item.partial_save()
        self.db_event.remove_event_per_user(self.__event_id, self.__user_id)
        if message:
            self.db_event.save_comment_by_event_id(self.__event_id, message)
        self.db_event.update_event_to_new(self.__event_id)