예제 #1
0
    def store_data(self, incident_data):
        incident_type, created = IncidentType.objects.get_or_create(
            type_name=incident_data['type'])
        incident = None
        try:
            incident = Incident.objects.get(
                incident_id=incident_data['incident_id'])
        except Incident.DoesNotExist:
            if incident_data['status'] == 'active':
                incident_args = {'incident_id': incident_data['incident_id'],
                                 'type': incident_type,
                                 'location_text': incident_data['location'],
                                 'level': incident_data['level']
                                 }
                incident = Incident()
                incident.create_incident(**incident_args)

                self.incident_logger.info("start, id: %s, type_id:"
                                          "\"%s\", loc_str: %s, lvl: %s"
                                          % (incident.incident_id,
                                             incident.type.type_name,
                                             incident.location_text,
                                             incident.level))

        if incident is not None and incident_data['status'] == 'closed' and \
                incident.end is None:
            incident.end = timezone.now()
            incident.save()
            self.incident_logger.info("end, id: %s" % incident.incident_id)

        for vehic_data in incident_data['units']:
            p = re.compile("([A-Za-z]+)")
            match = p.search(vehic_data)
            type_string = match.group()
            vehic_type, created = VehicleType.objects.get_or_create(
                name=type_string)

            vehicle, created = \
                Vehicle.objects.get_or_create(name=vehic_data,
                                              defaults={'type': vehic_type})
            if incident is not None:
                try:
                    Dispatch.objects.get(vehicle_id=vehicle,
                                         incident_id=incident)
                except ObjectDoesNotExist:
                    dispatch = Dispatch()
                    dispatch.dispatch(vehicle_id=vehicle,
                                      incident_id=incident)
                    self.dispatch_logger.info("vehic: %s, incident: %s" %
                                              (vehicle.name,
                                               incident.incident_id))
                    pass
예제 #2
0
def incident(request):
    if request.method == 'POST':
        form = Incident_Report_Form(request.POST, request.FILES)
        if form.is_valid():
            print "form was valid"

            cd = form.cleaned_data
            print "cd: ", cd
            i = Incident(description=cd['description'], incident_image=cd['incident_image'], x_gps_coordinate=cd['x_gps_coordinate'],
                         y_gps_coordinate=cd['y_gps_coordinate'], pub_date=timezone.now())
            i.save()
            return HttpResponse("Thank You!")
    else:
        print "Generating form:"
        form = Incident_Report_Form()
    return render(request, 'incident_report/incident.html', {'form':form})
예제 #3
0
def receive_incident(request):
    #print "LOL"
    print "Request: ", request
    try:
        #print "Data: ", data

        latitude = request.POST['LATITUDE']
        print "got latitude"
        longitude = request.POST['LONGITUDE']
        print "got longitude"
        description = request.POST['DESCRIPTION']
        print "got description"
        image = request.FILES['PHOTOGRAPH']
        today = now()
        print "\n\n\nDescription: ", description
        i = Incident(description=description, incident_image=image, x_gps_coordinate=latitude, y_gps_coordinate=longitude,
                    pub_date=today)
        i.save()
    except:
        print "Could not parse json"



    return HttpResponse("")