|
1
|
|
|
from datetime import datetime |
|
2
|
|
|
|
|
3
|
|
|
from django import template |
|
4
|
|
|
from wye.base.constants import WorkshopStatus, FeedbackType |
|
5
|
|
|
from wye.profiles.models import Profile |
|
6
|
|
|
|
|
7
|
|
|
register = template.Library() |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
def show_feedback_button(workshop, user): |
|
11
|
|
|
if (workshop.status == WorkshopStatus.COMPLETED or |
|
12
|
|
|
datetime.now().date() > workshop.expected_date): |
|
13
|
|
|
if (workshop.is_presenter(user) and |
|
14
|
|
|
workshop.workshopfeedback_set.filter( |
|
15
|
|
|
feedback_type=FeedbackType.PRESENTER).count() <= 0 or |
|
16
|
|
|
(workshop.is_organiser(user) and |
|
17
|
|
|
workshop.workshopfeedback_set.filter( |
|
18
|
|
|
feedback_type=FeedbackType.ORGANISATION).count() <= 0)): |
|
19
|
|
|
return True |
|
20
|
|
|
else: |
|
21
|
|
|
return False |
|
22
|
|
|
return False |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def show_draft_button(workshop, user): |
|
26
|
|
|
if (workshop.status in [WorkshopStatus.REQUESTED, |
|
27
|
|
|
WorkshopStatus.ACCEPTED, |
|
28
|
|
|
WorkshopStatus.DECLINED] and |
|
29
|
|
|
user in workshop.requester.user.all() and |
|
30
|
|
|
not show_feedback_button(workshop, user)): |
|
31
|
|
|
return True |
|
32
|
|
|
return False |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
def show_requested_button(workshop, user): |
|
36
|
|
|
if (workshop.status == WorkshopStatus.HOLD and |
|
37
|
|
|
user in workshop.requester.user.all() and |
|
38
|
|
|
not show_feedback_button(workshop, user)): |
|
39
|
|
|
|
|
40
|
|
|
return True |
|
41
|
|
|
return False |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def show_accepted_button(workshop, user): |
|
45
|
|
|
if (workshop.status == WorkshopStatus.REQUESTED): |
|
46
|
|
|
return True |
|
47
|
|
|
return False |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
def show_reject_button(workshop, user): |
|
51
|
|
|
if (workshop.status == WorkshopStatus.ACCEPTED and |
|
52
|
|
|
user in workshop.presenter.all() and |
|
53
|
|
|
not show_feedback_button(workshop, user)): |
|
54
|
|
|
|
|
55
|
|
|
return True |
|
56
|
|
|
return False |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
def show_decline_button(workshop, user): |
|
60
|
|
|
neglected_workshops = [WorkshopStatus.COMPLETED, |
|
61
|
|
|
WorkshopStatus.FEEDBACK_PENDING, |
|
62
|
|
|
WorkshopStatus.DECLINED] |
|
63
|
|
|
if (workshop.status not in neglected_workshops and |
|
64
|
|
|
user in workshop.requester.user.all() and |
|
65
|
|
|
not show_feedback_button(workshop, user)): |
|
66
|
|
|
return True |
|
67
|
|
|
return False |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
def show_volunteer_count(workshop, user): |
|
71
|
|
|
if workshop.status >= WorkshopStatus.ACCEPTED: |
|
72
|
|
|
return True |
|
73
|
|
|
return False |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
def show_accept_volunteer_button(workshop, user): |
|
77
|
|
|
number_of_volunteers = 0 if ( |
|
78
|
|
|
not workshop.number_of_volunteers) else workshop.number_of_volunteers |
|
79
|
|
|
if Profile.is_volunteer(user) and \ |
|
80
|
|
|
number_of_volunteers - workshop.volunteer.count() >= 1 and \ |
|
81
|
|
|
user not in workshop.volunteer.all() and \ |
|
82
|
|
|
user not in workshop.requester.user.all(): |
|
83
|
|
|
return True |
|
84
|
|
|
return False |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
def show_opt_out_volunteer_button(workshop, user): |
|
88
|
|
|
if user in workshop.volunteer.all(): |
|
89
|
|
|
return True |
|
90
|
|
|
return False |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
register.filter(show_accepted_button) |
|
94
|
|
|
register.filter(show_requested_button) |
|
95
|
|
|
register.filter(show_draft_button) |
|
96
|
|
|
register.filter(show_reject_button) |
|
97
|
|
|
register.filter(show_decline_button) |
|
98
|
|
|
register.filter(show_volunteer_count) |
|
99
|
|
|
register.filter(show_accept_volunteer_button) |
|
100
|
|
|
register.filter(show_feedback_button) |
|
101
|
|
|
register.filter(show_opt_out_volunteer_button) |
|
102
|
|
|
|