def dispatch(self, request, *args, **kwargs): """Empresa Delete View dispatch.""" key = self.kwargs['pk'] pk = SecurityKey.is_valid_key(request, key, 'doc_del') if not pk: return HttpResponseRedirect(self.success_url) self.kwargs['pk'] = pk try: self.get_object() except Exception as e: messages.error(self.request, e) log.warning(force_text(e), extra=log_params(self.request)) return HttpResponseRedirect(self.success_url) return super(CitaDeleteView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): """Tipo Documento Create View dispatch.""" key = self.kwargs.get(self.pk_url_kwarg, None) pk = SecurityKey.is_valid_key(request, key, 'doc_upd') if not pk: return HttpResponseRedirect(self.success_url) self.kwargs['pk'] = pk try: self.get_object() except Exception as e: messages.error(self.request, e) log.warning(force_text(e), extra=log_params(self.request)) return HttpResponseRedirect(self.success_url) return super(CompraUpdateView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): key = self.kwargs['pk'] state = self.kwargs['state'] pk = SecurityKey.is_valid_key(request, key, 'colamedica_%s' % state) if not pk: return HttpResponseRedirect(self.success_url) try: self.object = self.model.objects.get(pk=pk) except Exception as e: messages.error(self.request, e) log.warning(force_text(e), extra=log_params(self.request)) return HttpResponseRedirect(self.success_url) msg = _( 'La %(name)s del paciente "%(obj)s" %(action)s satisfactoriamente.' ) % { 'name': capfirst(force_text('atencion medica')), 'obj': force_text(self.object), 'action': (_('reactivated') if state == 'rea' else _('Terminó')) } mse = _('La %(name)s "%(obj)s" is already %(action)s.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object), 'action': (_('active') if state == 'rea' else _('inactive')) } try: if state == 'ina' and not self.object.is_active: raise Exception(mse) else: if state == 'rea' and self.object.is_active: raise Exception(mse) else: self.object.is_active = (True if state == 'rea' else False) self.object.save() messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) except Exception as e: messages.warning(self.request, e) log.warning(force_text(e), extra=log_params(self.request)) return HttpResponseRedirect(self.success_url)