Commit c35730d0ba4a3c4aaf5d3c05ffc855674e96e32f
1 parent
615652db
Exists in
master
and in
3 other branches
Adding log to category crud
Showing
1 changed file
with
34 additions
and
3 deletions
Show diff stats
categories/views.py
... | ... | @@ -16,6 +16,8 @@ from .forms import CategoryForm |
16 | 16 | from braces import views |
17 | 17 | from subjects.models import Subject |
18 | 18 | |
19 | +from log.mixins import LogMixin | |
20 | + | |
19 | 21 | class IndexView(LoginRequiredMixin, ListView): |
20 | 22 | |
21 | 23 | login_url = reverse_lazy("users:login") |
... | ... | @@ -57,7 +59,11 @@ class IndexView(LoginRequiredMixin, ListView): |
57 | 59 | |
58 | 60 | return context |
59 | 61 | |
60 | -class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, CreateView): | |
62 | +class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, CreateView): | |
63 | + log_component = 'category' | |
64 | + log_action = 'create' | |
65 | + log_resource = 'category' | |
66 | + log_context = {} | |
61 | 67 | |
62 | 68 | allowed_rules = ['system_admin'] |
63 | 69 | login_url = reverse_lazy('users:login') |
... | ... | @@ -93,7 +99,11 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, CreateView): |
93 | 99 | def form_valid(self, form): |
94 | 100 | self.object = form.save() |
95 | 101 | |
102 | + self.log_context['category_id'] = self.object.id | |
103 | + self.log_context['category_name'] = self.object.name | |
104 | + self.log_context['category_slug'] = self.object.slug | |
96 | 105 | |
106 | + super(CreateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
97 | 107 | |
98 | 108 | #TODO: Implement log calls |
99 | 109 | return super(CreateCategory, self).form_valid(form) |
... | ... | @@ -105,7 +115,11 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, CreateView): |
105 | 115 | return reverse_lazy('categories:index') |
106 | 116 | |
107 | 117 | |
108 | -class DeleteCategory(DeleteView): | |
118 | +class DeleteCategory(LogMixin, DeleteView): | |
119 | + log_component = 'category' | |
120 | + log_action = 'delete' | |
121 | + log_resource = 'category' | |
122 | + log_context = {} | |
109 | 123 | |
110 | 124 | login_url = reverse_lazy("users:login") |
111 | 125 | redirect_field_name = 'next' |
... | ... | @@ -125,11 +139,22 @@ class DeleteCategory(DeleteView): |
125 | 139 | return super(DeleteCategory, self).delete(self, request, *args, **kwargs) |
126 | 140 | |
127 | 141 | def get_success_url(self): |
142 | + self.log_context['category_id'] = self.object.id | |
143 | + self.log_context['category_name'] = self.object.name | |
144 | + self.log_context['category_slug'] = self.object.slug | |
145 | + | |
146 | + super(DeleteCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
147 | + | |
128 | 148 | messages.success(self.request, _('Category removed successfully!')) |
129 | 149 | return reverse_lazy('categories:index') |
130 | 150 | |
131 | 151 | |
132 | -class UpdateCategory(UpdateView): | |
152 | +class UpdateCategory(LogMixin, UpdateView): | |
153 | + log_component = 'category' | |
154 | + log_action = 'update' | |
155 | + log_resource = 'category' | |
156 | + log_context = {} | |
157 | + | |
133 | 158 | model = Category |
134 | 159 | form_class = CategoryForm |
135 | 160 | template_name = 'categories/update.html' |
... | ... | @@ -139,6 +164,12 @@ class UpdateCategory(UpdateView): |
139 | 164 | |
140 | 165 | |
141 | 166 | def get_success_url(self): |
167 | + self.log_context['category_id'] = self.object.id | |
168 | + self.log_context['category_name'] = self.object.name | |
169 | + self.log_context['category_slug'] = self.object.slug | |
170 | + | |
171 | + super(UpdateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
172 | + | |
142 | 173 | objeto = self.object.name |
143 | 174 | messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) |
144 | 175 | return reverse_lazy('categories:index') | ... | ... |