Ejemplo n.º 1
0
def create_prisoner(prisoner_name, prisoner_id, prisoner_address, prison_id,
                    rules):

    if prisoner_name is None:
        raise Exception("Prisoner must have a name")
    if prisoner_id is None:
        raise Exception("Prisoner must have an address")
    if prisoner_address is None and prison_id == -1:
        raise Exception(
            "Prisoner Address and Prison cannot both be unspecified")
    prisoner_address.save()
    prisoner_id = str(prisoner_id)
    sanitized_id = filter(str.isalnum, prisoner_id)
    prison = None
    if int(prison_id) != -1:
        prison = Prison.objects.get(pk=prison_id)
    p = Prisoner(name=prisoner_name,
                 prisoner_id=sanitized_id,
                 prisoner_id_raw=prisoner_id,
                 active=True,
                 prison=prison,
                 address=prisoner_address,
                 rules=rules)
    p.save()
    return p.prisoner_id
Ejemplo n.º 2
0
def create_prisoner(prisoner_name, prisoner_id,
                    prisoner_address, prison_id, rules):
    

    if prisoner_name is None:
        raise Exception("Prisoner must have a name")
    if prisoner_id is None:
        raise Exception("Prisoner must have an address")
    if prisoner_address is None and prison_id == -1:
        raise Exception(
            "Prisoner Address and Prison cannot both be unspecified")
    prisoner_address.save()
    prisoner_id = str(prisoner_id)
    sanitized_id = filter(str.isalnum, prisoner_id)
    prison = None
    if int(prison_id) != -1:
        prison = Prison.objects.get(pk=prison_id)
    p = Prisoner(name=prisoner_name,
                 prisoner_id = sanitized_id,
                 prisoner_id_raw = prisoner_id,
                 active=True,
                 prison=prison,
                 address=prisoner_address,
                 rules=rules)
    p.save()
    return p.prisoner_id
Ejemplo n.º 3
0
def read_file(fname):
    with open(fname, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter='\t')
        header = {}
        pattern = re.compile('[\W_]+')
        for idx, val in enumerate(reader.next()):
            header[val] = idx
        for row in reader:
            if len(row) != len(header):
                continue
            prisoner_id_sanitized = pattern.sub('', row[header['PrisonerID']])
            print "ID: %s " % prisoner_id_sanitized
            if row[header['BookEnrollDate']] == '00/00/00':
                book_date = '2000-01-01'
            else:
                book_date = time.strptime(row[header['BookEnrollDate']],
                                          "%m/%d/%y")
                book_date = datetime.fromtimestamp(time.mktime(book_date))
            print "BookEnrollDate: %s" % book_date

            a = Address(city=row[header['City']],
                        state=row[header['State']],
                        postal_code=row[header['ZipCode']],
                        address_1=row[header['PreAddress']],
                        address_2=row[header['Address']])
            a.save()
            p = Prisoner(name=row[header['FirstName']] + ' ' +
                         row[header['LastName']],
                         prisoner_id_raw=row[header['PrisonerID']],
                         prisoner_id=prisoner_id_sanitized,
                         last_active=book_date,
                         address=a)
            p.save()
Ejemplo n.º 4
0
def input(request):
    first_name = request.GET['first_name']
    last_name = request.GET['last_name']
    address = request.GET['addr']
    pre_address = request.GET['preaddr']
    city = request.GET['city']
    state = request.GET['state']
    zipcode = request.GET['zipcode']
    if isfloat(zipcode):
        zipcode = str(int(float(zipcode)))

    a = Address(city=city,
                state=state,
                postal_code=zipcode,
                address_1=pre_address,
                address_2=address)
    a.save()
    raw_id = request.GET['id']
    if isfloat(raw_id):
        raw_id = str(int(float(raw_id)))
    print raw_id, zipcode
    parsed_id = filter(str.isalnum, str(raw_id))
    p = Prisoner(name=first_name + ' ' + last_name,
                 active=True,
                 address=a,
                 prisoner_id=parsed_id,
                 prisoner_id_raw=raw_id)
    p.save()
    return HttpResponse("%s has prisoner id of %s" % (p.name, p.prisoner_id))
Ejemplo n.º 5
0
def read_file(fname):
    with open(fname, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter='\t')
        header = {}
        pattern = re.compile('[\W_]+')
        for idx, val in enumerate(reader.next()):
            header[val] = idx
        for row in reader:
            if len(row) != len(header):
                continue
            prisoner_id_sanitized = pattern.sub('',row[header['PrisonerID']])
            print "ID: %s " % prisoner_id_sanitized
            if row[header['BookEnrollDate']] == '00/00/00':
                book_date = '2000-01-01'
            else:
                book_date = time.strptime(row[header['BookEnrollDate']], "%m/%d/%y")
                book_date = datetime.fromtimestamp(time.mktime(book_date))
            print "BookEnrollDate: %s" % book_date
            
            a = Address(city=row[header['City']],
                        state=row[header['State']],
                        postal_code=row[header['ZipCode']],
                        address_1=row[header['PreAddress']],
                        address_2=row[header['Address']])
            a.save()
            p = Prisoner(name=row[header['FirstName']] +' '+
                                 row[header['LastName']],
                         prisoner_id_raw=row[header['PrisonerID']],
                         prisoner_id=prisoner_id_sanitized,
                         last_active=book_date,
                         address=a)
            p.save()
Ejemplo n.º 6
0
def input(request):
        first_name=request.GET['first_name'];
        last_name=request.GET['last_name'];
        address=request.GET['addr'];
        pre_address=request.GET['preaddr'];
        city=request.GET['city'];
        state=request.GET['state'];
        zipcode=request.GET['zipcode'];
        if isfloat(zipcode) :
            zipcode=str(int(float(zipcode)))
       
        a = Address(city=city, state=state,
                    postal_code=zipcode,
                    address_1=pre_address,
                    address_2=address)
        a.save()
        raw_id=request.GET['id'];
        if isfloat(raw_id) :
            raw_id=str(int(float(raw_id)))
        print raw_id ,zipcode
        parsed_id = filter(str.isalnum, str(raw_id))
        p = Prisoner(name=first_name+' '+last_name,
                     active=True,
                     address=a,
                     prisoner_id=parsed_id,
                     prisoner_id_raw = raw_id)
        p.save()
        return HttpResponse("%s has prisoner id of %s" % (p.name, p.prisoner_id))