Compare commits
4 commits
df0129acd3
...
c7cd7c80e4
Author | SHA1 | Date | |
---|---|---|---|
|
c7cd7c80e4 | ||
|
60c834bc69 | ||
|
fc1ed9d71e | ||
|
841aaa989c |
4 changed files with 32 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Offer, Wish
|
from .models import Offer, Wish, PflaenzliUser
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Offer)
|
@admin.register(Offer)
|
||||||
|
@ -10,3 +10,8 @@ class OfferAdmin(admin.ModelAdmin):
|
||||||
@admin.register(Wish)
|
@admin.register(Wish)
|
||||||
class WishAdmin(admin.ModelAdmin):
|
class WishAdmin(admin.ModelAdmin):
|
||||||
list_display = ['id', 'title', 'user']
|
list_display = ['id', 'title', 'user']
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(PflaenzliUser)
|
||||||
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ['id', 'username', 'email', 'zipcode', 'date_joined']
|
||||||
|
|
|
@ -30,9 +30,8 @@
|
||||||
type="text/css">
|
type="text/css">
|
||||||
<link href="{% static 'base.css' %}" rel="stylesheet" type="text/css">
|
<link href="{% static 'base.css' %}" rel="stylesheet" type="text/css">
|
||||||
<script async
|
<script async
|
||||||
defer
|
src="https://analytics2.thisfro.ch/script.js"
|
||||||
data-website-id="4cc39391-553f-45ae-9728-74ee24aa40a1"
|
data-website-id="4cc39391-553f-45ae-9728-74ee24aa40a1"></script>
|
||||||
src="https://analytics2.thisfro.ch/umami.js"></script>
|
|
||||||
<link rel="apple-touch-icon"
|
<link rel="apple-touch-icon"
|
||||||
sizes="180x180"
|
sizes="180x180"
|
||||||
href="{% static 'favicon/apple-touch-icon.png' %}">
|
href="{% static 'favicon/apple-touch-icon.png' %}">
|
||||||
|
|
|
@ -18,6 +18,7 @@ urlpatterns = [
|
||||||
path("accounts/<int:user_id>/wishlist/", views.wishlist, name="wishlist"),
|
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/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/', 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/register/', views.register_user, name='register_user'),
|
||||||
path('accounts/password_reset/', auth_views.PasswordResetView.as_view(template_name='registration/verify_email.html',
|
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'),
|
extra_context={'form_helper': settings.CRISPY_TEMPLATE_PACK}), name='password_reset'),
|
||||||
|
|
|
@ -46,12 +46,18 @@ def create_offer(request):
|
||||||
return render(request, "basic_form.html", {"form": form, "button_label": "Create", "title": "Create Offer"})
|
return render(request, "basic_form.html", {"form": form, "button_label": "Create", "title": "Create Offer"})
|
||||||
|
|
||||||
|
|
||||||
@ login_required
|
|
||||||
def offer_detail(request, offer_id):
|
def offer_detail(request, offer_id):
|
||||||
offer = get_object_or_404(Offer, id=offer_id)
|
offer = get_object_or_404(Offer, id=offer_id)
|
||||||
wishes = Wish.objects.filter(user=offer.user)
|
wishes = Wish.objects.filter(user=offer.user)
|
||||||
if offer.zipcode and request.user.zipcode:
|
|
||||||
dist = calculate_distance(offer.zipcode, request.user.zipcode)
|
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:
|
else:
|
||||||
dist = None
|
dist = None
|
||||||
|
|
||||||
|
@ -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})
|
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
|
@csrf_protect
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue