Exemple #1
0
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)
Exemple #2
0
def checkout_location(db):
    loc = Location(
        service=Location.CHECKOUT,
        name="Test Checkout Location",
        address="119 Orange St, Durham, NC 27701"
    )
    loc.save()
    return loc
Exemple #3
0
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')
Exemple #4
0
    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())
Exemple #5
0
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