Exemplo n.º 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
        #show the all the products of the list

        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            pid = self.request.get('pid')
            if pid:
                List.deleteProductFromList(list_id, int(pid))
                p_name = self.request.get('p_name')
                p_quantity = self.request.get('p_quantity')
                p_units = self.request.get('p_units')
                if p_name and p_quantity and p_units:
                    if Product.checkIfProductExists(p_name, list_id):
                        self.response.write(json.dumps({'status': 'exists'}))
                        return
                    Product.addProduct(p_name, p_quantity, p_units, list_id)
                    time.sleep(0.5)
            new_Product_name = self.request.get('new_Product_name')
            new_Product_quantity = self.request.get('new_Product_quantity')
            new_Product_units = self.request.get('new_Product_units')
            if new_Product_name and new_Product_quantity and new_Product_units:
                if Product.checkIfProductExists(new_Product_name, list_id):
                    self.response.write(json.dumps({'status': 'exists'}))
                    return
                Product.addProduct(new_Product_name, new_Product_quantity,
                                   new_Product_units, list_id)
                time.sleep(0.5)
            listProducts = List.getAllProductsOfTheList(list_id)
            list_name = List.getListByID(list_id).ListName
            user_permit = List.getUserPermit(list_id, user.email)
            data = []
            if list_name:
                data.append(list_name)
                data.append(listProducts)
                data.append(user_permit)
                self.response.write(json.dumps(data))
        else:
            self.response.write(json.dumps({'status': 'error'}))
Exemplo n.º 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
        template_params['userEmail'] = user.email
        #get group_id from cookies
        group_id = int(self.request.cookies.get('group_id_cookie'))

        #get group names
        groupsNames = Group.getAllGroupsNames(user.email)
        if groupsNames:
            template_params['userGroups'] = groupsNames

        #show the all the products of the list
        list_id = int(self.request.get('lid'))
        if list_id:
            self.response.set_cookie('list_id_cookie', str(list_id))
            listProducts = List.getAllProductsOfTheList(list_id)
            template_params['listProducts'] = listProducts
            list = List.getListByID(list_id)
            list_name = list.ListName
            template_params['list_name'] = list_name
            if (list.ListAdmin == user.email):
                template_params['isListAdmin'] = user.email

        #get the lists names from the group
        groupsLists = List.getAllListsNameOfTheUser(group_id, user.email)
        if groupsLists:
            template_params['groupsLists'] = groupsLists

        html = template.render("web/templates/list.html", template_params)
        self.response.write(html)
Exemplo n.º 3
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)
Exemplo n.º 4
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 = None

        template_params['userEmail'] = user.email
        group_id = None
        group_id = int(self.request.cookies.get('group_id_cookie'))

        groupsLists = List.getAllListsNameOfTheUser(group_id, user.email)
        if groupsLists:
            template_params['groupLists'] = groupsLists

        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            list = List.getListByID(list_id)
            if list:
                users = List.getAllListUsersByID(list_id)
                template_params['listUsers'] = users
                template_params['listName'] = list.ListName
                template_params['listAdmin'] = list.ListAdmin
                if (list.ListAdmin == user.email):
                    template_params['isListAdmin'] = user.email
                else:
                    template_params['isNotListAdmin'] = user.email

        # Retrieving all the groups names for showing on left side.
        groupsNames = Group.getAllGroupsNames(user.email)
        if groupsNames:
            template_params['userGroups'] = groupsNames
        template_params['group_id'] = group_id

        #delete user from a list
        deleteUser = self.request.get('deleteUser')
        if deleteUser:
            List.deleteUserFromList(deleteUser, list_id)

        #add user to a list
        addUser = self.request.get('addUser')
        permit = self.request.get('permit')
        if addUser:
            userToAdd = List.checkIfUserInList(addUser)
            if userToAdd == True:
                self.response.write('userExist')
                return
            else:
                #need to implement
                self.response.write('userNotExist')

        # changing a list name
        newListName = self.request.get('newListName')
        if newListName:
            List.changeListName(list_id, newListName)

        # check if asked to delete group
        confirmDeletion = self.request.get('confirmDeletion')
        if confirmDeletion:
            List.deleteList(list_id, group_id)
            self.response.delete_cookie('list_id')
            time.sleep(0.3)
            self.response.write('statusDeleted')

        html = template.render("web/templates/listDetails.html",
                               template_params)
        self.response.write(html)