Example #1
0
def validateToken(token):
	deviceModel = Device()
	device = deviceModel.getDevice({'token': token})
	if device is None:
		raise ValueError("This is an invalid token.")
	data = dict()
	data['device'] = device
	return data
 def put(self):
     data = dict()
     args = post_parser.parse_args()
     try:
         deviceModel = Device()
         device = deviceModel.getDevice(args)
         imgfile = args['image']
         ext = fileAllowed(imgfile.filename)
         if ext is None:
             raise ErrorWithCode(403, "File type not allowed")
         imagename = md5(datetime.now().strftime(
             "%b%d%Y%h%m%s%f")).hexdigest() + "." + ext
         workingdir = os.getcwd()
         imagePath = os.path.join(workingdir, 'images', imagename)
         imgfile.save(imagePath)
         self.resizeImage(imagePath)
         data['imagename'] = imagename
         return data, 200
     except Exception, e:
         data['message'] = str(e)
         return data, e.code if hasattr(e, 'code') else 500
Example #3
0
 def get(self):
     data = dict()
     args = parser.parse_args()
     try:
         deviceModel = Device()
         device = deviceModel.getDevice(args)
         lat_lng = args['lat_lng']
         lat = lat_lng.split(',')[0].strip()
         lng = lat_lng.split(',')[1].strip()
         locationModel = Location()
         data['inlocation'] = locationModel.getLocationFromPosition({
             'lat':
             lat,
             'lng':
             lng
         })
         data['avllocation'] = locationModel.getAllLocations()
         return marshal(
             data,
             resource_fields), 404 if data['inlocation'] is None else 200
     except Exception, e:
         data['message'] = str(e)
         return data, e.code if hasattr(e, 'code') else 500