HomePageView   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_context_data() 0 21 1
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
        workshopObj = workshopObj.filter(status__in=[
21
            WorkshopStatus.REQUESTED,
22
            WorkshopStatus.ACCEPTED,
23
            WorkshopStatus.DECLINED])
24
        workshop_list = Workshop.objects.filter(
25
            is_active=True
26
        ).filter(
27
            status__in=[WorkshopStatus.REQUESTED, WorkshopStatus.ACCEPTED]
28
        ).order_by('expected_date')
29
        context['requested_workshop_count'] = workshopObj.count()
30
        context['tutor_registered_count'] = Profile.objects.filter(
31
            usertype__slug="tutor").count()
32
        context['upcoming_workshops'] = workshop_list
33
        return context
34
35
36
def verify_user_profile(f):
37
    '''
38
    This decorator check  whether the user are valid for certain views
39
    '''
40
    def wrap(request, *args, **kwargs):
41
        user_profile, created = Profile.objects.get_or_create(
42
            user__id=request.user.id)
43
        if not user_profile.is_profile_filled:
44
            return HttpResponseRedirect(
45
                '/profile/{}/edit'.format(request.user.username))
46
        return f(request, *args, **kwargs)
47
    return wrap
48