Esempio n. 1
0
	def post(self, request, *args, **kwargs):
		fechacita = request.POST.get('date_holder', default = "")
		annio = fechacita[8:]
		mes   = fechacita[0:3]
		dia   = fechacita[4:6]
		if   mes == "Ene":
			mes = "01"
		elif mes == "Feb":
			mes = "02"
		elif mes == "Mar":
			mes = "03"
		elif mes == "Abr":
			mes = "04"
		elif mes == "May":
			mes = "05"
		elif mes == "Jun":
			mes = "06"
		elif mes == "Jul":
			mes = "07"
		elif mes == "Ago":
			mes = "08"
		elif mes == "Sep":
			mes = "09"
		elif mes == "Oct":
			mes = "10"
		elif mes == "Nov":
			mes = "11"
		elif mes == "Dic":
			mes = "12"
		fechacita = annio + '-' + mes + '-' + dia
		horaini = request.POST.get('start', default = "")

		if horaini == "08:00 am":
			horaini = "08:00"
		elif horaini == "08:15 am":
			horaini = "08:15"
		elif horaini == "08:30 am":
			horaini = "08:30"
		elif horaini == "08:45 am":
			horaini = "08:45"
		elif  horaini == "09:00 am":
			horaini = "09:00"

		horafin = request.POST.get('end', default = "")

		if horafin == "08:00 am":
			horafin = "08:00"
		elif horafin == "08:15 am":
			horafin = "08:15"
		elif horafin == "08:30 am":
			horafin = "08:30"
		elif horafin == "08:45 am":
			horafin = "08:45"
		elif  horafin == "09:00 am":
			horafin = "09:00"

		paciente_id = request.POST.get('paciente', default = "")
		tipoterapia_id = request.POST.get('tipoterapia', default = "")
		terapista_id = request.POST.get('terapista', default = "")
		cita = Cita()
		try:
			cita.tipo_terapia = Tipo_terapia.objects.get(id=tipoterapia_id)
		except Tipo_terapia.DoesNotExist:
			print "error"
		try:
			cita.paciente = Paciente.objects.get(id=paciente_id)
		except Paciente.DoesNotExist:
			print "error"
		try:
			cita.terapista = Terapista.objects.get(id=terapista_id)
		except Terapista.DoesNotExist:
			print "error"
		
		cita.fecha_cita=fechacita
		cita.hora_inicio=datetime.datetime.strptime(horaini[:24],'%a %b %d %Y %H:%M:%S')
		cita.hora_fin=datetime.datetime.strptime(horafin[:24],'%a %b %d %Y %H:%M:%S')
		cita.save()

		return HttpResponseRedirect(reverse('reservar_cita_view'))
Esempio n. 2
0
def save_cita(request):
	if request.is_ajax():
		if request.method == 'POST':
			fechacita = request.POST.get('date_holder', default = "")
			annio = fechacita[8:]
			mes   = fechacita[0:3]
			dia   = fechacita[4:6]
			if  mes == "Ene":
				mes = "01"
			elif mes == "Feb":
				mes = "02"
			elif mes == "Mar":
				mes = "03"
			elif mes == "Abr":
				mes = "04"
			elif mes == "May":
				mes = "05"
			elif mes == "Jun":
				mes = "06"
			elif mes == "Jul":
				mes = "07"
			elif mes == "Ago":
				mes = "08"
			elif mes == "Sep":
				mes = "09"
			elif mes == "Oct":
				mes = "10"
			elif mes == "Nov":
				mes = "11"
			elif mes == "Dic":
				mes = "12"
			fechacita = annio + '-' + mes + '-' + dia
			horaini = request.POST.get('start', default = "")

			if horaini == "08:00 am":
				horaini = "08:00"
			elif horaini == "08:15 am":
				horaini = "08:15"
			elif horaini == "08:30 am":
				horaini = "08:30"
			elif horaini == "08:45 am":
				horaini = "08:45"
			elif  horaini == "09:00 am":
				horaini = "09:00"

			horafin = request.POST.get('end', default = "")

			if horafin == "08:00 am":
				horafin = "08:00"
			elif horafin == "08:15 am":
				horafin = "08:15"
			elif horafin == "08:30 am":
				horafin = "08:30"
			elif horafin == "08:45 am":
				horafin = "08:45"
			elif  horafin == "09:00 am":
				horafin = "09:00"

			paciente_id = request.POST.get('paciente', default =None)
			tipoterapia_id = request.POST.get('tipoterapia', default =None)
			terapista_id = request.POST.get('terapista', default =None)
			estado = request.POST.get('estado', default =None)
			indicaciones = request.POST.get('indicaciones', default =None)

			if paciente_id and tipoterapia_id and terapista_id and estado:
				cita = Cita()
				try:
					cita.tipo_terapia = Tipo_terapia.objects.get(id=tipoterapia_id)
				except Tipo_terapia.DoesNotExist:
					print "error"
				try:
					cita.paciente = Paciente.objects.get(id=paciente_id)
				except Paciente.DoesNotExist:
					print "error"
				try:
					cita.terapista = Terapista.objects.get(id=terapista_id)
				except Terapista.DoesNotExist:
					print "error"
				
				cita.fecha_cita=fechacita
				cita.hora_inicio=datetime.datetime.strptime(horaini[:24],'%a %b %d %Y %H:%M:%S')
				cita.hora_fin=datetime.datetime.strptime(horafin[:24],'%a %b %d %Y %H:%M:%S')
				cita.estado = estado
				cita.indicaciones = indicaciones
				cita.save()
				return JsonResponse({'succes':True})
			else:
				return JsonResponse({'succes':False})

	else:
		return redirect('/')