Beispiel #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'}))
Beispiel #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)