Commit 5f13c2ccf3f28f8c0dc5839db05218f5d003fc75

Authored by Zambom
1 parent 1b4f8e9c

Adjusting category crud redirections

Showing 1 changed file with 12 additions and 3 deletions   Show diff stats
categories/views.py
@@ -152,7 +152,10 @@ class DeleteCategory(LogMixin, DeleteView): @@ -152,7 +152,10 @@ class DeleteCategory(LogMixin, DeleteView):
152 if subjects.count() > 0: 152 if subjects.count() > 0:
153 messages.error(self.request, _('The category cannot be removed, it contains one or more virtual enviroments attach.')) 153 messages.error(self.request, _('The category cannot be removed, it contains one or more virtual enviroments attach.'))
154 154
155 - return redirect(self.request.META.get('HTTP_REFERER')) 155 + if self.request.user.is_admin:
  156 + return redirect(reverse_lazy('categories:index'))
  157 +
  158 + return redirect(reverse_lazy('subjects:index'))
156 159
157 return super(DeleteCategory, self).delete(self, request, *args, **kwargs) 160 return super(DeleteCategory, self).delete(self, request, *args, **kwargs)
158 161
@@ -165,7 +168,10 @@ class DeleteCategory(LogMixin, DeleteView): @@ -165,7 +168,10 @@ class DeleteCategory(LogMixin, DeleteView):
165 168
166 messages.success(self.request, _('Category removed successfully!')) 169 messages.success(self.request, _('Category removed successfully!'))
167 170
168 - return self.request.META.get('HTTP_REFERER') 171 + if self.request.user.is_admin:
  172 + return reverse_lazy('categories:index')
  173 +
  174 + return reverse_lazy('subjects:index')
169 175
170 class UpdateCategory(LogMixin, UpdateView): 176 class UpdateCategory(LogMixin, UpdateView):
171 log_component = 'category' 177 log_component = 'category'
@@ -190,7 +196,10 @@ class UpdateCategory(LogMixin, UpdateView): @@ -190,7 +196,10 @@ class UpdateCategory(LogMixin, UpdateView):
190 objeto = self.object.name 196 objeto = self.object.name
191 messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) 197 messages.success(self.request, _('Category "%s" updated successfully!')%(objeto))
192 198
193 - return reverse_lazy('categories:index') 199 + if self.request.user.is_admin:
  200 + return reverse_lazy('categories:index')
  201 +
  202 + return reverse_lazy('subjects:index')
194 203
195 def get_context_data(self, **kwargs): 204 def get_context_data(self, **kwargs):
196 context = super(UpdateCategory, self).get_context_data(**kwargs) 205 context = super(UpdateCategory, self).get_context_data(**kwargs)