diff --git a/app/forms.py b/app/forms.py index f8c70dd..6197d7b 100644 --- a/app/forms.py +++ b/app/forms.py @@ -24,8 +24,8 @@ class DeleteWishlist(FlaskForm): class EditWishlistInfo(FlaskForm): - title = StringField("Title", validators=[DataRequired()]) - description = TextAreaField("Description", validators=[DataRequired()]) + title = StringField("Title") + description = TextAreaField("Description") wl_edit_submit = SubmitField("Submit") diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..83340ad --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,63 @@ + + + + {% block head %} + + + Wishthat + + + {% endblock head %} + + + + + {% block content %} + {% endblock content %} + + diff --git a/app/templates/edit.html b/app/templates/edit.html index 61e8b90..bef1766 100644 --- a/app/templates/edit.html +++ b/app/templates/edit.html @@ -1,121 +1,125 @@ {% set cpath = url_for("edit", id=wishlist.editId) %} -
-

Edit '{{wishlist.title}}'

- Manage your wishlist details and items -
-
- {{ form_wl_editinfo.hidden_tag() }} - {{ form_wl_editinfo.title.label }} - {{ form_wl_editinfo.title(placeholder=wishlist.title) }} - - {{ form_wl_editinfo.description.label }} - {{ form_wl_editinfo.description(placeholder=wishlist.description) }} - - {{ form_wl_editinfo.wl_edit_submit() }} -
-
-

Urls

- -
- {{ form_wl_reseturls.hidden_tag() }} - {{ form_wl_reseturls.wl_reset_submit() }} -
-
-

New item

-
- {{ form_it_new.hidden_tag() }} - - {{ form_it_new.it_new_title.label }} - {{ form_it_new.it_new_title() }} - - {{ form_it_new.description.label }} - {{ form_it_new.description() }} - - {{ form_it_new.price.label }} - {{ form_it_new.price() }} - - {{ form_it_new.url.label }} - {{ form_it_new.url() }} - - {{ form_it_new.image.label }} - {{ form_it_new.image() }} - - {{ form_it_new.it_new_submit() }} - -
-
-

Delete items

- {% if wishlist.items|length == 0 %}

No items yet

{% endif %} - -
-

Delete wishlist

-
- {{ form_wl_delete.hidden_tag() }} - {{ form_wl_delete.wl_del_submit() }} -
- -
+{% extends "base.html" %} - + $q("#scrape").addEventListener("click", async e => { + e.preventDefault() + const tUrl = url.value.trim(); + + if (!tUrl) { + alert("Please provide a valid url.") //TODO: Replace with daisyui modal + return + } + + const res = await fetch( + "/scrape?" + new URLSearchParams({ + url: tUrl + }).toString(), + { + method: "get", + } + ) + + if (res.status !== 200) { + alert("Failed to scrape site.") + return + } + + const json = await res.json() + title.value = json.name; + image.value = json.image; + price.value = json.price; + }) + +{% endblock content %} diff --git a/app/templates/footer.html b/app/templates/footer.html deleted file mode 100644 index b605728..0000000 --- a/app/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/app/templates/header.html b/app/templates/header.html deleted file mode 100644 index e3dce15..0000000 --- a/app/templates/header.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Wishthat - - - - - diff --git a/app/templates/index.html b/app/templates/index.html index e69de29..94d9808 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -0,0 +1 @@ +{% extends "base.html" %} diff --git a/app/templates/new.html b/app/templates/new.html index 54184df..f04c1a6 100644 --- a/app/templates/new.html +++ b/app/templates/new.html @@ -1,6 +1,8 @@ -{% include 'header.html' %} +{% extends "base.html" %} -
+{% block content %} + +
{{ form.hidden_tag() }} @@ -13,8 +15,8 @@ {{ form.description(class="w-full textarea validator mt-1 mb-2", placeholder="Wishlist Description") }}
Please make sure that both inputs are filled.
- {{ form.submit(class="btn btn-soft w-full") }} + {{ form.submit(class="btn btn-soft btn-success w-full") }}
-{% include 'footer.html' %} +{% endblock content %} diff --git a/app/templates/post_new.html b/app/templates/post_new.html index d8df650..5c7ff1c 100644 --- a/app/templates/post_new.html +++ b/app/templates/post_new.html @@ -1,4 +1,6 @@ -{% include 'header.html' %} +{% extends "base.html" %} + +{% block content %} -{% include 'footer.html' %} +{% endblock content %} diff --git a/app/templates/view.html b/app/templates/view.html index 742ebe1..432990b 100644 --- a/app/templates/view.html +++ b/app/templates/view.html @@ -1,4 +1,6 @@ -{% include 'header.html' %} +{% extends "base.html" %} + +{% block content %}

{{wishlist.title}}

{{wishlist.description}} @@ -57,4 +59,4 @@ -{% include 'footer.html' %} +{% endblock content %} diff --git a/app/views.py b/app/views.py index e1d55c8..0a81987 100644 --- a/app/views.py +++ b/app/views.py @@ -13,14 +13,12 @@ from app.forms import ( ) from app.models import Wishlist, Item from uuid import UUID, uuid4 as uuid -from json import JSONEncoder - from app.scrapers import scrapeSite @app.route("/") def index(): - return "hello" + return render_template("index.html") @app.route("/new", methods=["GET", "POST"]) @@ -67,8 +65,13 @@ def edit(id: str): return redirect(url_for("index")) elif form_wl_editinfo.validate_on_submit() and form_wl_editinfo.wl_edit_submit.data: - wishlist.title = str(form_wl_editinfo.title.data) - wishlist.description = str(form_wl_editinfo.description.data) + if form_wl_editinfo.title.data != "" and form_wl_editinfo.title.data != None: + wishlist.title = str(form_wl_editinfo.title.data) + if ( + form_wl_editinfo.description.data != "" + and form_wl_editinfo.description.data != None + ): + wishlist.description = str(form_wl_editinfo.description.data) db.session.commit() return redirect(url_for("edit", id=id)) diff --git a/instance/application.db b/instance/application.db index 5e34ed5..d3dec65 100644 Binary files a/instance/application.db and b/instance/application.db differ