Esempio n. 1
0
def river_name_input(request):
    # print get_ip(request)
    # print request.POST
    river_info = json.loads(request.POST['river_name'])
    river_name = river_info['river_name']
    object_id = river_info['object_id']
    # print river_name
    # print object_id
    # latitude = request.POST['latitude']
    # longitude = request.POST['longitude']
    # river_id = request.POST['river_id']
    
    # print 'river name:', river_name
    # print 'latitude:', latitude
    # print 'longitude:', longitude
    
    # context = {
        # 'river_name': 'yr',
        # 'latitude': latitude,
        # 'longitude': longitude,
    # }
    
    P = Point(point_name=river_name, object_id=object_id)
    P.save()
    # print 'saved'
    
    # return render(request, 'crowdsource/river_name_response.html', context)
    return HttpResponse(status=200)
Esempio n. 2
0
def submitPoint(request):
	userName = getUserName(request)
	if userName == None:
		return HttpResponseRedirect("/")

	pointDesc = ""

	maplerId = int(request.POST['maplerId'])
	if maplerId == -1: # new point
		newPoint = Point(owner=request.user)
		updatePointAccordingToForm(request.POST, newPoint)
		pointDesc = newPoint.description
		newPoint.save()
	else:
		point = Point.objects.get(pk=maplerId)
		if point.owner.username == userName:
			updatePointAccordingToForm(request.POST, point)
			pointDesc = point.description
			point.save()

	logRecord = UserLog()
	logRecord.ip = str(get_client_ip(request))
	logRecord.user = request.user
	logRecord.comment="Pt submit: " + pointDesc
	logRecord.save()

	return HttpResponseRedirect("/map/manage-points/")
Esempio n. 3
0
 def test_filter_points(self):
     point1 = Point(**point_data_1)
     point1.save()
     point2 = Point(**point_data_2)
     point2.save()
     assert [x for x in filter_points(100, 0, 100, 0)] == [point1]
     assert [x for x in filter_points(0, -20, 50, 0)] == [point2]
Esempio n. 4
0
 def create(self, request):
     """ """
     point = Point(**json.loads(request.form.cleaned_data['geo']))
     point.save()
     request.form.cleaned_data['geo'] = point
     wifi = Wifi(**request.form.cleaned_data)
     wifi.save()
     return rc.CREATED
Esempio n. 5
0
def init_db():
    # Create the fixtures
    point = Point(name='John Smith',
                  latitude='0',
                  longitud='0.1',
                  phone='+79000000000')
    point.save()

    config = Config(version=1, allowedRadius=1000, isDayPeriodAllowed=True)
    config.save()
Esempio n. 6
0
def setPoint(request, flag, pid, oid, name, description, longitude, latitude, index):
    if request.user.is_authenticated():
        try :
            newOid = int(oid)
            newName = replace(name, "_", " ")
            newDescription = replace(description, "_", " ")
            newIndex = int(index)
            p = Point(oid=Object.objects.get(oid=newOid), name=newName, description=newDescription, index=newIndex, longitude=longitude, latitude=latitude)
            p.save()
            return success()
            #return HttpResponse("insert_"+str(o.oid))
        except :
            return HttpResponse("Erreur "+traceback.format_exc())
    return failure()
Esempio n. 7
0
def incoming(request):
    logging.warning(request.GET)
    try:
        # p#, lat, long, timestamp
        message = request.GET['text']
        phone_no, lat, lon, time = message.split(',')
        p = Point(phone_no=phone_no, lat=float(lat), lon=float(lon), time=datetime.fromtimestamp(float(time)))
        p.save()
	post(phone_no, lat, lon, time)
    except ValueError as err:
        print "Not Recorded: {}".format(err.args[0])
        raise(err)

    return HttpResponse("RECEIVING SMS")
Esempio n. 8
0
def add_tags_and_points(chart, data, tags=[]):
    for key in data:
        try:
            tag = Tag.objects.get(short=key)
        except ObjectDoesNotExist:
            tag = Tag(short=key)
            tag.save()
        value = data[key]
        if isinstance(value, int):
            point = Point(value=value)
            point.chart = chart
            point.save()
            point.tags.add(tag)
            for t in tags:
                point.tags.add(t)
        else:
            add_tags_and_points(chart, value, [tag] + tags)
Esempio n. 9
0
def add_tags_and_points(chart,data,tags = []):
	for key in data:
		try:
			tag = Tag.objects.get(short=key)
		except ObjectDoesNotExist:
			tag = Tag(short=key)
			tag.save()
		value = data[key]
		if isinstance(value, int):
			point = Point(value=value)
			point.chart = chart
			point.save()
			point.tags.add(tag)
			for t in tags:
				point.tags.add(t)
		else:
			add_tags_and_points(chart,value,[tag]+tags)
Esempio n. 10
0
def new(request):
    """
    Funkcja zwraca stronę z formularzem do dodania nowego punktu lub dodaje punkt
    w zależności od typus żądania: GET (utwórz formularz) lub POST (zapisz formularz).

    .. include:: ../source/login_required.rst
    """
    if request.method == 'POST':
    	form = NewPointForm(request.POST)
        if form.is_valid():
            point = Point()
            point.user = request.user
            point.desc = form.cleaned_data['desc']
            point.latit = float(form.cleaned_data['latit'])
            point.longi = float(form.cleaned_data['longi'])
            messages.success(request, ADDED)
            point.save()
    return HttpResponseRedirect('/')