def save(entity): if entity.key is None: entity = Driver.save(entity) else: current = Driver.get(entity.key) if current is not None: # current.driver_phone = entity.driver_phone # current.driver_email = entity.driver_email # current.driver_id = entity.driver_id # current.driver_operational = entity.driver_operational # current.driver_name = entity.driver_name entity = Driver.save(entity) else: raise ValueError("Driver does not exists") return entity
def drivers(request): if request.method == 'GET': data = serializers.serialize("json", Driver.objects.all()) return HttpResponse(data, content_type='application/json') if request.method == 'POST': req = json.loads(request.body) for item in req: name = item['driverName'].split(" ") firstName = name[0] lastName = name[1] id = item['driverId'] startTime = item['driverStartTime'] endTime = item['driverEndTime'] time = item['driverBlockTime'] try: Block.objects.get(startTime=startTime) except: block = Block(startTime=startTime, endTime=endTime, shiftLength=time) block.save() try: Driver.objects.get(DPID=id) except ObjectDoesNotExist: block = Block.objects.get(startTime=startTime) driver = Driver(DPID=id, firstName = firstName, lastName = lastName, shiftLength = time, startTime = startTime, endTime = endTime, block = block ) driver.save() return HttpResponse("Kevin is the greatest of all time --drivers")