コード例 #1
0
def edit_profile_view(request):

    if request.method == 'POST':
        edit_user_form = EditUserForm(request.POST, instance=request.user)
        edit_profile_form = EditProfileForm(request.POST,
                                            request.FILES,
                                            instance=request.user.profile)

        if edit_user_form.is_valid and edit_profile_form.is_valid:
            user_info = edit_user_form.save()
            profile_info = edit_profile_form.save(commit=False)
            profile_info.user = user_info
            profile_info.save()
            messages.success(request,
                             'Your profile has been successfully updated.')
            return redirect(reverse('index'))

    else:
        edit_user_form = EditUserForm(instance=request.user)
        edit_profile_form = EditProfileForm(instance=request.user.profile)

    return render(request, 'edit_profile.html', {
        'edit_user_form': edit_user_form,
        'edit_profile_form': edit_profile_form
    })
コード例 #2
0
ファイル: views.py プロジェクト: jmorrice/garmsby-snippets
def edit_profile(request):
	user = request.user
	email = user.email
	#after submission
	if request.method == 'POST':
		edit_profile_form = EditProfileForm(request.POST, request.FILES, instance=user.profile)
		edit_user_form = EditUserForm(request.POST, request.FILES, instance=user, request=request)
		#success
		if edit_profile_form.is_valid() and edit_user_form.is_valid():
			ms = MailSnake('f92abfa01e0a9cecc885186de4e37106-us7')
			print user.email
			ms.listUpdateMember(id='ed61191f4e', email_address=email, merge_vars={
				'FNAME':edit_user_form.cleaned_data.get('first_name'),
				'LNAME':edit_user_form.cleaned_data.get('last_name'),
				'EMAIL':edit_user_form.cleaned_data.get('email'),
				})
			edit_profile_form.save()
			edit_user_form.save()
			return redirect('/profiles/' + user.username)
	#before submission 
	else:
		edit_profile_form = EditProfileForm(instance=user.profile)
		edit_user_form = EditUserForm(instance=user, request=request)

	user_profile = user
	return render(request, 'edit_profile.html', {'edit_profile_form': edit_profile_form, 'edit_user_form': edit_user_form, 'user_profile' : user_profile })
コード例 #3
0
ファイル: views.py プロジェクト: JEscalanteGT/BuzzterCo
def editProfile(request):
    userForm = EditUserForm(request.POST or None, instance=request.user)
    profileForm = EditProfileForm(request.POST or None, request.FILES or None, instance=request.user.profile)
    if userForm.is_valid() and profileForm.is_valid():
            userForm.save()
            profileForm.save()
            return HttpResponseRedirect('/Now/')
    return render_to_response('profiles/editProfile.html',{'userForm':userForm, 'profileForm':profileForm},
                                    context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: sanyaade-teachings/unisubs
def edit(request):
    if request.method == 'POST':
        # the form requires username and email
        # however, letting the user set it here isn't safe
        # (let the account view handle it)
        data = request.POST.copy()
        data['username'] = request.user.username
        data['email'] = request.user.email
        form = EditUserForm(data,
                            instance=request.user,
                            files=request.FILES,
                            label_suffix="")
        if form.is_valid():
            form.save()
            messages.success(request, _('Your profile has been updated.'))
            return redirect('profiles:edit')
    else:
        form = EditUserForm(instance=request.user, label_suffix="")

    context = {
        'form': form,
        'user_info': request.user,
        'edit_profile_page': True
    }
    return direct_to_template(request, 'profiles/edit.html', context)
コード例 #5
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditUserForm(request.POST,
                            instance=request.user,
                            files=request.FILES, label_suffix="")
        if form.is_valid():
            form.save()
            form_validated = True
        else:
            form_validated = False
            
        formset = UserLanguageFormset(request.POST, instance=request.user)
        if formset.is_valid() and form_validated:
            formset.save()
            messages.success(request, _('Your profile has been updated.'))
            return redirect('profiles:my_profile')
    else:
        form = EditUserForm(instance=request.user, label_suffix="")
        formset = UserLanguageFormset(instance=request.user)
    context = {
        'form': form,
        'user_info': request.user,
        'formset': formset,
        'edit_profile_page': True
    }
    return direct_to_template(request, 'profiles/edit_profile.html', context)
コード例 #6
0
ファイル: views.py プロジェクト: red-and-black/goodchat
def profile_edit(request):
    user = request.user
    if request.method == 'POST':
        user_form = EditUserForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST,
                                   instance=Profile.objects.get(user=user))
        if profile_form.is_valid() and user_form.is_valid():
            with transaction.atomic():
                profile_form.save()
                user_form.save()
            return redirect('profile-detail', user.username)
    else:
        profile_form = ProfileForm(instance=Profile.objects.get(user=user))
        user_form = EditUserForm(instance=user)
    return render(request, 'profile_edit.html', {
        'profile_form': profile_form,
        'user': user,
        'user_form': user_form,
    })
コード例 #7
0
def delete_user_view(request):
    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            del_user = User.objects.get(username=form.cleaned_data['username'])
            if del_user.profile.profile_type == 'ARTIST':
                stripe.Subscription.retrieve(request.user.profile.subscr_id)
                stripe.Subscription.delete(request.user.profile.subscr_id)
                messages.success(request,
                                 'You subscription has been cancelled.')
            if del_user is not None:
                del_user.delete()
                messages.success(request,
                                 "We have successfully deleted your account.")
                return redirect(reverse('index'))

        else:
            messages.error(request, "We could not delete your account.")
    else:
        form = EditUserForm(instance=request.user)

    return render(request, 'delete_profile.html', {'form': form})