diff --git a/src/db.sqlite3 b/src/db.sqlite3 index 10b17e9..f1e11f6 100644 Binary files a/src/db.sqlite3 and b/src/db.sqlite3 differ 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))