def GetCitaAjax(request): if request.is_ajax(): try: citas = Cita.objects.all() results = [] for cita in citas: cita_json = {} cita_json['id'] = cita.id cita_json['title'] = cita.evento.title cita_json['sin_atender'] = cita.estado cita_json['color'] = cita.evento.color cita_json['evento_id'] = cita.evento.id cita_json['descripcion'] = cita.descripcion cita_json['start'] = "%s" % cita.date cita_json['veterinario'] = cita.veterinario.id cita_json['cliente'] = cita.cliente.id cita_json['cliente_nombre'] = cita.cliente.persona.first_name cita_json['pke'] = SecurityKey.get_key(cita.pk, 'doc_upd') cita_json['pkd'] = SecurityKey.get_key(cita.pk, 'doc_del') if cita.veterinario.person: cita_json['veterinario_nombre'] = "%s %s" % ( cita.veterinario.person.first_name, cita.veterinario.person.last_name) results.append(cita_json) data_json = json.dumps(results) except Exception as e: raise e else: data_json = 'fail' return HttpResponse(data_json, content_type='application/json')
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)