def post(self): if User_tool.check_before_start("removeContactCar", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] latitude = dati["Latitude"] longitude = dati["Longitude"] temp_user = User.static_querySearch_email(user_data["Email"]) id_user = temp_user.get().key.id() timestamp = dati["Timestamp"] if History_park.parky(id_user, latitude, longitude, timestamp) == 1: if static_variable.DEBUG: logging.debug("The application has to send notification? --> "+str(True)) right = StatusReturn(20, "getNotification", True) self.response.write(right.print_result()) else: if static_variable.DEBUG: logging.debug("The application has to send notification? --> "+str(False)) right = StatusReturn(21, "getNotification", False) self.response.write(right.print_result())
def check_code(email, code): temp_user_key = User.static_querySearch_email(email) if temp_user_key.count() == 0: return -2 else: temp_user = temp_user_key.get() return temp_user.check_code(code)
def post(self): if User_tool.check_before_start("getCars", self) >= 0: dati = json.loads(self.request.body) if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS: logging.debug(dati) user_data = dati["User"] lower_email = user_data["Email"].lower() temp_user = User.static_querySearch_email(lower_email) if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS: logging.debug(temp_user) id_user = temp_user.get() if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS: logging.debug(id_user.key.id()) cars = User_car.getCarFromUser(id_user.key.id()) if (cars.count() == 0): allcars = [] right = StatusReturn(3, "getAllCars_fromEmail", allcars) self.response.write(right.print_result()) else: allcars = [] for id_carTemp in cars: if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS: logging.debug(id_carTemp) allcars.append(Car.get_json(long(id_carTemp.id_car))) right = StatusReturn(3, "getCars", allcars) self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("removeContactCar", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] latitude = dati["Latitude"] longitude = dati["Longitude"] temp_user = User.static_querySearch_email(user_data["Email"]) id_user = temp_user.get().key.id() timestamp = dati["Timestamp"] if History_park.parky(id_user, latitude, longitude, timestamp) == 1: if static_variable.DEBUG: logging.debug( "The application has to send notification? --> " + str(True)) right = StatusReturn(20, "getNotification", True) self.response.write(right.print_result()) else: if static_variable.DEBUG: logging.debug( "The application has to send notification? --> " + str(False)) right = StatusReturn(21, "getNotification", False) self.response.write(right.print_result())
def return_id_from_email(email): temp_key_user = User.static_querySearch_email(email) try: temp_id_user = temp_key_user.get().key.id() return temp_id_user except: return -1
def return_groups(email): temp_key_user = User.static_querySearch_email(email) try: temp_id_user = temp_key_user.get().key.id() id_groups = User_group.getGroupFromUser(temp_id_user) return id_groups except: return -1
def post(self): if User_tool.check_before_start("createCar", self) >= 0: dati = json.loads(self.request.body) car_data = dati["Car"] user_data = dati["User"] bluetooth_MAC = "" bluetooth_name = "" register = "" uuid = "" bmaj = "" bmin = "" marker_color = None if "Bluetooth_MAC" in car_data: bluetooth_MAC = car_data["Bluetooth_MAC"] if "Bluetooth_Name" in car_data: bluetooth_name = car_data["Bluetooth_Name"] if "Register" in car_data: register = car_data["Register"] if "Marker_Color" in car_data: marker_color = car_data["Marker_Color"] new_car = Car(name=car_data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()), email=user_data["Email"], bluetooth_MAC=bluetooth_MAC, bluetooth_name=bluetooth_name, brand=car_data["Brand"], register=register, isParked=False, lastdriver=user_data["Email"], uuid=uuid, marker_color=marker_color) new_car = new_car.put() list_user = car_data["Users"] searchuser = User.static_querySearch_email(user_data["Email"]) for user in searchuser: if static_variable.DEBUG: logging.debug(user.key.id()) new_contact_car = User_car(id_user=user.key.id(), id_car=(new_car.id())) new_contact_car.put() for user in list_user: userEmail = user["Email"] user_key = User.is_user_check(userEmail) if user_key == 0: new_user = User(id_android=None, code=0, temp_code=0, email=userEmail, nickname=None, is_user=0) temp_user_key = new_user.put() user_key = temp_user_key.id() if User_car.check_user_exist(user_key, new_car.id()) > 0: new_contact_car = User_car(id_user=user_key, id_car=new_car.id()) new_contact_car.put() right = StatusReturn(4, "createCar", new_car.id()) self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("updatePosition", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] temp_user = User.static_querySearch_email(user_data["Email"]) car_data = dati["Car"] timestamp = str(datetime.datetime.utcnow() + datetime.timedelta(hours=1)) if "Timestamp" in car_data: timestamp = car_data["Timestamp"] Car.update_position_ID(car_data["ID_car"], car_data["Latitude"], car_data["Longitude"], user_data["Email"]) list_user = User_car.getUserFromCar(car_data["ID_car"]) # Send notification to all user register with this car for user in list_user: # If the user is not registered inside the application send him an email if User.is_registered_check(user.id_user) == 0: if User.get_email_user(user.id_user) != user_data["Email"]: # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"], # car_data["Longitude"], user_data["Name"],car_data["Name"]) logging.debug("Update position") else: if User.get_email_user(user.id_user) != user_data["Email"]: Push_notification.send_push_park( User.get_id_android(user.id_user), car_data["Name"], user_data["Name"], car_data["ID_car"]) if static_variable.DEBUG: logging.debug("Date if car: " + car_data["Name"]) id_user = temp_user.get().key.id() if static_variable.DEBUG: logging.debug(timestamp) History_park.update_history(id_user, car_data["Latitude"], car_data["Longitude"], timestamp) right = StatusReturn(5, "updatePosition") self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("deleteGroup", self) >= 0: data = json.loads(self.request.body) id_group = long(data["ID_group"]) temp_user = User.static_querySearch_email(data["Email"]) User_group.delete_contact_group(temp_user.get().key.id(), id_group) logging.debug(User_group.getUserFromGroup(id_group).count()) if User_group.getUserFromGroup(id_group).count() == 0: Group.delete_group_ID(id_group) list_car = Car_group.getCarFromGroup(id_group) for cars in list_car: Car_group.delete_car_ID(cars.id_car, id_group) right = StatusReturn(8, "deleteGroup", "Removed From: " + str(id_group)) self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("updatePosition", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] temp_user = User.static_querySearch_email(user_data["Email"]) car_data = dati["Car"] timestamp = str(datetime.datetime.utcnow() + datetime.timedelta(hours=1)) if "Timestamp" in car_data: timestamp = car_data["Timestamp"] Car.update_position_ID(car_data["ID_car"], car_data["Latitude"], car_data["Longitude"], user_data["Email"]) list_user = User_car.getUserFromCar(car_data["ID_car"]) # Send notification to all user register with this car for user in list_user: # If the user is not registered inside the application send him an email if User.is_registered_check(user.id_user) == 0: if User.get_email_user(user.id_user) != user_data["Email"]: # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"], # car_data["Longitude"], user_data["Name"],car_data["Name"]) logging.debug("Update position") else: if User.get_email_user(user.id_user) != user_data["Email"]: Push_notification.send_push_park(User.get_id_android(user.id_user), car_data["Name"], user_data["Name"], car_data["ID_car"]) if static_variable.DEBUG: logging.debug("Date if car: "+car_data["Name"]) id_user = temp_user.get().key.id() if static_variable.DEBUG: logging.debug(timestamp) History_park.update_history(id_user,car_data["Latitude"],car_data["Longitude"], timestamp) right = StatusReturn(5, "updatePosition") self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("removeContactCar", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] car_data = dati["Car"] for userClass in car_data["Users"]: user = userClass["Email"] if static_variable.DEBUG: logging.debug("Email: " + str(user)) tempUser = User.static_querySearch_email(user) for id_user in tempUser: user_key = id_user.key.id() User_car.deleteCarUser(user_key, car_data["ID_car"]) # user_car = User_car.getUserFromCar(car_data["ID_car"]) # if (user_car.count() == 0): # Car.delete_car_ID(car_data["ID_car"]) right = StatusReturn(18, "removeContactCar") self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("removeContactCar", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] car_data = dati["Car"] for userClass in car_data["Users"]: user = userClass["Email"] if static_variable.DEBUG: logging.debug("Email: "+str(user)) tempUser = User.static_querySearch_email(user) for id_user in tempUser: user_key = id_user.key.id() User_car.deleteCarUser(user_key, car_data["ID_car"]) # user_car = User_car.getUserFromCar(car_data["ID_car"]) # if (user_car.count() == 0): # Car.delete_car_ID(car_data["ID_car"]) right = StatusReturn(18, "removeContactCar") self.response.write(right.print_result())
def post(self): if User_tool.check_before_start("deleteCar", self) >= 0: dati = json.loads(self.request.body) user_data = dati["User"] car_data = dati["Car"] temp_user = User.static_querySearch_email(user_data["Email"]) user = temp_user.get() id_user = user.key.id() User_car.deleteCarUser(id_user, car_data["ID_car"]) user_car = User_car.getUserFromCar(car_data["ID_car"]) if static_variable.DEBUG: logging.debug("Number of car with this user: "******"ID_car"]) right = StatusReturn(7, "deleteCar") self.response.write(right.print_result())
def getUser(self): user = User.static_querySearch_email(self.id_user) return user