Compare commits

...

4 commits

Author SHA1 Message Date
Jannis Portmann
c7cd7c80e4 Update umami 2023-04-26 15:47:57 +02:00
Jannis Portmann
60c834bc69 Allow offer view when not logged in 2023-04-26 15:31:14 +02:00
Jannis Portmann
fc1ed9d71e Allow users to update settings 2023-04-26 15:26:17 +02:00
Jannis Portmann
841aaa989c Add user to admin 2023-04-26 15:25:36 +02:00
4 changed files with 32 additions and 7 deletions

View file

@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Offer, Wish
from .models import Offer, Wish, PflaenzliUser
@admin.register(Offer)
@ -10,3 +10,8 @@ class OfferAdmin(admin.ModelAdmin):
@admin.register(Wish)
class WishAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'user']
@admin.register(PflaenzliUser)
class UserAdmin(admin.ModelAdmin):
list_display = ['id', 'username', 'email', 'zipcode', 'date_joined']

View file

@ -30,9 +30,8 @@
type="text/css">
<link href="{% static 'base.css' %}" rel="stylesheet" type="text/css">
<script async
defer
data-website-id="4cc39391-553f-45ae-9728-74ee24aa40a1"
src="https://analytics2.thisfro.ch/umami.js"></script>
src="https://analytics2.thisfro.ch/script.js"
data-website-id="4cc39391-553f-45ae-9728-74ee24aa40a1"></script>
<link rel="apple-touch-icon"
sizes="180x180"
href="{% static 'favicon/apple-touch-icon.png' %}">

View file

@ -18,6 +18,7 @@ urlpatterns = [
path("accounts/<int:user_id>/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/profile/edit', views.user_edit, name='user_edit'),
path('accounts/register/', views.register_user, name='register_user'),
path('accounts/password_reset/', auth_views.PasswordResetView.as_view(template_name='registration/verify_email.html',
extra_context={'form_helper': settings.CRISPY_TEMPLATE_PACK}), name='password_reset'),

View file

@ -46,14 +46,20 @@ def create_offer(request):
return render(request, "basic_form.html", {"form": form, "button_label": "Create", "title": "Create Offer"})
@ login_required
def offer_detail(request, offer_id):
offer = get_object_or_404(Offer, id=offer_id)
wishes = Wish.objects.filter(user=offer.user)
if request.user.is_authenticated:
if offer.zipcode and request.user.zipcode:
if offer.zipcode == request.user.zipcode:
dist = 0
else:
dist = calculate_distance(offer.zipcode, request.user.zipcode)
else:
dist = None
else:
dist = None
return render(request, "offer/detail.html", {"offer": offer, "wishes": wishes, "dist": dist})
@ -112,6 +118,20 @@ def wishlist(request, user_id):
return render(request, "user/wish.html", {"title": title, "form": form, "wishes": wishes, "own": user_id == request.user.id})
@login_required
def user_edit(request):
if request.method == "POST":
form = RegistrationForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
messages.success(request, "Account details updated successfully!")
return redirect("user_profile")
else:
form = RegistrationForm(instance=request.user)
return render(request, "basic_form.html", {"form": form, "button_label": "Save", "title": "Edit Account Details"})
@csrf_protect
@require_POST
@login_required