Some more basic stuff

This commit is contained in:
Maximilian Giller 2023-12-01 23:55:38 +01:00
parent 53d83a7855
commit c0f8cc02d2
8 changed files with 61 additions and 3 deletions

Binary file not shown.

View file

View file

@ -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.")

View file

@ -17,10 +17,12 @@ class WishlistItem(models.Model):
wishlist = models.ForeignKey(Wishlist, on_delete=models.CASCADE) wishlist = models.ForeignKey(Wishlist, on_delete=models.CASCADE)
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
description = models.CharField(max_length=2000, null=True) description = models.CharField(max_length=2000, null=True)
order = models.IntegerField(null=True)
url = models.CharField(max_length=2000, null=True) url = models.CharField(max_length=2000, null=True)
price = models.FloatField(null=True) price = models.FloatField(null=True)
image = models.CharField(max_length=2000, blank=True, null=True) image = models.CharField(max_length=2000, blank=True, null=True)
gifted = models.BooleanField(default=False) gifted = models.BooleanField(default=False)
reveal_date = models.DateTimeField(null=True)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)

View file

@ -0,0 +1,9 @@
{% if wishlist %}
<h1>{{ wishlist.name }}</h1>
<sub>Created on {{ wishlist.created_at }}</sub>
{% if wishlist.description %}
<p>{{ wishlist.description }}</p>
{% endif %}
{% else %}
<p>Wishlist not found.</p>
{% endif %}

View file

@ -4,6 +4,34 @@
{% if wishlist.description %} {% if wishlist.description %}
<p>{{ wishlist.description }}</p> <p>{{ wishlist.description }}</p>
{% endif %} {% endif %}
<a href="{% url 'public' wishlist.id %}">Public link</a>
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Link</th>
<th>Priority</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for item in wishlist_items %}
<tr>
<td>{{ item.name }}</td>
<td>{{ item.price }}</td>
<td><a href="{{ item.link }}">{{ item.link }}</a></td>
<td>{{ item.priority }}</td>
<td>
<a href="/items/{{ item.id }}/edit">Edit</a>
<a href="/items/{{ item.id }}/delete">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %} {% else %}
<p>Wishlist not found.</p> <p>Wishlist not found.</p>
{% endif %} {% endif %}

View file

@ -1,7 +1,9 @@
from uuid import UUID from uuid import UUID
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.template import loader from django.template import loader
from .handler.wishlist.get_wishlist_handler import get_wishlist_or_404_by_uuid
from .models import Wishlist from .models import Wishlist
@ -11,14 +13,15 @@ def index(request):
def owner(request, wishlist_id: UUID): 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}'.") return HttpResponse(f"You are the owner of wishlist '{wishlist.name}'.")
def public(request, wishlist_id: UUID): def public(request, wishlist_id: UUID):
wishlist = Wishlist.objects.get(id=wishlist_id)
template = loader.get_template("public/index.html") template = loader.get_template("public/index.html")
wishlist = get_wishlist_or_404_by_uuid(wishlist_id)
context = { context = {
"wishlist": wishlist, "wishlist": wishlist,
"wishlist_items": wishlist.wishlistitem_set.all(),
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))