Example #1
0
    def group_test(self):
        self.add_new_group(Group("Beginners (Foo)", 16, (6, 12), 2, [], []),
                           self.sport_map["Football"])
        self.add_new_group(
            Group("Intermediate (Foo)", 10, (12, 16), 1, [], []),
            self.sport_map["Football"])
        self.add_new_group(Group("Pro (Foo)", 6, (16, 35), 4, [], []),
                           self.sport_map["Football"])

        self.add_new_group(Group("Beginners (Voll)", 16, (6, 12), 2, [], []),
                           self.sport_map["Volleyball"])
        self.add_new_group(
            Group("Intermediate (Voll)", 10, (10, 33), 2, [], []),
            self.sport_map["Volleyball"])

        self.add_new_group(Group("Everybody (Che)", 30, (6, 99), 5, [], []),
                           self.sport_map["Chess"])

        self.add_new_group(Group("Beginners (Swi)", 16, (6, 12), 1, [], []),
                           self.sport_map["Swimming"])
        self.add_new_group(
            Group("Intermediate (Swi)", 10, (10, 20), 0, [], []),
            self.sport_map["Swimming"])
        print("test success")
        time.sleep(1.0)
Example #2
0
def find_group(username, user, session):

    group = Group.find(username=username)
    if not group:
        abort(404)

    return response({'group': group.make_json()})
Example #3
0
def username_available(username, user, session):

    users = User.find_username(username)
    groups = Group.find_username(username)

    available = not users and not groups
    return response({'username': username, 'available': available})
Example #4
0
def get_group(update: Update):
    """
    get group from update
    :param update: update instance
    :return: Group
    """

    group_data = update.effective_chat
    group = Group.get_by_chat_id(group_data.id)
    if group:
        return group

    group = Group.register(group_data.id, group_data.type,
                           group_data.username, group_data.title)

    return group
Example #5
0
    def new_group(self, selected_sport):
        """Takes in selected sport"""
        name = input("Write name of new group: ")
        try:
            group_size = input("Decide how big the group shall be: (number) ")
            #tuple of two integers, ages from (12,14)
            group_age_range_l = int(input("Ages ranging from: (number) "))
            group_age_range_h = int(input("to: (number) "))

            group_age_range = (group_age_range_l, group_age_range_h)

        except (ValueError, TypeError, IndexError):
            PrintGraphicsUI.oops()

        new_group = Group(name, group_size, group_age_range, 0, [], [])
        self.add_new_group(new_group, selected_sport)

        #== [ UNDO OP ] =============================================
        save_op = OpInfo(OpType.DELETE_GROUP, new_group, selected_sport)
        self.undo_stack.append(save_op)
        for op in self.undo_stack:
            print(f'Op Type: {op.op_type} -> Object pointer: {op}')
        #== [ END UNDO ] ============================================

        return new_group  #for when member makes new group to add to member?
Example #6
0
def join_group(username, user, session):

    group = Group.find(username=username)
    if not group:
        abort(404)

    group.add_user(user)
    ChatController.user_joined_group(group, user)
    return response({'joined': True, 'group': group.make_json()})
Example #7
0
def search_username(username, user, session):

    users = User.find_username(username)
    groups = Group.find_username(username)

    return response({
        'groups': [group.make_json(include_members=False) for group in groups],
        'users': [user.make_json() for user in users]
    })
def get_group(gid):
    conn = mysql.connect()
    cursor = conn.cursor()
    cursor.execute(
        'select G.GroupId, G.GroupName, G.GroupType, G.GroupOwner from Groups G where G.GroupId=%s',
        (gid))
    data = cursor.fetchone()
    if not data:
        return None
    return Group(data[0], data[1], data[2], data[3])
Example #9
0
def create_group(user, session):

    json = request.json
    schema = Schema({'title': str, 'username': str})
    try:
        schema.validate(json)
    except SchemaError as err:
        return response(err.code)

    title = json['title']
    username = json['username']

    users = User.find_username(username)
    groups = Group.find_username(username)
    if users or groups:
        return error_response('username has been already taken')

    group = Group.new(user.id, title, username)
    return response({'group': group.make_json()})
Example #10
0
def leave_group(username, user, session):

    group = Group.find(username=username)
    if not group:
        abort(404)

    if not group.has_user(user):
        return error_response('you are not a member of this group')

    group.remove_user(user)
    ChatController.user_left_group(group, user)
    return response({'joined': True, 'group': group.make_json()})
