Esempio n. 1
0
    def do_GET(self):
        self._set_headers(200)
        response = {}  # Default response

        # Parse the URL and capture the tuple that is returned
        parsed = self.parse_url(self.path)

        if len(parsed) == 2:
            (resource, id) = parsed

            if resource == "entries":
                if id is not None:
                    response = f"{get_single_entry(id)}"

                else:
                    response = f"{get_all_entries()}"
            if resource == "moods":
                response = f"{get_all_moods()}"
        
        elif len(parsed) == 3:
            (resource, key, value) = parsed
            
            if key == "q" and resource == "entries":
                response = get_all_entries(value)

        self.wfile.write(response.encode())
Esempio n. 2
0
def diary():
    if not users.authenticated():
        abort(403)
    if request.method == "GET":
        all_candies = candies.get_all_candies()
        daily_entries = entries.get_sum_of_days()
        user_data = entries.get_additional_user_data()
        all_entries = entries.get_all_entries()
        return render_template("diary.html",
                               candies=all_candies,
                               daily_entries=daily_entries,
                               user_data=user_data,
                               all_entries=all_entries)
    if request.method == "POST":
        candy = request.form["select-candy"]
        date = request.form["candy-date"]
        tokenc = request.form["tokenc"]
        new_name = request.form["add-candy-name"]
        new_company = request.form["add-candy-company"]
        new_weight = request.form["add-candy-weight"]
        new_sugar = request.form["add-candy-sugar"]
        new_gtin = request.form["add-candy-gtin"]
        new_category = request.form["add-candy-category"]
        if new_name != '':
            candy = candies.add_candy(new_name, new_company, new_weight,
                                      new_sugar, new_gtin, new_category)
        if entries.add_entry(candy, date, tokenc):
            return redirect("/diary")
    def do_GET(self):
        self._set_headers(200)

        response = {}

        # Parse URL and store entire tuple in a variable
        parsed = self.parse_url(self.path)

        # Response from parse_url() is a tuple with 2
        # items in it, which means the request was for
        # `/animals` or `/animals/2`
        if len(parsed) == 2:
            (resource, id) = parsed

            if resource == "entries":
                if id is not None:
                    response = get_single_entry(id)
                else:
                    response = get_all_entries()
            elif resource == "moods":
                response = get_all_moods()
            elif resource == "instructors":
                response = get_all_instructors()
            elif resource == "tags":
                response = get_all_tags()
            elif resource == "entrytags":
                response = get_all_entry_tags()

        # Response from parse_url() is a tuple with 3
        # items in it, which means the request was for
        # `/resource?parameter=value`
        elif len(parsed) == 3:
            (resource, key, value) = parsed

            # Is the resource `customers` and was there a
            # query parameter that specified the customer
            # email as a filtering value?
            if key == "entries" and resource == "customers":
                response = f"{get_customers_by_email(value)}"
            if key == "location_id":
                if resource == "animals":
                    response = f"{get_animals_by_location(value)}"
                elif resource == "employees":
                    response = f"{get_employees_by_location(value)}"
            if key == "status" and resource == "animals":
                response = f"{get_animals_by_status(value)}"

        self.wfile.write(response.encode())
Esempio n. 4
0
    def do_GET(self):
        self._set_headers(200)

        response = {}

        # Parse URL and store entire tuple in a variable
        parsed = self.parse_url(self.path)

        # Response from parse_url() is a tuple with 2
        # items in it, which means the request was for
        # `/entries` or `/entries/2`
        if len(parsed) == 2:
            ( resource, id ) = parsed

            if resource == "entries":
                if id is not None:
                    response = f"{get_single_entry(id)}"
                else:
                    response = f"{get_all_entries()}"
            if resource == "moods":
                if id is not None:
                    response = f"{get_single_mood(id)}"
                else:
                    response = f"{get_all_moods()}" 

        elif len(parsed) == 3:
            ( resource, key, value ) = parsed

            # Is the resource `customers` and was there a
            # query parameter that specified the customer
            # email as a filtering value?
            if resource == "entries":
                if key == "q" and value:
                    response = get_entries_with_value(value)
                else:
                    response = get_all_entries()
        
        
        self.wfile.write(response.encode())
Esempio n. 5
0
    def do_GET(self):
        self._set_headers(200)

        response = {}

        parsed = self.parse_url(self.path)

        if len(parsed) == 2:
            ( resource, id ) = parsed

            if resource == "entries":
                if id is not None:
                    response = f"{get_single_entry(id)}"
                else:
                    response = f"{get_all_entries()}"
            elif resource == "moods":
                if id is not None:
                    response = f"{get_single_mood(id)}"
                else:
                    response = f"{get_all_moods()}"
            elif resource == "tags":
                if id is not None:
                    response = ""
                else:
                    response = f"{get_all_tags()}"

        elif len(parsed) == 3:
            ( resource, key, value ) = parsed

            if key == "q" and resource == "entries":
                if value:
                    response = get_entry_by_word(value)
                else:
                    response = get_all_entries()

        self.wfile.write(response.encode())
Esempio n. 6
0
    def do_GET(self):
        self._set_headers(200)

        response = {}

        # Parse URL and store entire tuple in a variable
        parsed = self.parse_url(self.path)

        # Response from parse_url() is a tuple with 2
        # items in it, which means the request was for
        # `/animals` or `/animals/2`
        if len(parsed) == 2:
            (resource, id) = parsed

            if resource == 'entries':
                if id is not None:
                    response = f"{get_single_entry(id)}"
                else:
                    response = f"{get_all_entries()}"
            elif resource == 'moods':
                if id is not None:
                    response = f"{get_single_mood(id)}"
                else:
                    response = f"{get_all_moods()}"

        # Handle query params
        elif len(parsed) == 3:
            (resource, key, value) = parsed

            if key == "q" and resource == "entries":
                if value:
                    response = get_entry_by_query(value)
                else:
                    response = get_all_entries()

        self.wfile.write(response.encode())
    def do_GET(self):
        self._set_headers(200)
        response = {}  # Default response

        parsed = self.parse_url(self.path)
        # Parse the URL and capture the tuple that is returned
        if len(parsed) == 2:
            (resource, id) = self.parse_url(self.path)

            if resource == "entries":
                if id is not None:
                    response = f"{get_single_entry(id)}"
                else:
                    response = f"{get_all_entries()}"
            if resource == "moods":
                if id is not None:
                    response = f"{get_single_mood(id)}"

                else:
                    response = f"{get_all_moods()}"
            if resource == "tags":
                response = f"{get_all_tags()}"

        elif len(parsed) == 3:
            (resource, key, value) = parsed

            # Is the resource `customers` and was there a
            # query parameter that specified the customer
            # email as a filtering value?
            if key == "q" and resource == "entries":
                if value == None:
                    response = get_all_entries()
                else:
                    response = get_entry_by_word(value)

        self.wfile.write(response.encode())