You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
xmrauctions/core/views.py

44 lines
1.5 KiB
Python

from django.shortcuts import render, HttpResponseRedirect, reverse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages
from core.forms import UserShippingAddressForm
from core.models import UserShippingAddress
from core.monero import AuctionDaemon
def home(request):
daemon = AuctionDaemon()
if daemon.connected:
daemon_info = daemon.daemon.info()
else:
daemon_info = False
return render(request, 'home.html', {'daemon_info': daemon_info})
@login_required
def edit_shipping(request):
profile = UserShippingAddress.objects.filter(user=request.user).first()
if request.method == 'POST':
form = UserShippingAddressForm(request.POST, instance=profile)
if form.is_valid():
saved_profile = form.save(commit=False)
saved_profile.user = request.user
saved_profile.save()
messages.success(request, 'Profile updated.')
return HttpResponseRedirect(reverse('home'))
else:
messages.error(request, 'Unable to save shipping information.')
form_errors = form.errors.get_json_data()
for err in form_errors:
err_data = form_errors[err][0]
messages.error(request, f'{err}: {err_data["message"]}')
context = {
'form': UserShippingAddressForm(instance=profile)
}
return render(request, 'core/edit_shipping.html', context)