Example #1
0
def populate_by_qs(s, output=stdout):
    encoded_s = s.encode('utf-8')
    output.write('QUERYING FOR %s\n' % encoded_s)
    body = send_req('querystation.asp', {'inpPointFr': encoded_s})
    tree = ElementTree()
    tree.parse(StringIO(body))
    root = tree.getroot()
    points = root.getiterator(NS + 'Point')
    for point in points:
        station = Station()
        station.identifier = int(point.find(NS + 'Id').text)

        try:
            station = Station.objects.get(identifier=station.identifier)
        except Station.DoesNotExist:
            station.name = point.find(NS + 'Name').text
            station.x = int(point.find(NS + 'X').text)
            station.y = int(point.find(NS + 'Y').text)
            station.save()
            output.write('  STORED %s\n' % station.name.encode('utf-8'))
        except Station.MultipleObjectsReturned:
            output.write('  ERROR %d, %s\n' %
                         (station.identifier, station.name.encode('utf-8')))
        else:
            # output.write('  IGNORE %s\n' % (station.name.encode('utf-8')))
            pass
Example #2
0
def addStation(data):
    try:
        stationType_id = int(data["stationType"])
        serialNum = data["serialNum"]
        latitude = float(data["latitude"])
        longitude = float(data["longitude"])
        frequency = data["frequency"]
        token = data["token"]

        # se recupera el tipo de estacion
        stationType = StationType.objects.get(id=stationType_id)
        automatic = stationType.automatic
        # se crea una estacion
        station = Station()
        station.serialNum = serialNum
        station.location = Point(longitude, latitude)
        station.active = True
        station.stationType = stationType

        # si la estacion es automatica
        # se agregan la frecuencia
        # y el token
        if (automatic == True):
            if (frequency == "" or token == ""):
                return "Error: faltan argumentos"
            frequency = float(frequency)
            if (frequency <= 0):
                return "Error: frecuencia debe ser mayor que cero"
            station.frequency = frequency
            station.token = token

        station.save()
    except Exception as e:
        return "Error " + str(e)
    return None
Example #3
0
def submitstation(request):

    if request.method == 'POST':
        form = StationForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

            mystation = Station(lat = cd['latitude'],
                                lon = cd['longitude'],
                                why = cd['why'],
                                comment = cd['comment'],
                                creator = request.user,
                                like = 0,
                                dontlike= 0,
                                dontcare = 0,
                                nbsupports = 0,
                                activated = 'A')

            mystation.save()

            mystations=Station.objects.all()[0:1]
            return HttpResponseRedirect('/stations?id={0}'.format(mystations[0].id))

    else:

        form = StationForm()

    return render_to_response('submitstation.html',
                                  {'current_menu':'station',
                                   'me': request.user.username,
                                   'form': form},
                                  context_instance=RequestContext(request))
Example #4
0
    def post(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            station_id = int(request.POST.get('stationId'))
            name = request.POST.get('name')
            location = request.POST.get('location')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            remark_1 = request.POST.get('remark1', '')
            remark_2 = request.POST.get('remark2', '')
            remark_3 = request.POST.get('remark3', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_station = Station.objects.get(id=station_id)
        district_id = cur_station.district_id
        section_id = cur_station.section_id
        new_station = Station(name=name,
                              location=location,
                              channel=channel,
                              remark1=remark_1,
                              call_sign=call_sign,
                              remark2=remark_2,
                              remark3=remark_3,
                              district_id=district_id)
        try:
            with transaction.atomic():
                new_station.save()
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_SAVE_INFO_FAIL,
                status.HTTP_500_INTERNAL_SERVER_ERROR)
        chief = cur_station.chief.all()
        trans = cur_station.exec_chief_trans.all()
        for item in chief:
            new_station.chief.add(item)
        for item in trans:
            new_station.exec_chief_trans.add(item)

        # 路的段/岗数量更新
        if section_id:
            road_id = Section.objects.get(id=section_id).road_id
            if road_id:
                cur_guard_road = guard_road.objects.filter(uid=road_id +
                                                           increment)
                cur_guard_road.update(sectionnum=F('stationnum') + 1)
        return Response(response_data, status.HTTP_200_OK)