views.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from django.shortcuts import render, redirect
  2. from django.views.generic import View
  3. from django.contrib import messages
  4. from .forms import UserRegisterForm
  5. from .models import UserAccount
  6. from gauth.models import Location
  7. class RegistrationView(View):
  8. def get(self, request, *args, **kwargs):
  9. form = UserRegisterForm()
  10. return render(request, 'signup.html', {'form': form})
  11. def post(self, request, *args, **kwargs):
  12. form = UserRegisterForm(request.POST)
  13. if form.is_valid():
  14. email = form.cleaned_data.get('email')
  15. location = Location.objects.filter(recipient_email=email).first()
  16. if location:
  17. user = form.save()
  18. UserAccount.objects.create(user=user, location=location)
  19. messages.success(request, f'Your account has been created! You are now able to log in')
  20. return redirect('login')
  21. else:
  22. messages.warning(request, f'Sorry, We don\'t have any location with this email!')
  23. return render(request, 'signup.html', {'form': form})
  24. class LocationAnalytics(View):
  25. def get(self, requests, *args, **kwargs):
  26. context = {
  27. 'labels': ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
  28. }
  29. return render(requests, 'user-dashboard.html', context=context)