def profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('listProfile')
    else:
        form = ProfileForm()
    return render(request, 'profile.html', {'form': form})
Esempio n. 2
0
def profile_edit(request):
    form = ProfileForm(request.POST or None, instance=request.user.profile)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('app:edit_profile')
    context = {'form': form}
    print(form.errors)

    return render(request, 'app/edit_profile.html', context)
Esempio n. 3
0
def register(request): #注册
	registered = False
	errors=[]
	if request.method == 'POST':
		user_form = UserForm(data = request.POST)
		profile_form = ProfileForm(data = request.POST)
		if user_form.is_valid() and profile_form.is_valid(): 
			user = user_form.save(commit = False)
			user.set_password(user.password)  #设置密码
			user.save()
			profile = profile_form.save(commit=False)  #不保存
			profile.user = user

			if 'userImage' in request.FILES:  #判断是否有上传头像
				profile.userImage = request.FILES['userImage']

			profile.save()  #保存
			registered = True
		else:
			errors.append(user_form.errors)
			errors.append(profile_form.errors)

	else:
		user_form = UserForm()
		profile_form = ProfileForm()
	return render(request, 'app/register.html', {'user_form':user_form, 'profile_form':profile_form, 'errors':errors,'registered':registered})
Esempio n. 4
0
def signup(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            auth_data = {
                'username': user.username,
                'password': user_form.cleaned_data['password1'],
            }
            u = auth.authenticate(request, **auth_data)
            if u is not None:
                auth.login(request, user)
                return redirect('/')

            return render(request, 'signup.html', {
                'form': user_form,
                **tags_and_users
            })

        return render(request, 'signup.html', {
            'form': user_form,
            **tags_and_users
        })
    return render(request, 'signup.html', tags_and_users)
Esempio n. 5
0
def register(request):  # 注册
    registered = False
    errors = []
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = ProfileForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)  # 设置密码
            user.save()
            profile = profile_form.save(commit=False)  # 不保存
            profile.user = user

            if 'userImage' in request.FILES:  # 判断是否有上传头像
                profile.userImage = request.FILES['userImage']

            profile.save()  # 保存
            registered = True
        else:
            errors.append(user_form.errors)
            errors.append(profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = ProfileForm()
    return render(
        request, 'app/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'errors': errors,
            'registered': registered
        })
Esempio n. 6
0
def register(request):
	registered = False
	errors=[]
	if request.method == 'POST':
		user_form = UserForm(data = request.POST)
		profile_form = ProfileForm(data = request.POST)
		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save(commit = False)
			user.set_password(user.password)
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			print request.FILES

			# if request.FILES['userImage']:
			if 'userImage' in request.FILES:
				print 'has a Picture 1'
				profile.userImage = request.FILES['userImage']


			profile.save()
			registered = True
			# HttpResponseRedirect('app/')
		else:
			errors.append(user_form.errors)
			errors.append(profile_form.errors)
	else:
		user_form = UserForm()
		profile_form = ProfileForm()
	return render(request, 'app/register.html', {'user_form':user_form, 'profile_form':profile_form, 'errors':errors,'registered':registered})
Esempio n. 7
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return HttpResponseRedirect('/')
        else:
            messages.error(request, ('Please correct the error below.'))
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'home/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Esempio n. 8
0
def settings(request):
    form = ProfileForm(request.POST or None, request.FILES or None, instance=request.user.profile)
    if form.is_valid():
        profile = form.save(commit=False)
        profile.user = request.user
        profile.save()

        return redirect('/dashboard/')

    return render(request, 'settings.html', {'form': form})
Esempio n. 9
0
def settings(request):
    form = ProfileForm(request.POST or None,
                       request.FILES or None,
                       instance=request.user.profile)
    if form.is_valid():
        profile = form.save(commit=False)
        profile.user = request.user
        profile.save()

        return redirect('/dashboard/')

    return render(request, 'settings.html', {'form': form})
Esempio n. 10
0
def user_edit(request, pk):
    user = User.objects.get(pk=pk)

    if request.method == 'POST':
        user_form = UserChangeForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST, instance=user.profile)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()

            messages.success(request, 'User {} updated successfully'.format(user.username))
            return redirect('user_list')
    else:
        user_form = UserChangeForm(instance=user)
        profile_form = ProfileForm(instance=user.profile)

    return render(request, 'auth/user_edit_form.html', {
        'form': user_form,
        'profile_form': profile_form,
    })
Esempio n. 11
0
def profile(request):
    user = request.user
    profile = get_object_or_404(Profile, user=user)

    if request.method == "POST":
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            data = form.save(commit=False)
            data.save()
            messages.success(request, "Successfully updated profile")
            return redirect("profile")
    else:
        form = ProfileForm(instance=profile)
    return render(request, 'app/profile.html', {'form': form})
Esempio n. 12
0
def edit_profile_view(request):
    user_name = request.user.username
    if request.method == 'GET':
        num_notifications = get_notifications(request)
        user = get_object_or_404(User, username=user_name)
        profile = get_object_or_404(UserProfile, user=user)
        user_skills = profile.skills.all()
        user_requests = Request.objects.filter(created_by=user)[:5]
        user_offers = Offer.objects.filter(offer_by=user, is_accepted=True)[:5]
        requests_count = len(user_requests)
        offers_count = len(user_offers)
        data = {'profile': profile,
                'skills': user_skills,
                'offers': user_offers,
                'requests': user_requests,
                'num_offers': offers_count,
                'num_requests': requests_count,
                }
        return render(request=request, template_name='app/editProfile.html',
                      context={'data': data, 'num_notifications': num_notifications})

    elif request.method == 'POST':
        instance = get_object_or_404(UserProfile, user=request.user)
        form = ProfileForm(request.POST or None, instance=instance)
        if form.is_valid():
            for id in request.POST.getlist('skills'):
                tag = SkillTag.objects.get(pk=id)
                if tag:
                    instance.skills.add(tag)

            instance.save()
            form.save(commit=True)
            messages.add_message(request, messages.SUCCESS, 'Your Profile Updated Successfully !')
            return HttpResponseRedirect('/users/' + str(user_name))

        else:
            return HttpResponseRedirect("/users/" + str(user_name))
Esempio n. 13
0
def update_profile(request):
    '''
    Function that renders the update profile template and passes the form into it.
    '''
    current_user = request.user
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if profile_form.is_valid():
            Profile.objects.filter(user_id=current_user.id).delete()
            profile = profile_form.save(commit=False)
            profile.user = current_user
            profile.save()
            return redirect("Profile")
    else:
        profile_form = ProfileForm()

    return render(request, 'updateprofile.html',
                  {"profile_form": profile_form})
Esempio n. 14
0
def register(request):
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, prefix='Profile')
        user_form = UserForm(request.POST, prefix='User')
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            password = request.POST['User-password']
            user.set_password(password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            return HttpResponseRedirect('/')
    else:
        profile_form = ProfileForm(prefix='Profile')
        user_form = UserForm(prefix='User')
    return render(request, 'app/register.html', {
        'profile_form': profile_form,
        'user_form': user_form
    })
Esempio n. 15
0
def profile_create(request):
    form = ProfileForm(request.POST)
    if form.is_valid():
        form.save()
        return redirect('home page')