|
1
|
|
|
from django.views.generic import TemplateView |
|
2
|
|
|
from django.http import HttpResponseRedirect |
|
3
|
|
|
from wye.organisations.models import Organisation |
|
4
|
|
|
from wye.profiles.models import Profile |
|
5
|
|
|
from wye.workshops.models import Workshop |
|
6
|
|
|
|
|
7
|
|
|
from .constants import WorkshopStatus |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class HomePageView(TemplateView): |
|
11
|
|
|
template_name = 'index.html' |
|
12
|
|
|
|
|
13
|
|
|
def get_context_data(self, **kwargs): |
|
14
|
|
|
context = super(HomePageView, self).get_context_data(**kwargs) |
|
15
|
|
|
organisationObj = Organisation.objects.filter(active=True) |
|
16
|
|
|
workshopObj = Workshop.objects.filter(is_active=True) |
|
17
|
|
|
context['organisation_registered_count'] = organisationObj.count() |
|
18
|
|
|
context['completed_workshop_count'] = workshopObj.filter( |
|
19
|
|
|
status=WorkshopStatus.COMPLETED).count() |
|
20
|
|
|
context['requested_workshop_count'] = workshopObj.count() |
|
21
|
|
|
context['tutor_registered_count'] = Profile.objects.filter( |
|
22
|
|
|
usertype__slug="tutor").count() |
|
23
|
|
|
return context |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def verify_user_profile(f): |
|
27
|
|
|
''' |
|
28
|
|
|
This decorator check whether the user are valid for certain views |
|
29
|
|
|
''' |
|
30
|
|
|
def wrap(request, *args, **kwargs): |
|
31
|
|
|
user_profile, created = Profile.objects.get_or_create( |
|
32
|
|
|
user__id=request.user.id) |
|
33
|
|
|
if not user_profile.is_profile_filled: |
|
34
|
|
|
return HttpResponseRedirect( |
|
35
|
|
|
'/profile/{}/edit'.format(request.user.username)) |
|
36
|
|
|
return f(request, *args, **kwargs) |
|
37
|
|
|
return wrap |
|
38
|
|
|
|