Exemplo n.º 1
0
    def post(self):

        the_RU = check_user_id_cookie(self.request)

        if the_RU:
            # get request data

            # id data (which check boxes has user checked) put in a variable
            list_of_id_checked = self.request.get_all("delete")  # returns a list of id strings

            # delete button data (if delete button clicked, list will have 1 item else no item in list)
            one_item_delete_button_list = self.request.get_all("delete_button")  # there is only 1 delete_button

            if len(one_item_delete_button_list) == 1:  # delete button is clicked
                # loop through list_of_id_checked and remove matches from db
                for an_id in list_of_id_checked:
                    # find the item with the specific id in db
                    match = FoodItem.get_by_id(int(an_id))
                    # remove the item
                    if match:
                        FoodItem.delete(match)
                time.sleep(0.1)  # to delay so db table gets displayed correct

            sort_code = self.request.cookies.get("sort_code")  # look_number (cookie)
            if sort_code:
                sort_criteria = validation.get_param(sort_code)
            else:
                sort_criteria = "created DESC"
            self.render_front(the_RU.name, parameter=sort_criteria)

        else:  # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie())
            self.redirect("/logout")
Exemplo n.º 2
0
    def get(self):
        the_RU = check_user_id_cookie(self.request)

        if the_RU:
            id_descript = self.request.get(
                "id_description"
            )  # if header link 'Description' is clicked 'ASC' or 'DESC' will be assigned
            id_days_left = self.request.get(
                "id_days_to_exp"
            )  # if header link 'Days to exp' is clicked 'ASC' or 'DESC' will be assigned
            id_days_in_freezer = self.request.get(
                "id_days_frozen"
            )  # if header link 'Days in freezer' is clicked 'ASC' or 'DESC' will be assigned

            if id_descript:  # 'Description' was clicked
                self.render_front(the_RU.name,
                                  parameter="lower_case_description %s" %
                                  id_descript)
            elif id_days_left:  # 'Days to exp' was clicked
                self.render_front(the_RU.name,
                                  parameter="expiry %s" %
                                  id_days_left)  # the 'oldest' shown first
            elif id_days_in_freezer:  # 'Days in freezer' was clicked
                self.render_front(the_RU.name,
                                  parameter="created %s" % id_days_in_freezer)
            else:
                sort_code = self.request.cookies.get(
                    'sort_code')  # look_number (cookie)
                if sort_code:
                    sort_criteria = validation.get_param(sort_code)
                else:
                    sort_criteria = "created DESC"
                self.render_front(the_RU.name, parameter=sort_criteria)
        else:  # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie())
            self.redirect("/logout")
Exemplo n.º 3
0
    def get(self):
        the_RU = check_user_id_cookie(self.request)

        if the_RU:
            id_descript = self.request.get(
                "id_description"
            )  # if header link 'Description' is clicked 'ASC' or 'DESC' will be assigned
            id_days_left = self.request.get(
                "id_days_to_exp"
            )  # if header link 'Days to exp' is clicked 'ASC' or 'DESC' will be assigned
            id_days_in_freezer = self.request.get(
                "id_days_frozen"
            )  # if header link 'Days in freezer' is clicked 'ASC' or 'DESC' will be assigned

            if id_descript:  # 'Description' was clicked
                self.render_front(the_RU.name, parameter="lower_case_description %s" % id_descript)
            elif id_days_left:  # 'Days to exp' was clicked
                self.render_front(the_RU.name, parameter="expiry %s" % id_days_left)  # the 'oldest' shown first
            elif id_days_in_freezer:  # 'Days in freezer' was clicked
                self.render_front(the_RU.name, parameter="created %s" % id_days_in_freezer)
            else:
                sort_code = self.request.cookies.get("sort_code")  # look_number (cookie)
                if sort_code:
                    sort_criteria = validation.get_param(sort_code)
                else:
                    sort_criteria = "created DESC"
                self.render_front(the_RU.name, parameter=sort_criteria)
        else:  # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie())
            self.redirect("/logout")
Exemplo n.º 4
0
    def post(self):

        the_RU = check_user_id_cookie(self.request)

        if the_RU:
            # get request data

            # id data (which check boxes has user checked) put in a variable
            list_of_id_checked = self.request.get_all(
                "delete")  # returns a list of id strings

            # delete button data (if delete button clicked, list will have 1 item else no item in list)
            one_item_delete_button_list = self.request.get_all(
                "delete_button")  # there is only 1 delete_button

            if len(one_item_delete_button_list
                   ) == 1:  # delete button is clicked
                # loop through list_of_id_checked and remove matches from db
                for an_id in list_of_id_checked:
                    # find the item with the specific id in db
                    match = FoodItem.get_by_id(int(an_id))
                    # remove the item
                    if match:
                        FoodItem.delete(match)
                time.sleep(0.1)  # to delay so db table gets displayed correct

            sort_code = self.request.cookies.get(
                'sort_code')  # look_number (cookie)
            if sort_code:
                sort_criteria = validation.get_param(sort_code)
            else:
                sort_criteria = "created DESC"
            self.render_front(the_RU.name, parameter=sort_criteria)

        else:  # either user_id_cookie_value, username, or the_RU is None (see check_user_id_cookie())
            self.redirect("/logout")