def groupid_to_object(groupids):
    conn = mysql.connect()
    cursor = conn.cursor()
    groups = []
    for g in groupids:
        cursor.execute(
            'SELECT GroupId, GroupName, GroupType FROM Groups WHERE groupid=%s',
            (g))
        data = cursor.fetchone()
        group = Group(gid=data[0], groupname=data[1], grouptype=data[2])
        groups.append(group)

    return groups
def created_groups_controller():
    conn = mysql.connect()
    cursor = conn.cursor()
    query = "SELECT G.groupId, G.groupName, G.groupType FROM Groups G WHERE G.groupOwner = %s ORDER BY G.groupName;"
    cursor.execute(query, (session['userid']))
    data = cursor.fetchall()

    #create group objects
    groups = []
    for d in data:
        group = Group(gid=d[0], groupname=d[1], grouptype=d[2])
        groups.append(group)

    return groups
def find_membered_group_controller(form):
    conn = mysql.connect()
    cursor = conn.cursor()

    #search for groups that start with whatever was entered and that the user is already in
    query = "SELECT G.groupId, G.groupName, G.groupType FROM Groups G, GroupMembers GM WHERE GM.userId = %s AND G.groupId = GM.groupId AND G.groupName LIKE %s ORDER BY G.groupName;"
    cursor.execute(query, (session['userid'], (form.groupname.data + '%')))
    data = cursor.fetchall()

    # create group objects
    groups = []
    for d in data:
        group = Group(gid=d[0], groupname=d[1], grouptype=d[2])
        groups.append(group)

    return groups
Example #14
0
    def new_msg(cls, sender_id, recipient_id, text):
        """
        when a user sends a new message to the server
        :param sender_id: sender's id
        :param recipient_id: recipient (group/user) id
        :param text: message's text
        :return:
        """

        sender = User.find(id=sender_id)
        sender_sid = cls.get_user_sid(sender.id)

        if is_group(recipient_id):

            recipient_group = Group.find(id=recipient_id)

            if not recipient_group:
                raise Exception('recipient was not found')
            if not recipient_group.has_user(sender):
                raise Exception('user is not a member of this group')

            cls._broadcast_group(sender, sender_sid,
                                 recipient_group, text)

        elif is_user(recipient_id):

            recipient = User.find(id=recipient_id)
            if not sender.is_friends(recipient):
                raise Exception('user is not friends with recipient')

            if recipient.blocked(sender):
                raise Exception('recipient has blocked you')

            if not recipient:
                raise Exception('recipient was not found')

            cls._broadcast_user(sender, sender_sid, recipient,
                                text)

        else:

            raise Exception('bad recipient id')
def find_non_membered_group_controller(form):
    conn = mysql.connect()
    cursor = conn.cursor()

    #search for groups that start with whatever was entered and that the user is NOT already in (all groups (-) membered groups)
    query = "SELECT DISTINCT G.groupId, G.groupName, G.groupType FROM Groups G, GroupMembers GM WHERE G.groupId = GM.groupId AND G.groupName LIKE '%s' AND GM.groupId NOT IN " % (
        form.groupname.data + '%')
    query2 = "(SELECT GM.groupId FROM GroupMembers GM, Groups G WHERE G.groupId = GM.groupId AND GM.userId = %s) ORDER BY G.groupName;" % (
        session['userid'])

    cursor.execute(query + query2)
    data = cursor.fetchall()

    # create group objects
    groups = []
    for d in data:
        group = Group(gid=d[0], groupname=d[1], grouptype=d[2])
        groups.append(group)

    return groups
Example #16
0
    def calendarURL(self, bot, update):
        user_id = update.message.from_user.id
        message = update.message.text

        # Verify the URL
        if self.__icorsiCalendarURLIsValid(message):
            a = DBConnection.Instance().executeQuery(
                "SELECT * FROM Groups WHERE groupId = {}".format(user_id),
                True)
            if a == None:
                group = Group(user_id, message)
                DBConnection.Instance().save(group)

            # ELSE: This is a weird case. The group may already be present in the DB

            update.message.reply_text("The bot has been set up!")
        else:
            update.message.reply_text(
                "Looks like the provided URL is not valid. Please start again with the procedure"
            )