Exemplo n.º 1
0
def UserRegistration(request):
    ''' Registers credentials for a user '''
    
    # get my urls
    urls = genurls()
        
    if request.user.is_authenticated():
        return HttpResponseRedirect(urls['home'])
    
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(username=form.cleaned_data['username'],
                                                      email=form.cleaned_data['email'],
                                                      password=form.cleaned_data['password1'],)
            user.save()
            person = Person(user=user, 
                            firstname=form.cleaned_data['firstname'],
                            surname=form.cleaned_data['surname'], 
                            institute=form.cleaned_data['institute'])
            person.save()
            
            return HttpResponseRedirect(urls['home'])
        else:
            # get my urls
            urls = genurls()
            return render_to_response('page/register.html', {'form': form, 'urls':urls}, context_instance=RequestContext(request))
            
    else:
        ''' user is not submitting a form therefore show a registration form '''
        urls = genurls()
        form = RegistrationForm()
        context = {'form': form, 'urls':urls}
        return render_to_response('page/register.html', context, context_instance=RequestContext(request))
Exemplo n.º 2
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()
Exemplo n.º 3
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})
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})
Exemplo n.º 6
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)