From c0f8cc02d26d7b6bc9a956142bfb0810ba753796 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 1 Dec 2023 23:55:38 +0100 Subject: [PATCH] Some more basic stuff --- src/db.sqlite3 | Bin 159744 -> 159744 bytes src/wishlists/handler/__init__.py | 0 src/wishlists/handler/wishlist/__init__.py | 0 .../handler/wishlist/get_wishlist_handler.py | 16 ++++++++++ src/wishlists/models.py | 2 ++ src/wishlists/templates/owner/index.html | 9 ++++++ src/wishlists/templates/public/index.html | 28 ++++++++++++++++++ src/wishlists/views.py | 9 ++++-- 8 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/wishlists/handler/__init__.py create mode 100644 src/wishlists/handler/wishlist/__init__.py create mode 100644 src/wishlists/handler/wishlist/get_wishlist_handler.py create mode 100644 src/wishlists/templates/owner/index.html diff --git a/src/db.sqlite3 b/src/db.sqlite3 index 10b17e9b96b3fbe6dcd8222dd6bfe2f889aeef1f..f1e11f67d8fdd8c4c5f638b523880c4dfcd93827 100644 GIT binary patch delta 257 zcmZp8z}fJCbAq&>Is*d(2&)1y6A=4N)G=mM-wFp(HD77p#F(*DHu_V>Vz{ptF&`8(7 zP{GK^%D~jh)KJgd)Y!n%VDkwnb5TaoCWCDTjI0JsOkbw6Cosx#F@0foWb0x&!*ph1 z!0clA4}cq~I6o;{y~$vRO$1 UWPeF!Zfg6x6vplEQkaCe0p1@?sQ>@~ delta 119 zcmZp8z}fJCbAq&>8Uq7^IuNS@F%uB`Ow=)ERNI)agr8Z2>%?Ss0nLq#Gq^UNkTMr# z6lpTpX28g5z{IRRojrk3mWx@P-I1+}=?v4EiH(Q0e@I|tVVXF>n5)^#o?YD1lCe#H V`@bZ{LyYa8Qy8~@PGREZ1_0Z6AmRW3 diff --git a/src/wishlists/handler/__init__.py b/src/wishlists/handler/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/wishlists/handler/wishlist/__init__.py b/src/wishlists/handler/wishlist/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/wishlists/handler/wishlist/get_wishlist_handler.py b/src/wishlists/handler/wishlist/get_wishlist_handler.py new file mode 100644 index 0000000..a9d477e --- /dev/null +++ b/src/wishlists/handler/wishlist/get_wishlist_handler.py @@ -0,0 +1,16 @@ +from uuid import UUID + +from django.http import Http404 + +from wishlists.models import Wishlist + + +def get_wishlist_by_uuid(uuid: UUID) -> Wishlist: + return Wishlist.objects.get(id=uuid) + + +def get_wishlist_or_404_by_uuid(uuid: UUID) -> Wishlist: + try: + return get_wishlist_by_uuid(uuid) + except Wishlist.DoesNotExist: + raise Http404("This wishlist does not exist.") diff --git a/src/wishlists/models.py b/src/wishlists/models.py index 81d2c05..8728651 100644 --- a/src/wishlists/models.py +++ b/src/wishlists/models.py @@ -17,10 +17,12 @@ class WishlistItem(models.Model): wishlist = models.ForeignKey(Wishlist, on_delete=models.CASCADE) name = models.CharField(max_length=200) description = models.CharField(max_length=2000, null=True) + order = models.IntegerField(null=True) url = models.CharField(max_length=2000, null=True) price = models.FloatField(null=True) image = models.CharField(max_length=2000, blank=True, null=True) gifted = models.BooleanField(default=False) + reveal_date = models.DateTimeField(null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/src/wishlists/templates/owner/index.html b/src/wishlists/templates/owner/index.html new file mode 100644 index 0000000..1d602cf --- /dev/null +++ b/src/wishlists/templates/owner/index.html @@ -0,0 +1,9 @@ +{% if wishlist %} +

{{ wishlist.name }}

+ Created on {{ wishlist.created_at }} + {% if wishlist.description %} +

{{ wishlist.description }}

+ {% endif %} +{% else %} +

Wishlist not found.

+{% endif %} \ No newline at end of file diff --git a/src/wishlists/templates/public/index.html b/src/wishlists/templates/public/index.html index 1d602cf..16790fe 100644 --- a/src/wishlists/templates/public/index.html +++ b/src/wishlists/templates/public/index.html @@ -4,6 +4,34 @@ {% if wishlist.description %}

{{ wishlist.description }}

{% endif %} + + Public link + + + + + + + + + + + + + {% for item in wishlist_items %} + + + + + + + + {% endfor %} + +
ItemPriceLinkPriorityActions
{{ item.name }}{{ item.price }}{{ item.link }}{{ item.priority }} + Edit + Delete +
{% else %}

Wishlist not found.

{% endif %} \ No newline at end of file diff --git a/src/wishlists/views.py b/src/wishlists/views.py index ecdbfec..8017973 100644 --- a/src/wishlists/views.py +++ b/src/wishlists/views.py @@ -1,7 +1,9 @@ from uuid import UUID -from django.http import HttpResponse +from django.http import HttpResponse, Http404 from django.template import loader + +from .handler.wishlist.get_wishlist_handler import get_wishlist_or_404_by_uuid from .models import Wishlist @@ -11,14 +13,15 @@ def index(request): def owner(request, wishlist_id: UUID): - wishlist = Wishlist.objects.get(id=wishlist_id) + wishlist = get_wishlist_or_404_by_uuid(wishlist_id) return HttpResponse(f"You are the owner of wishlist '{wishlist.name}'.") def public(request, wishlist_id: UUID): - wishlist = Wishlist.objects.get(id=wishlist_id) template = loader.get_template("public/index.html") + wishlist = get_wishlist_or_404_by_uuid(wishlist_id) context = { "wishlist": wishlist, + "wishlist_items": wishlist.wishlistitem_set.all(), } return HttpResponse(template.render(context, request))