diff --git a/pflaenzli/pflaenzli/forms.py b/pflaenzli/pflaenzli/forms.py
index e334684..2e7d651 100644
--- a/pflaenzli/pflaenzli/forms.py
+++ b/pflaenzli/pflaenzli/forms.py
@@ -3,7 +3,7 @@ from django.contrib.auth.forms import UserCreationForm
from django.utils.safestring import mark_safe
from friendly_captcha.fields import FrcCaptchaField
-from .models import Offer, PflaenzliUser
+from .models import Offer, PflaenzliUser, Wish
class CreateOfferForm(forms.ModelForm):
@@ -27,3 +27,9 @@ class FilterForm(forms.Form):
' Zipcode'))
distance = forms.IntegerField(required=False, label=mark_safe(
' Distance (km)'))
+
+
+class WishForm(forms.ModelForm):
+ class Meta:
+ model = Wish
+ fields = ['title']
diff --git a/pflaenzli/pflaenzli/templates/user/wish.html b/pflaenzli/pflaenzli/templates/user/wish.html
new file mode 100644
index 0000000..b5573a1
--- /dev/null
+++ b/pflaenzli/pflaenzli/templates/user/wish.html
@@ -0,0 +1,44 @@
+{% extends 'base.html' %}
+{% load crispy_forms_tags %}
+{% block title %}Whishlist{% endblock %}
+{% block content %}
+
+
{{ title }} Wishlist
+
+
+ {% if wishes %}
+
+ {% for wish in wishes %}
+ -
+ {{ wish.title }}
+ {% if own %}
+
+
+
+ {% endif %}
+
+ {% endfor %}
+
+ {% else %}
+
There are currently no wishes!
+ {% endif %}
+
+ {% if form %}
+
+
+
+ New wish
+
+
+
+ {% endif %}
+{% endblock %}
diff --git a/pflaenzli/pflaenzli/templates/user/wish.html.twig b/pflaenzli/pflaenzli/templates/user/wish.html.twig
deleted file mode 100644
index e1f0099..0000000
--- a/pflaenzli/pflaenzli/templates/user/wish.html.twig
+++ /dev/null
@@ -1,45 +0,0 @@
-{% extends 'base.html.twig' %}
-
-{% block title %}Whishlist{% endblock %}
-
-{% block content %}
- {% for message in app.flashes('error') %}
-
- {{ message }}
-
- {% endfor %}
- {% for message in app.flashes('success') %}
-
- {{ message }}
-
- {% endfor %}
-
-
-
Your Wishlist
-
-
-
- {% if wishes == [] %}
-
- There are currently no wishes!
-
- {% else %}
-
- {% for wish in wishes %}
- - {{ wish.title }}
-
-
-
-
- {% endfor %}
-
- {% endif %}
-
-
-
-
-
-
New wish
- {{ form(wish_form) }}
-
-{% endblock %}
\ No newline at end of file
diff --git a/pflaenzli/pflaenzli/urls.py b/pflaenzli/pflaenzli/urls.py
index 38054ae..b156859 100644
--- a/pflaenzli/pflaenzli/urls.py
+++ b/pflaenzli/pflaenzli/urls.py
@@ -15,10 +15,12 @@ urlpatterns = [
path("offer//edit/", views.offer_edit, name="offer_edit"),
path("offer//trade/", views.offer_trade, name="offer_trade"),
path("accounts/", views.user_detail, name="user_detail"),
+ path("accounts//wishlist/", views.wishlist, name="wishlist"),
path('accounts/login/', auth_views.LoginView.as_view(template_name='registration/login.html')),
path('accounts/profile/', auth_views.LoginView.as_view(template_name='user/detail.html'), name='user_profile'),
path('accounts/register/', views.register_user, name='register_user'),
path('accounts/', include('django.contrib.auth.urls')),
path("faq/", TemplateView.as_view(template_name='app/faq.html'), name="faq"),
path("imprint/", TemplateView.as_view(template_name='app/imprint.html'), name="imprint"),
+ path("wish/delete/", views.delete_wish, name='delete_wish'),
]
diff --git a/pflaenzli/pflaenzli/views.py b/pflaenzli/pflaenzli/views.py
index 480c502..980f597 100644
--- a/pflaenzli/pflaenzli/views.py
+++ b/pflaenzli/pflaenzli/views.py
@@ -1,11 +1,13 @@
-from django.shortcuts import render, get_object_or_404, redirect
+from django.shortcuts import render, get_object_or_404, redirect, reverse
from django.utils import timezone
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.auth.decorators import login_required
+from django.views.decorators.csrf import csrf_protect
+from django.views.decorators.http import require_POST
from django.http import HttpResponseForbidden
-from .forms import CreateOfferForm, RegistrationForm, FilterForm
+from .forms import CreateOfferForm, RegistrationForm, FilterForm, WishForm
from .models import PflaenzliUser, Offer, Wish
from .mail import send_offer_email
@@ -88,6 +90,43 @@ def offer_edit(request, offer_id):
return render(request, "basic_form.html", {"form": form, "button_label": "Update", "title": "Edit Offer"})
+@login_required
+def wishlist(request, user_id):
+ wishes = Wish.objects.filter(user=user_id)
+
+ if user_id == request.user.id:
+ title = "Your"
+ if request.method == "POST":
+ form = WishForm(request.POST)
+ if form.is_valid():
+ wish = form.save(commit=False)
+ wish.user = request.user
+ wish.save()
+ messages.success(request, "Wish added successfully!")
+ form = WishForm()
+ else:
+ form = None
+ user = get_object_or_404(PflaenzliUser, id=user_id)
+ title = f"{user.username}'s"
+
+ return render(request, "user/wish.html", {"title": title, "form": form, "wishes": wishes, "own": user_id == request.user.id})
+
+
+@csrf_protect
+@require_POST
+@login_required
+def delete_wish(request, wish_id):
+ wish = get_object_or_404(Wish, id=wish_id)
+
+ if wish.user != request.user:
+ messages.error(request, "You don't have permission to delete this wish!")
+ return redirect("wishlist", request.user.id)
+
+ wish.delete()
+
+ return redirect("wishlist", request.user.id)
+
+
@login_required
def offer_trade(request, offer_id):
offer = get_object_or_404(Offer, id=offer_id)