|
|
@@ -8,10 +8,18 @@ from django.contrib.auth.decorators import login_required
|
|
8
|
8
|
|
|
9
|
9
|
from fruit.models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorProduct
|
|
10
|
10
|
|
|
11
|
|
-from .forms import StoreForm, ProductForm, InboxForm, SaleForm, PhotoFormSet,VendorFilter, InlinePhotoFormset, ProductSKUForm, ProductFilter, SaleFilter, InboxFilter, VendorForm, VendorOrderForm, VendorOrderFilter, VendorOrder, InlineVendorProductFormset, VendorProductForm
|
|
|
11
|
+from .forms import StoreForm, ProductForm, InboxForm, SaleForm, PhotoFormSet,VendorFilter, InlinePhotoFormset, ProductSKUForm, ProductFilter, SaleFilter, InboxFilter, VendorForm, VendorOrderForm, VendorOrderFilter, VendorOrder, InlineVendorProductFormset, VendorProductForm, SignUpForm
|
|
12
|
12
|
from django.contrib import messages
|
|
13
|
13
|
from django.core.paginator import Paginator
|
|
14
|
14
|
|
|
|
15
|
+from django.utils.encoding import force_bytes, force_text
|
|
|
16
|
+from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
|
|
17
|
+from django.template.loader import render_to_string
|
|
|
18
|
+from .tokens import account_activation_token
|
|
|
19
|
+
|
|
|
20
|
+
|
|
|
21
|
+from django.contrib.auth.models import User
|
|
|
22
|
+
|
|
15
|
23
|
|
|
16
|
24
|
def index(request):
|
|
17
|
25
|
return render(request, 'fruit/index.html')
|
|
|
@@ -304,7 +312,7 @@ def vendor_create(request):
|
|
304
|
312
|
|
|
305
|
313
|
form = VendorForm()
|
|
306
|
314
|
|
|
307
|
|
- form.fields['products'].queryset = stores[0].product_set.all().order_by("-created_at")
|
|
|
315
|
+ #form.fields['products'].queryset = stores[0].product_set.all().order_by("-created_at")
|
|
308
|
316
|
|
|
309
|
317
|
if request.method == "POST":
|
|
310
|
318
|
form = VendorForm(request.POST)
|
|
|
@@ -417,7 +425,7 @@ def vendororder_edit(request, pk):
|
|
417
|
425
|
|
|
418
|
426
|
obj = VendorOrder.objects.get(pk=pk)
|
|
419
|
427
|
form = VendorOrderForm(instance = obj)
|
|
420
|
|
-
|
|
|
428
|
+ form.fields['vendor'].queryset = stores[0].vendor_set.all().order_by("-created_at")
|
|
421
|
429
|
#form.fields['product'].queryset = stores[0].product_set.all().order_by("-created_at")
|
|
422
|
430
|
|
|
423
|
431
|
if request.method == "POST":
|
|
|
@@ -445,7 +453,8 @@ def vendororder_create(request):
|
|
445
|
453
|
stores = request.user.store_created.all().order_by("-created_at")
|
|
446
|
454
|
|
|
447
|
455
|
form = VendorOrderForm()
|
|
448
|
|
-
|
|
|
456
|
+ form.fields['vendor'].queryset = stores[0].vendor_set.all().order_by("-created_at")
|
|
|
457
|
+ #form = stores[0].vendor_set.all()
|
|
449
|
458
|
|
|
450
|
459
|
if request.method == "POST":
|
|
451
|
460
|
form = VendorOrderForm(request.POST)
|
|
|
@@ -472,14 +481,41 @@ def vendororder_create(request):
|
|
472
|
481
|
|
|
473
|
482
|
def signup(request):
|
|
474
|
483
|
if request.method == 'POST':
|
|
475
|
|
- form = UserCreationForm(request.POST)
|
|
|
484
|
+ form = SignUpForm(request.POST)
|
|
476
|
485
|
if form.is_valid():
|
|
477
|
|
- form.save()
|
|
478
|
|
- username = form.cleaned_data.get('username')
|
|
479
|
|
- raw_password = form.cleaned_data.get('password1')
|
|
480
|
|
- user = authenticate(username=username, password=raw_password)
|
|
481
|
|
- login(request, user)
|
|
482
|
|
- return redirect('front:index')
|
|
|
486
|
+ user = form.save(commit=False)
|
|
|
487
|
+ user.is_active = False
|
|
|
488
|
+ user.save()
|
|
|
489
|
+ current_site = "https://localhost:8000"
|
|
|
490
|
+ subject = 'Activate Your MySite Account'
|
|
|
491
|
+ message = render_to_string('fruit/account_activation_email.html', {
|
|
|
492
|
+ 'user': user,
|
|
|
493
|
+ 'domain': current_site,
|
|
|
494
|
+ 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
|
|
|
495
|
+ 'token': account_activation_token.make_token(user),
|
|
|
496
|
+ })
|
|
|
497
|
+ user.email_user(subject, message)
|
|
|
498
|
+ return redirect('fruit:account_activation_sent')
|
|
|
499
|
+
|
|
483
|
500
|
else:
|
|
484
|
|
- form = UserCreationForm()
|
|
|
501
|
+ form = SignUpForm()
|
|
485
|
502
|
return render(request, 'fruit/signup.html', {'form': form})
|
|
|
503
|
+
|
|
|
504
|
+def activate(request, uidb64, token):
|
|
|
505
|
+ try:
|
|
|
506
|
+ uid = force_text(urlsafe_base64_decode(uidb64))
|
|
|
507
|
+ user = User.objects.get(pk=uid)
|
|
|
508
|
+ except (TypeError, ValueError, OverflowError, User.DoesNotExist):
|
|
|
509
|
+ user = None
|
|
|
510
|
+
|
|
|
511
|
+ if user is not None and account_activation_token.check_token(user, token):
|
|
|
512
|
+ user.is_active = True
|
|
|
513
|
+ user.profile.email_confirmed = True
|
|
|
514
|
+ user.save()
|
|
|
515
|
+ login(request, user)
|
|
|
516
|
+ return redirect('front:index')
|
|
|
517
|
+ else:
|
|
|
518
|
+ return render(request, 'account_activation_invalid.html')
|
|
|
519
|
+
|
|
|
520
|
+def account_activation_sent(request):
|
|
|
521
|
+ return render(request, "fruit/account_activation_sent.html")
|