Exemple #1
0
def test_edit_profile_form_phone_not_isdigit():
    form = EditProfileForm()
    form.cleaned_data = {'phone': FAKE.phone_number()[:10]}
    try:
        form.clean()
    except ValidationError:
        pass
    else:
        assert 2 == 1
Exemple #2
0
def test_edit_profile_form_phone_to_short():
    form = EditProfileForm()
    form.cleaned_data = {'phone': '2'}
    try:
        form.clean()
    except ValidationError:
        pass
    else:
        assert 2 == 1
Exemple #3
0
def edit_profile(request):
    get_user = get_object_or_404(User, id=request.user.id)
    instance = get_object_or_404(UserProfile, user=get_user)
    form = EditProfileForm(request.POST or None, instance=instance)
    if request.method == "POST":
        if form.is_valid():
            form.save()
            return render(request, 'account/view_profile.html',
                          {"user": request.user})
    else:
        return render(request, 'account/edit_profile.html', {'form': form})
Exemple #4
0
def edit_profile(request):

    inst = User_info.objects.get(user_id=request.user)

    form = EditProfileForm(instance=inst)
    img_form = UserImageForm()

    if request.method == 'POST':
        """if 'details' in request.POST:
			form = EditProfileForm(request.POST, instance=inst)
			if form.is_valid():
				edit_profile_obj = form.save(commit=False)
				about_tags = form.cleaned_data['about_tags']
				edit_profile_obj.about_tags.clear()
				for tag in about_tags:
					edit_profile_obj.about_tags.add(tag.lower())
				edit_profile_obj.save()
				if 'location' in request.POST and request.POST.get('location'):
					inst.location_id = request.POST.get('location')
					inst.save()
				#edit_profile_obj.about_tags.add(*about_tags)
				#return HttpResponseRedirect("/accounts/add_interest/")"""
        if 'location' in request.POST and request.POST.get('location'):
            inst.location_id = request.POST.get('location')
            inst.save()
        elif 'image' in request.POST:
            img_form = UserImageForm(request.POST, request.FILES)
            if img_form.is_valid():
                if 'avatar' in request.FILES:
                    ext = request.FILES['avatar'].content_type.split('/')[1]
                    request.FILES['avatar'].name = str(
                        request.user) + '.' + str(ext)

                    obj = User_info.objects.get(user_id=request.user)

                    if obj.avatar == 'user_images/root.jpeg':
                        delete(obj.avatar, delete_file=False)
                    else:
                        delete(obj.avatar)

                    obj.avatar = request.FILES['avatar']
                    obj.save()
        else:
            img_form = UserImageForm()
        return HttpResponseRedirect("/profile/")
    else:
        form = EditProfileForm(instance=inst)
        img_form = UserImageForm()
    return render(request, "edit_profile.html", {
        'form': form,
        'img_form': img_form,
        'user_obj': inst
    })
def profile(request):
    if request.user.is_authenticated:
        if request.method == 'POST':
            form = EditProfileForm(request.POST)
            if form.is_valid():
                user = User.objects.get(username=request.user)
                cd = form.cleaned_data
                user.email = cd['email']
                user.first_name = cd['first_name']
                user.last_name = cd['last_name']
                user.save()
                return redirect('/dashboard')

            return render(request, 'account/editprofile.html')
        return render(request, 'account/editprofile.html')
    return redirect('/login')
Exemple #6
0
def edit_profile(request):
    if request.method == "POST":
        form = EditProfileForm(request.POST)
        if form.is_valid():
            if not request.user.check_password(form.cleaned_data['password']):
                form._errors['password'] = ErrorList([u'The password you entered is incorrect.'])
            else:
                request.user.email = form.cleaned_data['email']
                if form.cleaned_data['password1']:
                    request.user.set_password(form.cleaned_data['password1'])
                request.user.save()
                return HttpResponseRedirect('/settings/')
    else:
        form = EditProfileForm()
        form.fields['email'].initial = request.user.email
    return TemplateResponse(request, "edit_profile_form.html",
            {'form': form})
Exemple #7
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('/accounts/profile')
    else:
        form = EditProfileForm(instance=request.user)
        return render(request, 'account/edit_profile.html', {'form': form})
