18
18
from django .views .generic import ListView
19
19
from django .utils .decorators import method_decorator
20
20
from django .core .urlresolvers import reverse_lazy
21
-
21
+ from volunteer . utils import vol_id_check
22
22
23
23
class AdministratorLoginRequiredMixin (object ):
24
24
@@ -568,6 +568,10 @@ def sign_up(request, shift_id, volunteer_id):
568
568
class ViewHoursView (LoginRequiredMixin , FormView , TemplateView ):
569
569
template_name = 'shift/hours_list.html'
570
570
571
+ @method_decorator (vol_id_check )
572
+ def dispatch (self , * args , ** kwargs ):
573
+ return super (ViewHoursView , self ).dispatch (* args , ** kwargs )
574
+
571
575
def get_context_data (self , ** kwargs ):
572
576
context = super (ViewHoursView , self ).get_context_data (** kwargs )
573
577
volunteer_id = self .kwargs ['volunteer_id' ]
@@ -577,36 +581,15 @@ def get_context_data(self, **kwargs):
577
581
578
582
579
583
@login_required
584
+ @vol_id_check
580
585
def view_volunteer_shifts (request , volunteer_id ):
581
- user = request .user
582
- vol = None
583
-
584
- try :
585
- vol = user .volunteer
586
- except ObjectDoesNotExist :
587
- pass
586
+ shift_list = get_unlogged_shifts_by_volunteer_id (volunteer_id )
587
+ return render (
588
+ request ,
589
+ 'shift/volunteer_shifts.html' ,
590
+ {'shift_list' : shift_list , 'volunteer_id' : volunteer_id , }
591
+ )
588
592
589
- # check that a volunteer is logged in
590
- if vol :
591
- if volunteer_id :
592
- volunteer = get_volunteer_by_id (volunteer_id )
593
- if volunteer :
594
- user = request .user
595
- if int (user .volunteer .id ) == int (volunteer_id ):
596
- shift_list = get_unlogged_shifts_by_volunteer_id (volunteer_id )
597
- return render (
598
- request ,
599
- 'shift/volunteer_shifts.html' ,
600
- {'shift_list' : shift_list , 'volunteer_id' : volunteer_id , }
601
- )
602
- else :
603
- return HttpResponse (status = 403 )
604
- else :
605
- raise Http404
606
- else :
607
- raise Http404
608
- else :
609
- return HttpResponse (status = 403 )
610
593
611
594
612
595
class VolunteerSearchView (AdministratorLoginRequiredMixin , FormView ):
0 commit comments