Ejemplo n.º 1
0
def edit_profile(request):
    user = request.user
    mi = get_memberinfo(user)
    error = None

    if request.method == 'POST':
        form = MemberInfoForm(request.POST)
        if form.is_valid():
            fill_member_from_form(mi, form)
            mi.save()

            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()

            return redirect('views_user-profile')
    else:
        data = {}
        data['first_name'] = user.first_name
        data['last_name'] = user.last_name
        data['usda_zone'] = mi.usda_zone
        data['email'] = user.email
        data['email_is_public'] = mi.email_is_public
        data['phone'] = mi.phone
        data['phone_is_public'] = mi.phone_is_public
        try:
            sl, cc = mi.street_address.rsplit('~ ', 1)
        except:
            sl = mi.street_address
            cc = "US"
        data['country_code'] = cc
        if cc == 'US':
            try:
                sl, c, s, z = sl.split('~ ', 3)
            except:
                sl = sl
                c = ""
                s = "AL"
                z = "11111"
            data['street_line'] = sl
            data['city'] = c
            data['state'] = s
            data['zipcode'] = z
        else:
            data['street_line'] = sl
        data['street_address_is_public'] = mi.street_address_is_public
        data['mailing_address'] = mi.mailing_address
        data['mailing_address_is_public'] = mi.mailing_address_is_public
        data['about_me'] = mi.about_me
        data['external_url'] = mi.external_url
        data['include_in_member_profiles'] = mi.include_in_member_profiles

        form = MemberInfoForm(data)

    return render_to_response('profile-edit.html', {
        "form": form,
        "error": error
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def new_user(request):

    if request.method == 'POST':
        miform = MemberInfoForm(request.POST)
        uiform = ModifiedUserCreationForm(request.POST)
        if miform.is_valid() and uiform.is_valid():
            user = User.objects.create_user(
                uiform.cleaned_data['username'],
                miform.cleaned_data['email'],
                uiform.cleaned_data['password1'],
                first_name=miform.cleaned_data['first_name'],
                last_name=miform.cleaned_data['last_name'],
            )
            user.save()

            mi = MemberInfo.objects.create(user=user)
            fill_member_from_form(mi, miform)
            mi.save()
            authuser = authenticate(username=user.username,
                                    password=uiform.cleaned_data['password1'])
            if authuser is not None:
                if authuser.is_active:
                    login(request, authuser)
                    return redirect('seednetwork-home')

        return render_to_response('profile-create.html', {
            "miform": miform,
            "uiform": uiform
        },
                                  context_instance=RequestContext(request))

    return redirect('seednetwork-home')
Ejemplo n.º 3
0
def new_user(request):

	if request.method == 'POST':
		miform = MemberInfoForm(request.POST)
		uiform = UserCreationForm(request.POST)
		if miform.is_valid() and uiform.is_valid():
			user = User.objects.create_user(
				uiform.cleaned_data['username'],
				miform.cleaned_data['email'],
			    uiform.cleaned_data['password1'],
			    first_name = miform.cleaned_data['first_name'],
			    last_name = miform.cleaned_data['last_name'],
			    )
			user.save()

			mi = MemberInfo.objects.create(user=user)
			fill_member_from_form(mi, miform)
			mi.save()
			authuser = authenticate(username=user.username, password=uiform.cleaned_data['password1'])
			if authuser is not None:
				if authuser.is_active:
					login(request, authuser)
					return redirect('seednetwork.views.home')


		return render_to_response('profile-create.html',
			{ "miform": miform, "uiform": uiform },
              context_instance=RequestContext(request))

	return redirect('seednetwork.views.home')
Ejemplo n.º 4
0
def home(request):

	login_form = AuthenticationForm()
	create_user_form = ModifiedUserCreationForm()
	member_info_form = MemberInfoForm()

	return render_to_response('home.html',
			{ 'login_form': login_form,
			  'create_user_form': create_user_form,
			  'member_info_form': member_info_form
			},
			context_instance=RequestContext(request))
Ejemplo n.º 5
0
def edit_profile(request):
	user = request.user
	mi = get_memberinfo(user)
	error = None

	if request.method == 'POST':
		form = MemberInfoForm(request.POST)
		if form.is_valid():
			fill_member_from_form(mi, form)
			mi.save()

			user.first_name = form.cleaned_data['first_name']
			user.last_name = form.cleaned_data['last_name']
			user.email = form.cleaned_data['email']
			user.save()

			return redirect('seednetwork.views_user.profile')
	else:
		data = {}
		data['first_name'] = user.first_name
		data['last_name'] = user.last_name
		data['email'] = user.email
		data['email_is_public'] = mi.email_is_public
		data['town'] = mi.town
		data['phone'] = mi.phone
		data['phone_is_public'] = mi.phone_is_public
		data['street_address'] = mi.street_address
		data['street_address_is_public'] = mi.street_address_is_public
		data['mailing_address'] = mi.mailing_address
		data['mailing_address_is_public'] = mi.mailing_address_is_public
		data['about_me'] = mi.about_me
		data['include_in_member_profiles'] = mi.include_in_member_profiles
		
		form = MemberInfoForm(data)

	return render_to_response('profile-edit.html',
		{ "form": form, "error": error },
        context_instance=RequestContext(request))