コード例 #1
0
    def get_rate_template_context(buff, user_id):
        """
        return the template name and correct context for rating and comment
        """
        day = Helper.get_day_of_week()
        week = Helper.get_week_number()

        if day in ["saturday", "sunday"]:
            return {"template": "weekend_rate_error", "context": {}}

        else:
            meal = buff[1]
            option = buff[2]
            rating = buff[3]
            comment = " ".join(buff[4:]) or "no comment"

            check_option = Helper.check_option_selected(option, day, week, meal)

            if not Helper.check_meal_selected(meal):
                return {"template": "invalid_meal", "context": {}}

            if not check_option["bool"]:
                return {"template": "invalid_option", "context": {"option_count": check_option["option"]}}

            if not Helper.check_rating(rating):
                return {"template": "invalid_rating", "context": {}}

            if Helper.check_multiple_rating(user_id, meal):
                return {"template": "multiple_rating", "context": {}}

            variables = (meal, day, week, option)
            sql = CustomSQL()
            query_string = (
                "SELECT id FROM menu_table WHERE meal = (%s) AND day = (%s) AND week = (%s) AND option = (%s)"
            )
            result = sql.query(query_string, variables)
            food_menu_id = int(result[0][0])
            get_date = Helper.get_date()
            variables = (user_id, food_menu_id, rating, comment, get_date)
            query_string = (
                "INSERT INTO rating (user_id, menu_id, rate, comment, created_at) VALUES (%s, %s, %s, %s, %s)"
            )
            sql.command(query_string, variables)
            return {"template": "rating_response", "context": {}}
コード例 #2
0
    def get_rate_template_context(buff, user_id):
        """
        return the template name and correct context for rating and comment
        """
        day = Helper.get_day_of_week()
        week = Helper.get_week_number()

        if day in ['saturday', 'sunday']:
            return {'template': 'weekend_rate_error', 'context': {}}

        else:
            meal = buff[1]
            option = buff[2]
            rating = buff[3]
            comment = ' '.join(buff[4:]) or 'no comment'

            check_option = Helper.check_option_selected(option, day, week,
                                                        meal)

            if Helper.check_meal_selected(meal) is False:
                return {'template': 'invalid_meal', 'context': {}}

            if check_option['bool'] is False:
                return {'template': 'invalid_option',
                        'context': {'option_count': check_option['option']}}

            if Helper.check_rating(rating) is False:
                return {'template': 'invalid_rating', 'context': {}}

            variables = (meal, day, week, option,)
            sql = CustomSQL()
            query_string = 'SELECT id FROM menu_table WHERE meal = (%s) AND day = (%s) AND week = (%s) AND option = (%s)'
            result = sql.query(query_string, variables)
            food_menu_id = int(result[0][0])
            variables = (user_id, food_menu_id, rating, comment)
            query_string = "INSERT INTO rating (user_id, menu_id, rate, comment) VALUES (%s, %s, %s, %s)"
            sql.command(query_string, variables)
            return {'template': 'rating_response', 'context': {}}