Commit 3525260d54425830f38caaa448bef852eef13dfd
1 parent
4d316ef2
Exists in
master
and in
3 other branches
Adding groups log
Showing
1 changed file
with
62 additions
and
3 deletions
Show diff stats
students_group/views.py
... | ... | @@ -10,6 +10,8 @@ from amadeus.permissions import has_subject_permissions |
10 | 10 | |
11 | 11 | from subjects.models import Subject |
12 | 12 | |
13 | +from log.mixins import LogMixin | |
14 | + | |
13 | 15 | from .models import StudentsGroup |
14 | 16 | from .forms import StudentsGroupForm |
15 | 17 | |
... | ... | @@ -48,7 +50,12 @@ class IndexView(LoginRequiredMixin, generic.ListView): |
48 | 50 | |
49 | 51 | return context |
50 | 52 | |
51 | -class CreateView(LoginRequiredMixin, generic.edit.CreateView): | |
53 | +class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
54 | + log_component = 'students_group' | |
55 | + log_action = 'create' | |
56 | + log_resource = 'students group' | |
57 | + log_context = {} | |
58 | + | |
52 | 59 | login_url = reverse_lazy("users:login") |
53 | 60 | redirect_field_name = 'next' |
54 | 61 | |
... | ... | @@ -77,6 +84,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
77 | 84 | initial['description'] = group.description |
78 | 85 | initial['name'] = group.name |
79 | 86 | initial['participants'] = group.participants.all() |
87 | + | |
88 | + self.log_action = 'replicate' | |
89 | + | |
90 | + self.log_context['replicated_group_id'] = group.id | |
91 | + self.log_context['replicated_group_name'] = group.name | |
92 | + self.log_context['replicated_group_slug'] = group.slug | |
80 | 93 | |
81 | 94 | return initial |
82 | 95 | |
... | ... | @@ -90,6 +103,18 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
90 | 103 | |
91 | 104 | self.object.save() |
92 | 105 | |
106 | + self.log_context['category_id'] = self.object.subject.category.id | |
107 | + self.log_context['category_name'] = self.object.subject.category.name | |
108 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
109 | + self.log_context['subject_id'] = self.object.subject.id | |
110 | + self.log_context['subject_name'] = self.object.subject.name | |
111 | + self.log_context['subject_slug'] = self.object.subject.slug | |
112 | + self.log_context['group_id'] = self.object.id | |
113 | + self.log_context['group_name'] = self.object.name | |
114 | + self.log_context['group_slug'] = self.object.slug | |
115 | + | |
116 | + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
117 | + | |
93 | 118 | return super(CreateView, self).form_valid(form) |
94 | 119 | |
95 | 120 | def get_context_data(self, **kwargs): |
... | ... | @@ -116,7 +141,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
116 | 141 | |
117 | 142 | return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) |
118 | 143 | |
119 | -class UpdateView(LoginRequiredMixin, generic.UpdateView): | |
144 | +class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
145 | + log_component = 'students_group' | |
146 | + log_action = 'update' | |
147 | + log_resource = 'students group' | |
148 | + log_context = {} | |
149 | + | |
120 | 150 | login_url = reverse_lazy("users:login") |
121 | 151 | redirect_field_name = 'next' |
122 | 152 | |
... | ... | @@ -149,9 +179,26 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
149 | 179 | def get_success_url(self): |
150 | 180 | messages.success(self.request, _('The group "%s" was updated successfully!')%(self.object.name)) |
151 | 181 | |
182 | + self.log_context['category_id'] = self.object.subject.category.id | |
183 | + self.log_context['category_name'] = self.object.subject.category.name | |
184 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
185 | + self.log_context['subject_id'] = self.object.subject.id | |
186 | + self.log_context['subject_name'] = self.object.subject.name | |
187 | + self.log_context['subject_slug'] = self.object.subject.slug | |
188 | + self.log_context['group_id'] = self.object.id | |
189 | + self.log_context['group_name'] = self.object.name | |
190 | + self.log_context['group_slug'] = self.object.slug | |
191 | + | |
192 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
193 | + | |
152 | 194 | return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) |
153 | 195 | |
154 | -class DeleteView(LoginRequiredMixin, generic.DeleteView): | |
196 | +class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
197 | + log_component = 'students_group' | |
198 | + log_action = 'delete' | |
199 | + log_resource = 'students group' | |
200 | + log_context = {} | |
201 | + | |
155 | 202 | login_url = reverse_lazy("users:login") |
156 | 203 | redirect_field_name = 'next' |
157 | 204 | |
... | ... | @@ -171,4 +218,16 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView): |
171 | 218 | def get_success_url(self): |
172 | 219 | messages.success(self.request, _('The group "%s" was removed successfully!')%(self.object.name)) |
173 | 220 | |
221 | + self.log_context['category_id'] = self.object.subject.category.id | |
222 | + self.log_context['category_name'] = self.object.subject.category.name | |
223 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
224 | + self.log_context['subject_id'] = self.object.subject.id | |
225 | + self.log_context['subject_name'] = self.object.subject.name | |
226 | + self.log_context['subject_slug'] = self.object.subject.slug | |
227 | + self.log_context['group_id'] = self.object.id | |
228 | + self.log_context['group_name'] = self.object.name | |
229 | + self.log_context['group_slug'] = self.object.slug | |
230 | + | |
231 | + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
232 | + | |
174 | 233 | return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) |
175 | 234 | \ No newline at end of file | ... | ... |