Пример #1
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return

        group_id = None
        gid = self.request.get('gid')
        if gid:
            group_id = int(gid)
            self.response.set_cookie('group_id_cookie', str(group_id))
        else:
            group_id = int(self.request.cookies.get('group_id_cookie'))

        #create new list
        new_list_name = self.request.get('new_list_name')
        if new_list_name:
            if List.checkIfTheNameExists(new_list_name, group_id):
                self.response.write(
                    json.dumps({
                        "status": "exist",
                        "name": new_list_name
                    }))
                return
            else:
                list_usersToAdd = json.loads(
                    self.request.get('list_usersToAdd'))
                newList = List.createList(new_list_name, user.email, group_id)
                if newList:
                    if list_usersToAdd:
                        for listUser in list_usersToAdd:
                            List.addUserToList(new_list_name, user.email,
                                               listUser[0], listUser[1],
                                               newList.ListID)
                time.sleep(0.3)
                allData = []
                listNames = List.getAllListsName(group_id)
                if listNames:
                    allData.append(listNames)
                    allData.append(newList.ListID)
                    self.response.write(json.dumps(allData))
Пример #2
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return

        group_id = None
        gid = self.request.get('gid')
        if gid:
            group_id = int(gid)
        else:
            group_id = int(self.request.cookies.get('group_id_cookie'))

        #Fill User Input
        fill = self.request.get('fillUsers')
        if fill:
            users = Group.getAllUsersFromGroupByID(group_id)
            self.response.write(json.dumps(users))

        # changing a list name
        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            newListName = self.request.get('newListName')
            if newListName:
                if List.checkIfTheNameExists(newListName, group_id):
                    self.response.write(
                        json.dumps({
                            "status": "exist",
                            "name": newListName
                        }))
                    return
                data = []
                List.changeListName(list_id, newListName)
                listNames = List.getAllListsName(group_id)
                data.append(listNames)
                data.append(newListName)
                self.response.write(json.dumps(data))
                return

        #delete user from a list
        removeUser = self.request.get('removeUser')
        if removeUser:
            List.deleteUserFromList(removeUser, list_id)
            time.sleep(0.3)
            users = List.getAllListUsersByID(list_id)
            if users:
                self.response.write(json.dumps(users))
            else:
                self.response.write(json.dumps({"status": "empty"}))
            return

        #add user to a list
        addUser = self.request.get('addUser')
        permit = self.request.get('permit')
        if addUser:
            userToAdd = List.checkIfUserInList(list_id, addUser)
            if userToAdd == True:
                self.response.write(
                    json.dumps({
                        "status": "exist",
                        "name": addUser
                    }))
                return
            checkIfUser = User.checkIfUserExists(addUser)
            if checkIfUser:
                list = List.getListByID(list_id)
                list_name = list.ListName
                List.addUserToList(list_name, user.email, addUser, permit,
                                   list_id)
                time.sleep(0.3)
                users = List.getAllListUsersByID(list_id)
                self.response.write(json.dumps(users))
                return
            else:
                self.response.write(
                    json.dumps({
                        "status": "notUser",
                        "name": addUser
                    }))
                return

        # leaving a list
        leaveList = self.request.get('leaveList')
        if leaveList:
            List.deleteUserFromList(user.email, list_id)
            self.response.write(json.dumps({"status": "ok"}))
            time.sleep(0.3)