@@ -29,9 +29,19 @@ def landing_page(request):
29
29
30
30
class LeadListView (LoginRequiredMixin , generic .ListView ):
31
31
template_name = "leads/lead_list.html"
32
- queryset = Lead .objects .all ()
33
32
context_object_name = "leads"
34
33
34
+ def get_queryset (self ):
35
+ user = self .request .user
36
+ # initial queryset of leads for the entire organisation
37
+ if user .is_organisor :
38
+ queryset = Lead .objects .filter (organisation = user .userprofile )
39
+ else :
40
+ queryset = Lead .objects .filter (organisation = user .agent .organisation )
41
+ # filter for the agent that is logged in
42
+ queryset = queryset .filter (agent__user = user )
43
+ return queryset
44
+
35
45
36
46
def lead_list (request ):
37
47
leads = Lead .objects .all ()
@@ -43,9 +53,19 @@ def lead_list(request):
43
53
44
54
class LeadDetailView (LoginRequiredMixin , generic .DetailView ):
45
55
template_name = "leads/lead_detail.html"
46
- queryset = Lead .objects .all ()
47
56
context_object_name = "lead"
48
57
58
+ def get_queryset (self ):
59
+ user = self .request .user
60
+ # initial queryset of leads for the entire organisation
61
+ if user .is_organisor :
62
+ queryset = Lead .objects .filter (organisation = user .userprofile )
63
+ else :
64
+ queryset = Lead .objects .filter (organisation = user .agent .organisation )
65
+ # filter for the agent that is logged in
66
+ queryset = queryset .filter (agent__user = user )
67
+ return queryset
68
+
49
69
50
70
def lead_detail (request , pk ):
51
71
lead = Lead .objects .get (id = pk )
@@ -70,7 +90,7 @@ def form_valid(self, form):
70
90
recipient_list = [
"[email protected] " ]
71
91
)
72
92
return super (LeadCreateView , self ).form_valid (form )
73
-
93
+
74
94
75
95
def lead_create (request ):
76
96
form = LeadModelForm ()
@@ -87,9 +107,13 @@ def lead_create(request):
87
107
88
108
class LeadUpdateView (OrganisorAndLoginRequiredMixin , generic .UpdateView ):
89
109
template_name = "leads/lead_update.html"
90
- queryset = Lead .objects .all ()
91
110
form_class = LeadModelForm
92
111
112
+ def get_queryset (self ):
113
+ user = self .request .user
114
+ # initial queryset of leads for the entire organisation
115
+ return Lead .objects .filter (organisation = user .userprofile )
116
+
93
117
def get_success_url (self ):
94
118
return reverse ("leads:lead-list" )
95
119
@@ -111,11 +135,15 @@ def lead_update(request, pk):
111
135
112
136
class LeadDeleteView (OrganisorAndLoginRequiredMixin , generic .DeleteView ):
113
137
template_name = "leads/lead_delete.html"
114
- queryset = Lead .objects .all ()
115
138
116
139
def get_success_url (self ):
117
140
return reverse ("leads:lead-list" )
118
141
142
+ def get_queryset (self ):
143
+ user = self .request .user
144
+ # initial queryset of leads for the entire organisation
145
+ return Lead .objects .filter (organisation = user .userprofile )
146
+
119
147
120
148
def lead_delete (request , pk ):
121
149
lead = Lead .objects .get (id = pk )
0 commit comments