Ejemplo n.º 1
0
def load_people_from_affiliations(infile):
    """ Loads a set of Person-Corp relations, and creates Person objects from
    them. Checks for pre-existing Persons.
    Returns an array of affiliation objects parsed from JSON for use in
    loading affiliations. """
    objects = []
    i = 0
    for l in infile:
        if i % 1000 == 0:
            print i
        i += 1
        data = json.loads(l)
        if PersonForm(data['person']).is_valid():
            pers = Person(**data['person'])
            try:
                Person.objects.get(personal_code=pers.personal_code)
            except ObjectDoesNotExist:  #TODO: Merge person data
                pers.save()
def create(request):
    errors = []
    person = Person()
    person.first_name = request.POST.get('first_name')
    person.last_name = request.POST.get('last_name')
    person.zip_code = request.POST.get('zip')
    person.city = request.POST.get('city')
    if len(request.POST.get('first_name')) < 4:
        errors.append('First name must be at least 4 characters!')
    if len(request.POST.get('last_name')) < 4:
        errors.append('Last name must be at least 4 characters!')
    if len(request.POST.get('zip')) < 5:
        errors.append('Must enter a valid zip code!')
    if len(request.POST.get('city')) < 4:
        errors.append('City must be at least 4 characters!')
    if not errors:
        person.save()
        return redirect('/')
    else:
        return render(request, 'person/new.html', {'errors': errors})
Ejemplo n.º 3
0
def parse_person(json_string):
    """ Takes a json object and converts it into a Person object."""
    data = json.loads(corp_string)
    # Keys are identical in scrapy and Django, and no processing needed
    return Person(**data)