Commit 8e3ef4ba8ba20ad8ef50fc3949a48736a3baad31
1 parent
03db6478
Exists in
master
and in
3 other branches
Adjusting url redirection crud
Showing
1 changed file
with
12 additions
and
17 deletions
Show diff stats
categories/views.py
@@ -130,7 +130,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | @@ -130,7 +130,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | ||
130 | messages.success(self.request, _('Category "%s" register successfully!')%(objeto)) | 130 | messages.success(self.request, _('Category "%s" register successfully!')%(objeto)) |
131 | return reverse_lazy('categories:index') | 131 | return reverse_lazy('categories:index') |
132 | 132 | ||
133 | - | ||
134 | class DeleteCategory(LogMixin, DeleteView): | 133 | class DeleteCategory(LogMixin, DeleteView): |
135 | log_component = 'category' | 134 | log_component = 'category' |
136 | log_action = 'delete' | 135 | log_action = 'delete' |
@@ -146,16 +145,11 @@ class DeleteCategory(LogMixin, DeleteView): | @@ -146,16 +145,11 @@ class DeleteCategory(LogMixin, DeleteView): | ||
146 | def delete(self, request, *args, **kwargs): | 145 | def delete(self, request, *args, **kwargs): |
147 | category = get_object_or_404(Category, slug = self.kwargs.get('slug')) | 146 | category = get_object_or_404(Category, slug = self.kwargs.get('slug')) |
148 | subjects = Subject.objects.filter(category = category) | 147 | subjects = Subject.objects.filter(category = category) |
149 | - | ||
150 | - print(self.request.META.get('HTTP_REFERER')) | ||
151 | 148 | ||
152 | if subjects.count() > 0: | 149 | if subjects.count() > 0: |
153 | messages.error(self.request, _('The category cannot be removed, it contains one or more virtual enviroments attach.')) | 150 | messages.error(self.request, _('The category cannot be removed, it contains one or more virtual enviroments attach.')) |
154 | - | ||
155 | - if self.request.user.is_staff: | ||
156 | - return redirect(reverse_lazy('categories:index')) | ||
157 | - | ||
158 | - return redirect(reverse_lazy('subjects:index')) | 151 | + |
152 | + return redirect(self.request.META.get('HTTP_REFERER')) | ||
159 | 153 | ||
160 | return super(DeleteCategory, self).delete(self, request, *args, **kwargs) | 154 | return super(DeleteCategory, self).delete(self, request, *args, **kwargs) |
161 | 155 | ||
@@ -167,11 +161,8 @@ class DeleteCategory(LogMixin, DeleteView): | @@ -167,11 +161,8 @@ class DeleteCategory(LogMixin, DeleteView): | ||
167 | super(DeleteCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 161 | super(DeleteCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
168 | 162 | ||
169 | messages.success(self.request, _('Category "%s" removed successfully!')%(self.object.name)) | 163 | messages.success(self.request, _('Category "%s" removed successfully!')%(self.object.name)) |
170 | - | ||
171 | - if self.request.user.is_staff: | ||
172 | - return reverse_lazy('categories:index') | ||
173 | - | ||
174 | - return reverse_lazy('subjects:index') | 164 | + |
165 | + return self.request.META.get('HTTP_REFERER') | ||
175 | 166 | ||
176 | class UpdateCategory(LogMixin, UpdateView): | 167 | class UpdateCategory(LogMixin, UpdateView): |
177 | log_component = 'category' | 168 | log_component = 'category' |
@@ -191,14 +182,15 @@ class UpdateCategory(LogMixin, UpdateView): | @@ -191,14 +182,15 @@ class UpdateCategory(LogMixin, UpdateView): | ||
191 | self.log_context['category_name'] = self.object.name | 182 | self.log_context['category_name'] = self.object.name |
192 | self.log_context['category_slug'] = self.object.slug | 183 | self.log_context['category_slug'] = self.object.slug |
193 | 184 | ||
185 | + #url to return | ||
186 | + return_url = self.log_context['return_url'] | ||
187 | + self.log_context.pop('return_url', None) | ||
188 | + | ||
194 | super(UpdateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 189 | super(UpdateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
195 | 190 | ||
196 | messages.success(self.request, _('Category "%s" updated successfully!')%(self.object.name)) | 191 | messages.success(self.request, _('Category "%s" updated successfully!')%(self.object.name)) |
197 | 192 | ||
198 | - if self.request.user.is_staff: | ||
199 | - return reverse_lazy('categories:index') | ||
200 | - | ||
201 | - return reverse_lazy('subjects:index') | 193 | + return return_url |
202 | 194 | ||
203 | def form_valid(self, form): | 195 | def form_valid(self, form): |
204 | category = form.save() | 196 | category = form.save() |
@@ -215,6 +207,9 @@ class UpdateCategory(LogMixin, UpdateView): | @@ -215,6 +207,9 @@ class UpdateCategory(LogMixin, UpdateView): | ||
215 | context = super(UpdateCategory, self).get_context_data(**kwargs) | 207 | context = super(UpdateCategory, self).get_context_data(**kwargs) |
216 | context['title'] = _('Update Category') | 208 | context['title'] = _('Update Category') |
217 | 209 | ||
210 | + if self.request.method == 'GET': | ||
211 | + self.log_context['return_url'] = self.request.META.get('HTTP_REFERER') | ||
212 | + | ||
218 | if 'categories' in self.request.META.get('HTTP_REFERER'): | 213 | if 'categories' in self.request.META.get('HTTP_REFERER'): |
219 | context['template_extends'] = 'categories/list.html' | 214 | context['template_extends'] = 'categories/list.html' |
220 | context['settings_menu_active'] = "settings_menu_active" | 215 | context['settings_menu_active'] = "settings_menu_active" |