def save(request): if request.is_ajax(): success_message = "saved!" invalid_name_message = "the name you entered is invalid" address = request.POST.get('address', False) lng = request.POST.get('longitude', False) lat = request.POST.get('latitude', False) name = request.POST.get('name', False).strip() if not re.search('^\w* \w*$', name): return HttpResponse(invalid_name_message) firstName = name.split(' ')[0] lastName = name.split(' ')[1] employee = Employee.objects.filter(firstName=firstName, lastName=lastName) if not employee: employee = Employee(firstName=firstName, lastName=lastName, numLocations=0) employee.save() else: employee = employee[0] location = Location(lat=lat, lng=lng, address=address, employee=employee, time=datetime.datetime.utcnow()) location.save() employee.numLocations += 1 employee.save() return HttpResponse(success_message)
def checkout_location(db): loc = Location( service=Location.CHECKOUT, name="Test Checkout Location", address="119 Orange St, Durham, NC 27701" ) loc.save() return loc
def create_location(request): if request.method == 'POST': print request.POST name = request.POST['Location'] print "NAME= " + str(name) if name is None: return HttpResponse(status=400) location = Location(name=name) location.save() return HttpResponseRedirect('/fertilizer/index.html#/create')
def build_medical_center(medical_center, request): medical_center_model = MedicalCenter() medical_center_model.balanced = medical_center['balanced'] medical_center_model.distance = medical_center['distance'] location = Location() location.latitude = medical_center['location']['latitude'] location.longitude = medical_center['location']['latitude'] medical_center_model.location = location medical_center_model.name = medical_center['name'] medical_center_model.request = request return medical_center_model
def save_data(data): init_db() request = Request() request.distance_imbalance = data['calculate'] user_location = Location() user_location.latitude = data['user_location']['latitude'] user_location.longitude = data['user_location']['latitude'] request.location = user_location request.radius = data['radius'] medical_centers = [ build_medical_center(medical_center, request) for medical_center in data['medical_centers'] ] request.medical_centers = medical_centers db_session.add(request) db_session.commit()
def test_location_model(self): l1 = Location(street_number="3", route="impasse des argelas", locality="Le Teil", postal_code="07400", coutry="FR", lat=44.5523379, lng=4.6755323) l1.save() l2 = Location().geocode_raw_address() self.assertEquals(l1.getPoint(), l2.getPoint())
def quickCreate(name, sport, distance, city, date): """ example : quickCreate(name="Triathlon de Montélimar", sport="Triathlon", distance="XS", city="Montélimar", date="25/06/2015") """ s = Sport try: s = Sport.objects.get(name=sport) except Sport.DoesNotExist: print("Sport {0} does not exist".format(sport)) dc = DistanceCategory try: dc = DistanceCategory.objects.get(name=distance) except DistanceCategory.DoesNotExist: print("Distance {0} does not exist".format(distance)) e = Event(name=name, edition=1) e.save() c = Contact(name="Pierre Dupont") c.save() l = Location(country=Location.objects.all()[0].country, city=city) l.save() r = Race( sport=s, event=e, date=datetime.strptime(date, "%d/%m/%Y"), distance_cat=dc, price=40, contact=c, location=l, ) r.save() return r
def get(self, request): try: result = dict() location = Location.locationQuery(**request.query_params) locationSerializer = LocationSerializer(location['items'], many=True) result['data'] = locationSerializer.data result['draw'] = location['draw'] result['recordsTotal'] = location['total'] result['recordsFiltered'] = location['count'] return Response(result, status=status.HTTP_200_OK, template_name=None, content_type=None) except Exception as e: return Response(e, status=status.HTTP_404_NOT_FOUND, template_name=None, content_type=None)
def setUpTestData(cls): cls.user: CustomUser = get_user_model() cls.user_data: dict = {'username': '******', 'password': '******'} cls.testuser = cls.user.objects.create_user(**cls.user_data) cls.productCode_data: dict = \ {'code': '00000', 'codeName': '맛있는계란', 'type': '전란', 'amount_kg': 0.50, 'price': 1000} cls.productCode = ProductCode(**cls.productCode_data) cls.productCode.save() cls.location_data: dict = \ {'code': '00000', 'codeName': '전산팀', 'type': '판매', 'location_manager': cls.testuser} cls.location = Location(**cls.location_data) cls.location.save() cls.order_data = \ {'ymd': '20191230', 'count': 2, 'amount': 1.00, 'memo': 'test', 'productCode': cls.productCode, 'orderLocationCode': cls.location, 'orderLocationName': cls.location.codeName, 'type': '판매'} cls.order_data: dict = dict(cls.productCode_data, **cls.order_data) cls.order = Order(**cls.order_data) cls.order.save()