Exemplo n.º 1
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)
def profile(request):
    user = User.objects.get(id = request.user.id)
    try:
        user.applicant
    except:
        return HttpResponseRedirect(reverse('index'))
    applicant = user.applicant
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.save()
            applicant.city = form.cleaned_data.get('city')
            applicant.state = form.cleaned_data.get('state')
            applicant.country = form.cleaned_data.get('country')
            applicant.zipcode = form.cleaned_data.get('zipcode')
            applicant.phone = form.cleaned_data.get('phone')
            applicant.dob = form.cleaned_data.get('dob')
            applicant.languages = form.cleaned_data.get('languages')
            applicant.communities = form.cleaned_data.get('communities')
            applicant.working_now = form.cleaned_data.get('working_now')
            applicant.school_now = form.cleaned_data.get('school_now')
            applicant.time_commitment = form.cleaned_data.get('time_commitment')
            applicant.past_applicant = form.cleaned_data.get('past_applicant')
            applicant.referral = form.cleaned_data.get('referral')
            applicant.save()
            return HttpResponseRedirect(reverse('index'))
    else:
        userinfo = model_to_dict(user)
        applicationinfo = model_to_dict(applicant)
        allinfo = dict(userinfo.items() + applicationinfo.items())
        form = ProfileForm(initial=allinfo)
    return render(request, 'profile.html', {'form':form})
Exemplo 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
        })
Exemplo n.º 4
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})
Exemplo 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})
Exemplo n.º 6
0
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})
Exemplo n.º 7
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)
Exemplo 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})
Exemplo 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})
Exemplo n.º 10
0
def profile(request):
    """Renders the profile page."""
    assert isinstance(request, HttpRequest)
    interests = getInterestsAndSubInterests(request.user)
    form = ProfileForm(request.POST or None, suggestedInterests=interests)
    photoform = ProfilePicForm()
    userInfo = getUserInfo(request.user)
    photoUrl = userInfo.profilepic.url if bool(userInfo.profilepic) else ''
    if (request.method == 'POST' and form.is_valid()):
        firstname = form.cleaned_data['firstname']
        lastname = form.cleaned_data['lastname']
        bio = form.cleaned_data['bio']
        request.user.first_name = firstname
        request.user.last_name = lastname
        request.user.save()
        userInfo.bio = bio
        userInfo.save()
        subinterestIDs = form.cleaned_data['interests']
        subinterests = list(
            map(
                lambda subinterestID: Subinterest.objects.get(
                    id=subinterestID), subinterestIDs))
        uniqueInterests = {
            subinterest.interest
            for subinterest in subinterests
        }
        UserInterest.objects.filter(user=userInfo).delete()
        for interest in uniqueInterests:
            userInterest = UserInterest(user=userInfo,
                                        interest=interest,
                                        priority=1)
            userInterest.save()
            userSubInterests = [
                subinterest for subinterest in subinterests
                if subinterest.interest == interest
            ]
            userInterest.subinterests = userSubInterests
            userInterest.save()
    userInterests = getUserInterestsAsIdList(request.user)
    form = ProfileForm(suggestedInterests=interests,
                       initial={
                           'firstname': request.user.first_name,
                           'lastname': request.user.last_name,
                           'bio': userInfo.bio,
                           'interests': userInterests
                       })
    return render(
        request, 'app/profile.html', {
            'title': 'Profile',
            'form': form,
            'photoform': photoform,
            'photoUrl': photoUrl,
        })
Exemplo n.º 11
0
    def post(self, request):
        profile_form = ProfileForm(request.POST)

        if profile_form.is_valid():
            prefecture_id = profile_form.cleaned_data["prefecture_id"]

            person = request.user.person
            person.prefecture_id = prefecture_id
            person.save(update_fields=["prefecture_id", "updated_at"])
            request.session["notification"] = Notification.PROFILE_CHANGE

            return redirect("profile")