Exemple #8
0
def edit_profile(request):
    if request.method == 'POST':
        # Check the form.py for the details
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('/account/profile')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'account/edit_profile.html', args)
Exemple #9
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()
            return redirect(reverse('account:view_profile'))
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'account/edit_profile.html', args)
Exemple #10
0
def edit_profile(request):
    """
    View allow user to edit profile
    """
    #Get profile instance to bind to form
    profile_data = Profile.objects.get(username = request.user)
    if request.method == 'POST':
        form = EditProfileForm(request.POST, request.FILES, instance=profile_data)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(request.META['HTTP_REFERER'])
    form = EditProfileForm(instance=profile_data)
    return render_to_response('account/edit_profile.html', { 'form': form, }, context_instance=RequestContext(request))
Exemple #11
0
def EditProfile(request):
    user = request.user.id
    profile = Profile.objects.get(user__id=user)
    BASE_WIDTH = 300

    if request.method == 'POST':
        form = EditProfileForm(request.POST, request.FILES)
        if form.is_valid():
            profile.picture = form.cleaned_data.get('picture')
            profile.first_name = form.cleaned_data.get('first_name')
            profile.last_name = form.cleaned_data.get('last_name')
            profile.location = form.cleaned_data.get('location')
            profile.url = form.cleaned_data.get('url')
            profile.profile_info = form.cleaned_data.get('profile_info')
            profile.save()
            return redirect('post_list')
    else:
        form = EditProfileForm()

    context = {
        'form': form,
    }

    return render(request, 'account/edit_profile.html', context)
Exemple #12
0
def register(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/account')
    else:
        form = RegistrationForm()
        args = {'form': form}
        return render(request, 'account/reg_form.html', args)
Exemple #13
0
def edit_profile(request, pk):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            context = {'form': form}

        return redirect('profile', pk=pk)


    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'layout/edit_profile.html', args)
Exemple #14
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            """
			subject = "Thank you"
			message = 'Your confirmation email'
			from_email = settings.EMAIL_HOST_USER
			to_list = [save_it.email]
			send_mail(subject, message, from_email, to_list, fail_silently = False)
			"""
            return redirect('/account/profile')
    else:
        #blank form
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'account/edit_profile.html', args)
Exemple #15
0
def edit(request):
    #Example of how to get an instance of a model
    profile = get_object_or_404(Profile, user=request.user)

    if request.method == "POST":
        form = EditProfileForm(request.POST, request.FILES, instance=profile)
        infoform = EditPersonalInfoForm(request.POST, instance=profile.user)
        if form.is_valid() and infoform.is_valid():
            form.save()
            infoform.save()
            return redirect('/account')
        else:
            return render_to_response('account/edit.html', {'form': form})
    else:
        form = EditProfileForm(instance=profile)
        infoform = EditPersonalInfoForm(instance=profile.user)
        ctxt = {'user': request.user, 'form': form, 'infoform': infoform}

        return render(request, 'account/edit.html', ctxt)
Exemple #16
0
def edit_profile(request):

    if not request.user.is_authenticated:
        return redirect("account:login")

    context = {}

    if request.method == 'POST':
        form = EditProfileForm(data=request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('student_portals:index')

    else:
        form = EditProfileForm(initial={
            "email": request.user.email,
            "username": request.user.username,
        })
    context = {'form': form}
    return render(request, 'account/edit_profile.html', context)
Exemple #17
0
def edit_profile(request):
    if request.method == "POST":
        form = EditProfileForm(request.POST)
        if form.is_valid():
            if not request.user.check_password(form.cleaned_data['password']):
                form._errors['password'] = ErrorList(
                    [u'The password you entered is incorrect.'])
            else:
                request.user.email = form.cleaned_data['email']
                if form.cleaned_data['password1']:
                    request.user.set_password(form.cleaned_data['password1'])
                request.user.save()
                return HttpResponseRedirect('/settings/')
    else:
        form = EditProfileForm()
        form.fields['email'].initial = request.user.email
    return TemplateResponse(request, "edit_profile_form.html", {'form': form})
Exemple #18
0
 def get(self, request):
     form = EditProfileForm(instance=request.user)
     return render(request, 'account/edit_profile.html', {'form': form})
Exemple #19
0
 def post(self, request):
     form = EditProfileForm(request.POST, instance=request.user)
     if form.is_valid():
         form.save()
     return redirect('my_account')
Exemple #20
0
def test_edit_profile_form():
    form = EditProfileForm()
    form.cleaned_data = {
        'phone': ''.join(i for i in FAKE.phone_number() if i.isdigit())[:10]
    }
    form.clean()