|
@@ -2,7 +2,7 @@ from django.http import Http404
|
|
from django.shortcuts import render, redirect
|
|
from django.shortcuts import render, redirect
|
|
from django.views.generic import View
|
|
from django.views.generic import View
|
|
from django.contrib import messages
|
|
from django.contrib import messages
|
|
-from .forms import UserRegisterForm
|
|
|
|
|
|
+from .forms import UserRegisterForm, StaffRegistrationForm
|
|
from .models import UserAccount
|
|
from .models import UserAccount
|
|
from gauth.models import Location
|
|
from gauth.models import Location
|
|
from review.models import Review
|
|
from review.models import Review
|
|
@@ -130,9 +130,34 @@ class ReviewAnalyticsGraph(View):
|
|
|
|
|
|
class StaffLeaderBoard(View):
|
|
class StaffLeaderBoard(View):
|
|
|
|
|
|
- def get(self, requests, *args, **kwargs):
|
|
|
|
- staffs = Staff.objects.filter(location=requests.user.useraccount.location).order_by('-total_units')
|
|
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ staffs = Staff.objects.filter(location=request.user.useraccount.location).order_by('-total_units')
|
|
|
|
+ form = StaffRegistrationForm()
|
|
|
|
+
|
|
|
|
+ context = {
|
|
|
|
+ 'staffs': staffs,
|
|
|
|
+ 'form': form
|
|
|
|
+ }
|
|
|
|
+ return render(request, 'staff_list.html', context)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ staffs = Staff.objects.filter(location=request.user.useraccount.location).order_by('-total_units')
|
|
|
|
+ form = StaffRegistrationForm(request.POST)
|
|
|
|
+ if form.is_valid():
|
|
|
|
+ name = form.cleaned_data.get('name')
|
|
|
|
+ department = form.cleaned_data.get('department')
|
|
|
|
+ nick_names = form.cleaned_data.get('nick_names')
|
|
|
|
+ location_id = request.user.useraccount.location_id
|
|
|
|
+ staff = Staff.objects.create(
|
|
|
|
+ name=name,
|
|
|
|
+ location_id=location_id,
|
|
|
|
+ department=department,
|
|
|
|
+ nick_names=nick_names
|
|
|
|
+ )
|
|
|
|
+ messages.success(request, f'A new staff {staff} has been created!')
|
|
|
|
+
|
|
context = {
|
|
context = {
|
|
- 'staffs': staffs
|
|
|
|
|
|
+ 'staffs': staffs,
|
|
|
|
+ 'form': form
|
|
}
|
|
}
|
|
- return render(requests, 'staff_list.html', context)
|
|
|
|
|
|
+ return render(request, 'staff_list.html', context)
|