示例#1
0
def postIncident(request):
	incidentForm = IncidentForm(request.POST)
	incidentForm.data = incidentForm.data.copy()

	# Convert coords to valid geometry
	try:
		incidentForm.data['geom'] = normalizeGeometry(incidentForm.data['geom'])
	except(ValueError):
		messages.error(request, '<strong>Error</strong><br>No point was selected for this type of report.')
		return HttpResponseRedirect(reverse('mapApp:index'))

	# Set p_type field to collision, nearmiss, or fall
	incidentForm.data['p_type'] = getIncidentType(incidentForm.data['i_type'])

	# Validate and submit to db
	if incidentForm.is_valid():
		incident = incidentForm.save()
		alertUsers(request, incident)

		messages.success(request, '<strong>Thank you!</strong><br>Your incident marker was successfully added.')
		return HttpResponseRedirect(reverse('mapApp:index', \
			kwargs=({										\
				"lat":str(incident.latlngList()[0]),		\
				"lng":str(incident.latlngList()[1]),		\
				"zoom":str(18)								\
			})												\
		))
	else: # Show form errors
		return render(request, 'mapApp/index.html', indexContext(request, incidentForm=incidentForm))
示例#2
0
def postTheft(request):
	theftForm = TheftForm(request.POST)
	theftForm.data = theftForm.data.copy()

	# Convert coords to valid geometry
	try:
		theftForm.data['geom'] = normalizeGeometry(theftForm.data['geom'])
	except(ValueError):
		messages.error(request, '<strong>Error</strong><br>No point was selected for this type of report.')
		return HttpResponseRedirect(reverse('mapApp:index'))

	# Set p_type
	theftForm.data['p_type'] = 'theft'

	if theftForm.is_valid():
		theft = theftForm.save()
		alertUsers(request, theft)

		messages.success(request, '<strong>Thank you!</strong><br>Your theft marker was successfully added.')
		return HttpResponseRedirect(reverse('mapApp:index', \
			kwargs=({										\
				"lat":str(theft.latlngList()[0]),		\
				"lng":str(theft.latlngList()[1]),		\
				"zoom":str(18)								\
			})												\
		))

	else: # Show form errors
		return render(request, 'mapApp/index.html', indexContext(request, theftForm=theftForm))
示例#3
0
 def post(self, request, format=None):
     serializer = HazardSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         if serializer.data['properties'] is not None:
            if serializer.data['properties']['pk'] is not None:
               hazard = Hazard.objects.get(pk=(serializer.data['properties']['pk']))
               alertUsers(request, hazard)
               # Errors with push notifications should not affect reporting
               try:
                   pushNotification.pushNotification(hazard)
               except:
                   pass
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#4
0
 def post(self, request, format=None):
     serializer = HazardSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         if serializer.data['properties'] is not None:
            if serializer.data['properties']['pk'] is not None:
               hazard = Hazard.objects.get(pk=(serializer.data['properties']['pk']))
               alertUsers(request, hazard)
               # Errors with push notifications should not affect reporting
               try:
                   pushNotification.pushNotification(hazard)
               except:
                   pass
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)