Ejemplo n.º 1
0
def user_new(request):
	try:
		email = request.POST['email']
		imei = request.POST['imei']
		provider = request.POST['empresa']
		first_name = request.POST.get('first_name', '')
		last_name = request.POST.get('last_name', '')
		phone = request.POST.get('phone', '')
		is_active = request.POST.get('is_active', None)

		new_userprov = InfoProv(
			username=imei,
			first_name=first_name,
			last_name=last_name,
			email=email,
			imei=imei,
			telefono=phone,
			empresa_id=int(provider)
			)
		if is_active is not None:
			new_userprov.is_active=(is_active.lower() == 'true'),
		new_userprov.save()

		registerLog(request.user, 'Nuevo', 'Proveedor', new_userprov.pk)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien",
			'user_id':new_userprov.pk
		})
	except :
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Fallo"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json' )
Ejemplo n.º 2
0
def site_new(request):
	try:
		name = request.POST['name']
		neumonico = request.POST['neumonico']
		lat = request.POST['lat']
		lng = request.POST['lng']
		region = request.POST['region']
		radio = request.POST.get('radio', '10')

		new_site = Sitio(
			neumonico=neumonico,
			nombre=name,
			lat=lat,
			lng=lng,
			radio=float(radio),
			region=Region.objects.get(pk=int(region)))
		new_site.save()

		registerLog(request.user, 'Nuevo', 'Sitio', new_site.pk)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien",
			'provider_id' : new_site.pk
		})
	except Exception, e:
		raise e
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Fallo"
		})
Ejemplo n.º 3
0
def user_edit(request, id_user):
	try:
		email = request.POST.get('email', None)
		first_name = request.POST.get('first_name', None)
		last_name = request.POST.get('last_name', None)
		phone = request.POST.get('phone', None)
		the_userprov = InfoOther.objects.get(pk=id_user)
		if email is not None :
			the_userprov.email = email
		if first_name is not None :
			the_userprov.first_name = first_name
		if last_name is not None :
			the_userprov.last_name = last_name
		if phone is not None :
			the_userprov.telefono = phone

		the_userprov.save()

		registerLog(request.user, 'Edición', 'Usuario', id_user)

		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien"
		})
	except InfoOther.DoesNotExist:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "No existe el usuario"
		})
	except:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Ocurrio un error desconocido"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json' )
Ejemplo n.º 4
0
def user_new(request):
	try:
		email = request.POST['email']
		first_name = request.POST.get('first_name', '')
		last_name = request.POST.get('last_name', '')
		phone = request.POST.get('phone', '')
		password = request.POST.get('password', None)

		new_userprov = InfoOther(
			username=email,
			first_name=first_name,
			last_name=last_name,
			email=email,
			password=password,
			telefono=phone,
			)
		new_userprov.save()

		registerLog(request.user, 'Nuevo', 'Usuario', new_userprov.pk)

		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien",
			'user_id':new_userprov.pk
		})
	except Exception, e :
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Fallo"
		})
Ejemplo n.º 5
0
def site_delete(request, id_site):
	try:
		the_site = Sitio.objects.get(pk=id_site)
		the_site.delete()
		registerLog(request.user, 'Borrar', 'Sitio', id_site)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Borrado"
		})
	except Site.DoesNotExist:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "No existe el sitio"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json')
Ejemplo n.º 6
0
def user_delete(request, id_user):
	try:
		the_userprov = InfoOther.objects.get(pk=id_user)
		the_userprov.delete()
		registerLog(request.user, 'Borrar', 'Usuario', id_user)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Borrado"
		})
	except InfoOther.DoesNotExist:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "No existe el usuario"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json' )
Ejemplo n.º 7
0
def user_edit(request, id_user):
	try:
		# TODO Editar al usuario
		email = request.POST.get('email', None)
		imei = request.POST.get('imei',None)
		provider = request.POST.get('provider', None)
		first_name = request.POST.get('first_name', None)
		last_name = request.POST.get('last_name', None)
		phone = request.POST.get('phone', None)
		is_active = request.POST.get('is_active', None)
		the_userprov = InfoProv.objects.get(pk=id_user)
		if email is not None :
			the_userprov.email = email
		if imei is not None :
			the_userprov.imei = imei
			the_userprov.username = imei
		if provider is not None :
			the_userprov.empresa_id = int(provider)
		if first_name is not None :
			the_userprov.first_name = first_name
		if last_name is not None :
			the_userprov.last_name = last_name
		if phone is not None :
			the_userprov.telefono = phone
		if is_active is not None:
			the_userprov.is_active = (is_active.lower() == 'true')

		the_userprov.save()

		registerLog(request.user, 'Edición', 'Proveedor', id_user)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien"
		})
	except InfoProv.DoesNotExist:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "No existe el usuario"
		})
	except:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Ocurrio un error desconocido"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json' )
Ejemplo n.º 8
0
def site_edit(request, id_site):
	try:
		name = request.POST.get('name', None)
		neumonico = request.POST.get('neumonico', None)
		id_region = request.POST.get('region', None)
		lat = request.POST.get('lat', None)
		lng = request.POST.get('lng', None)
		radio = request.POST.get('radio', None)

		the_site = Sitio.objects.get(pk=id_site)
		if name is not None :
			the_site.nombre = name
		if neumonico is not None :
			the_site.neumonico = neumonico
		if id_region is not None :
			the_site.region_id = Region.objects.get(pk=int(id_region))
		if lat is not None :
			the_site.lat = lat
		if lng is not None :
			the_site.lng = lng

		the_site.save()

		registerLog(request.user, 'Edición', 'Sitio', id_site)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien"
		})
	except Sitio.DoesNotExist:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "No existe el sitio"
		})
	except:
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Ocurrio un error desconocido"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json')