From 89118c6d1d23663d8bf8b794c7d828ed4dc797a2 Mon Sep 17 00:00:00 2001 From: Jurn Wubben Date: Tue, 24 Jun 2025 09:45:17 +0200 Subject: [PATCH] Created base template. Updated forms. Added navbar. Added better scraping support for edit page. --- app/forms.py | 4 +- app/templates/base.html | 63 ++++++++++ app/templates/edit.html | 236 ++++++++++++++++++------------------ app/templates/footer.html | 2 - app/templates/header.html | 11 -- app/templates/index.html | 1 + app/templates/new.html | 10 +- app/templates/post_new.html | 6 +- app/templates/view.html | 6 +- app/views.py | 13 +- instance/application.db | Bin 12288 -> 12288 bytes 11 files changed, 208 insertions(+), 144 deletions(-) create mode 100644 app/templates/base.html delete mode 100644 app/templates/footer.html delete mode 100644 app/templates/header.html 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 5e34ed5a3baa084af424db9310e9144f4cf2de15..d3dec6517c4314420e8ddce17051f8229440973b 100644 GIT binary patch delta 447 zcmZojXh@hK&8Rq0#+gxZW5N=C6#=dW2L6@&Hhi!6Ch%#MnXDW{k_Z#jR z+%8ONKQ;kO-eCJO0q~c zNi<5eG&D>!OEEREFf}nrO0h6cGe|QrH8V0vvotnKGXoixnU|iGTC9+rn3tVe6vPKI zSyD35)G#&GEZNjBEiKW+$kNy{(a_M)z$C@Q!Ynn}z#t{r(%8tt*wP}&%)->f+$hb$ zxZcFrG%3X(DcQo*%rZ3%Vq8|DLRNly5HG|~3qu3bOAGVFG$Uh!loa!n+{Enc)S`_1)FNIk YKOV4|f+?nHiDs52Mi!g@N;8W90M7e?IRF3v delta 55 zcmZojXh@hK%_uri#+gxcW5N=C86NI84E!tkZTMdCP2zLp{lGhm*M;XD&r}{8?l&6? M&v0*kBP}8V0Nc0`{{R30