Exemplo n.º 12
0
def profile(request):
    user = request.user
    your_ideas = Idea.objects.filter(user = user).order_by('-date')
    ideas_len = len(your_ideas)
    your_slates = Slate.objects.filter(creator = user).order_by('-id')
    slates_len = len(your_slates)
    if request.method == 'POST': #If something has been submitted
            print "post"
            if 'vote' in request.POST:
                voteForm = VoteForm(request.POST)
                if voteForm.is_valid():
                    helpers.vote(voteForm,request.user)
            if 'profile' in request.POST:
                print "profile"
                profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.get_profile())
                print profile_form
                if profile_form.is_valid():
                    print "valid"
                    photo_string = hashlib.sha224(
                            "profile_pic"+
                            CLIENT_SUB_DOMAIN+
                            str(user.id)).hexdigest()
                    write_url = '%susers/%s.png' %(STATIC_DOC_ROOT,photo_string)
                    print photo_string
                    try:
                        photo = request.FILES['photo']
                    except:#no image
                        pass
                    else:
                        success, string = helpers.handle_uploaded_file(photo, write_url, "profile")
                        if success:
                            print success
                            user.get_profile().photo = photo_string + ".png"
                            user.get_profile().save()
                        else:

                            messages.error(request, "That file was too large.")
                        user.save()
                        return HttpResponseRedirect("/accounts/profile/")



    profile_form = ProfileForm()

    voted_on = Vote.objects.filter(user = user)
    voted_len = len(voted_on)
    commented_on = user.get_profile().get_ideas_commented_on()
    comments_len = len(commented_on)

    return render_to_response('main/profile.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 13
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})
Exemplo n.º 14
0
def profile(request):
    data = {'login': request.user.username, 'email': request.user.email}
    form = ProfileForm(data, initial=data)

    if request.POST:
        form = ProfileForm(request.POST, initial=data)
        if form.is_valid() and form.has_changed():
            request.user.username = form.cleaned_data.get('login')
            request.user.email = form.cleaned_data.get('email')
            request.user.save()
            return redirect('/')

    context['form'] = form
    return render(request, 'profile.html', context)
Exemplo n.º 15
0
def user_profile(request):
    if request.method == "POST":
        form = ProfileForm(request.POST)
        if form.is_valid():
            user = request.user
            user.profile.first_name = form.cleaned_data.get('first_name')
            user.profile.last_name = form.cleaned_data.get('last_name')
            user.profile.email = form.cleaned_data.get('email')
            user.save()       
            messages.success(request, 'Form submission successful')
    else:
        form = ProfileForm(instance=request.user.profile)
    return render(request, 'profile.html', {
        'form': form,
    })
Exemplo n.º 16
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
    })
Exemplo n.º 17
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})
Exemplo n.º 18
0
 def change_profile(request):
     user = request.user
     password_form = PasswordChangeForm(request.user)
     profile_form = ProfileForm(request.POST)
     if request.method == 'POST':
         if profile_form.is_valid():
             user.email = request.POST['email']
             user.save()
             messages.success(request,
                              'Your profile was successfully updated!')
             return HttpResponseRedirect(reverse('app:profile'))
         else:
             messages.error(request, 'Please correct the error below.')
     return render(
         request, 'app/profile/index.html', {
             'user': user,
             'password_form': password_form,
             'profile_form': profile_form
         })
Exemplo n.º 19
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,
    })
Exemplo n.º 20
0
def profile_edit(request, u_id):
    user = User.objects.get(id=u_id)
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, request.FILES)

        if profile_form.is_valid():
            profile_cd = profile_form.cleaned_data
            user.nickname = profile_cd['nickname']
            # user.icon = profile_cd['icon']
            user.save()
            return redirect('account:login_success')
        else:
            print(profile_form.errors)
            return HttpResponse('表单有问题')
    else:
        profile_form = ProfileForm()
        content = {
            'profile_form': profile_form,
            'user': user,
        }
        return render(request, 'account/profile_edit.html', content)
Exemplo n.º 21
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
    })
Exemplo n.º 22
0
def edit_profile(request):
    response = api_get_user(request.session['user']['email'], request.session['user']['token'])
    if response.ok:
        user = response.json()
        if request.method == 'POST':
            form = ProfileForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                user['lastname'] = data['lastname']
                user['firstname'] = data['firstname']
                user.pop('order_set')
                user.pop('address_set')
                user.pop('vehicle_set')
                response = api_edit_user(user, request.session['user']['token'])
                if response.ok:
                    return HttpResponseRedirect(reverse('profile'))
                return render(request, 'profile/edit.html', {
                    'form': form, 'errors': response.json()['errors']
                })

        form = ProfileForm(initial=user)
        return render(request, 'profile/edit.html', {'form': form})
    return HttpResponseRedirect(reverse('logout'))
Exemplo n.º 23
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))
Exemplo n.º 24
0
def profile_create(request):
    form = ProfileForm(request.POST)
    if form.is_valid():
        form.save()
        return redirect('home page')