class MascotaUpdateView(UpdateView): model = Mascota form_class = MascotaUpdateForm template_name = "clinica/form/mascota.html" @method_decorator(permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): return super(MascotaUpdateView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(MascotaUpdateView, self).get_context_data(**kwargs) context['opts'] = self.model._meta # context['cmi'] = 'empresa' context['title'] = ('Actualizar %s') % ('Mascota') return context def form_valid(self, form): self.object = form.save(commit=False) self.object.usuario = self.request.user msg = ('%(name)s "%(obj)s" fue cambiado satisfacoriamente.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(MascotaUpdateView, self).form_valid(form) def get_success_url(self): return reverse('clinica:mascota_list', kwargs={'cliente_pk': self.object.duenho_id})
class MainCreateView(CreateView): model = ColaMedica form_class = ColaMedicaForm template_name = "clinica/busqueda.html" success_url = reverse_lazy("clinica:crear_medica") @method_decorator( permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): """dispatch.""" return super(MainCreateView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(MainCreateView, self).get_context_data(**kwargs) context['opts'] = self.model._meta # context['cmi'] = 'tipodoc' context['title'] = ('Recepción') return context def form_valid(self, form): """"Empresa Crete View form valid.""" self.object = form.save(commit=False) msg = _(' %(name)s "%(obj)s" fue creado satisfactoriamente.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(MainCreateView, self).form_valid(form)
class MascotaCreateView(CreateView): """Tipo Documento Identidad.""" model = Mascota form_class = MascotaForm template_name = "clinica/form/mascota.html" @method_decorator(permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): """dispatch.""" return super(MascotaCreateView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): """ """ context = super(MascotaCreateView, self).get_context_data(**kwargs) context['opts'] = self.model._meta #context['cmi'] = 'mascota' context['title'] = ('Agregar %s') % ('mascota') context['subtitle'] = ('Registro %s') % (' de nueva mascota') return context def form_valid(self, form): """"Empresa Crete View form valid.""" self.object = form.save(commit=False) self.object.user = self.request.user self.object.duenho_id = self.kwargs.get('cliente_pk') print("=========llega================="), self.object.save() cantidad= Historial.objects.all() historia = Historial( num_historia =cantidad.count()+1, veterinario = self.request.user, mascota = self.object, caracter = form.cleaned_data['caracter'], actividad = form.cleaned_data['actividad'], habitar = form.cleaned_data['habitar'], alimentacion = form.cleaned_data['alimentacion'], aptitup = form.cleaned_data['aptitup'], convive = form.cleaned_data['convive'] ) historia.save() msg = _(' %(name)s "%(obj)s" fue creado satisfactoriamente.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(MascotaCreateView, self).form_valid(form) def get_success_url(self): return reverse('clinica:mascota_list', kwargs={'cliente_pk':self.object.duenho_id})
class AtencionTerminadaView(ListView): """ """ model = ColaMedica template_name = "clinica/colamedica.html" success_url = reverse_lazy("clinica:listar_medica") @method_decorator( permission_resource_required(template_name='main/dashboard.html')) 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)
class MascotaUpdateActiveView(ListView): """ """ model = Mascota template_name = "clinica/mascota.html" @method_decorator(permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): key = self.kwargs['pk'] state = self.kwargs['state'] pk = SecurityKey.is_valid_key(request, key, 'mascota_%s' % state) if not pk: return HttpResponseRedirect(self.get_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.get_success_url()) msg = _('La %(name)s "%(obj)s" %(action)s.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object), 'action': (_('esta vivo') if state == 'rea' else _('fallecio')) } mse = _('The %(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.error(self.request, e) log.warning(force_text(e), extra=log_params(self.request)) return HttpResponseRedirect(self.get_success_url()) def get_success_url(self): return reverse('clinica:mascota_list', kwargs={'cliente_pk': self.object.duenho_id})
class HistoriaMascotaCreateView(CreateView): """ """ model = Historial form_class = HistoriaMascotaForm template_name = "clinica/form/historia.html" @method_decorator( permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): """dispatch.""" return super(HistoriaMascotaCreateView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): """ """ context = super(HistoriaMascotaCreateView, self).get_context_data(**kwargs) context['opts'] = self.model._meta #context['cmi'] = 'mascota' context['datos'] = Historial.objects.all() context['cantidad'] = context['datos'].count() + 1 context['title'] = ('Agregar %s') % ('mascota') context['subtitle'] = ('Registro %s') % (' de nueva mascota') return context def form_valid(self, form): """"Empresa Crete View form valid.""" self.object = form.save(commit=False) self.object.veterinario = self.request.user self.object.mascota_id = self.kwargs.get('mascota_pk') self.object.duenho_id = self.kwargs.get('cliente_pk') msg = _(' %(name)s "%(obj)s" fue creado satisfactoriamente.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(HistoriaMascotaCreateView, self).form_valid(form) def get_success_url(self): return reverse('clinica:mascota_list', kwargs={'cliente_pk': self.object.duenho_id})
class MascotaListView(ListView): u"""Mascota List""" model = Mascota paginate_by = settings.PER_PAGE template_name = "clinica/index.html" @method_decorator(permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): """dispatch.""" return super(MascotaListView, self).dispatch(request, *args, **kwargs) def get_paginate_by(self, queryset): """Paginate.""" if 'all' in self.request.GET: return None return ListView.get_paginate_by(self, queryset) def get_queryset(self): """Tipo Doc List Queryset.""" self.o = empty(self.request, 'o', '-id') self.f = empty(self.request, 'f', 'nombre') self.q = empty(self.request, 'q', '') column_contains = u'%s__%s' % (self.f, 'contains') return self.model.objects.filter(**{column_contains: self.q}).order_by(self.o) def get_context_data(self, **kwargs): context = super(MascotaListView, self).get_context_data(**kwargs) context['opts'] = self.model._meta context['id_cliente'] = self.kwargs.get('cliente_pk') context['listar_mascota'] = Mascota.objects.filter(duenho = self.kwargs.get('cliente_pk')) #context['cmi'] = 'mascota' # Validacion de manual del menu context['title'] = ('Seleccione %s' ) % capfirst(' una mascota') context['o'] = self.o context['f'] = self.f context['q'] = self.q.replace('/', '-') return context
class AtencionCreateView(CreateView): """ """ model = Atenciones form_class = AtencionesForm template_name = "clinica/historial/index.html" @method_decorator( permission_resource_required(template_name='main/dashboard.html')) def dispatch(self, request, *args, **kwargs): """dispatch.""" return super(AtencionCreateView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): u"""get_context_data.""" context = super(AtencionCreateView, self).get_context_data(**kwargs) context['opts'] = self.model._meta context['id_cola_medica'] = self.kwargs.get('colamedica_pk') context['id_mascota'] = self.kwargs.get('mascota_pk') context['id'] = self.kwargs.get('pk') context['mascota'] = Mascota.objects.filter(id=18) context['historial'] = Atenciones.objects.filter( colamedica__mascota=self.kwargs.get('mascota_pk')) mascotas = Mascota.objects.get(id=self.kwargs.get('mascota_pk')) print("sssssssssssssssssssssssssssssssssssssss", mascotas) context['mascota_nombre'] = mascotas.nombre context['mascota_raza'] = mascotas.raza context['mascota_genero'] = mascotas.genero context['mascota_dueño'] = mascotas.duenho context['title'] = ( 'Seleccione %s para cambiar') % capfirst('Atenciones') return context def form_valid(self, form): """"Empresa Crete View form valid.""" try: print("hola") self.object = form.save(commit=False) self.object.veterinario = self.request.user self.object.colamedica_id = self.kwargs.get('colamedica_pk') print("========funciona=========") msg = _(' %(name)s "%(obj)s" fue creado satisfactoriamente.') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(AtencionCreateView, self).form_valid(form) except Exception as e: msg = _('La %(name)s para la mascota %(obj)s ya existe') % { 'name': capfirst(force_text(self.model._meta.verbose_name)), 'obj': force_text(self.object) } messages.warning(self.request, msg) log.warning(force_text(msg), extra=log_params(self.request)) return super(AtencionCreateView, self).form_invalid(form) def get_success_url(self): return reverse('clinica:historia_list', kwargs={ 'mascota_pk': self.kwargs.get('mascota_pk'), 'colamedica_pk': self.object.colamedica_id })