1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- from django.shortcuts import render, redirect
- from django.views.generic import View
- from django.contrib import messages
- from .forms import UserRegisterForm
- from .models import UserAccount
- from gauth.models import Location
- class RegistrationView(View):
- def get(self, request, *args, **kwargs):
- form = UserRegisterForm()
- return render(request, 'signup.html', {'form': form})
- def post(self, request, *args, **kwargs):
- form = UserRegisterForm(request.POST)
- if form.is_valid():
- email = form.cleaned_data.get('email')
- location = Location.objects.filter(recipient_email=email).first()
- if location:
- user = form.save()
- UserAccount.objects.create(user=user, location=location)
- messages.success(request, f'Your account has been created! You are now able to log in')
- return redirect('login')
- else:
- messages.warning(request, f'Sorry, We don\'t have any location with this email!')
- return render(request, 'signup.html', {'form': form})
- class LocationAnalytics(View):
- def get(self, requests, *args, **kwargs):
- context = {
- 'google_pos': 400,
- 'google_neg': 60,
- 'google_pos_gr': -5,
- 'google_neg_gr': -3,
- 'yelp_pos': 323,
- 'yelp_neg': 32,
- 'yelp_pos_gr': -2.4,
- 'yelp_neg_gr': 4,
- 'facebook_pos': 430,
- 'facebook_neg': 40,
- 'facebook_pos_gr': 2.5,
- 'facebook_neg_gr': -2.3,
- }
- return render(requests, 'user-dashboard.html', context=context)
|