Exemple #1
0
def participant(request):
	if request.user.is_authenticated():
		submitMsg = ""
		instance = Profile.objects.get(username=request.user.profile.username)

		if (request.method == 'POST'):

			form = ProfileForm(request.POST,instance=instance)
			if form.is_valid():
				form.save()
				submitMsg="Changes updated"
			else: 
				submitMsg = "Invalid Entry!"
		form = ProfileForm(instance=instance)
		template = loader.get_template('login/participant.html')
		studyProfiles = Profile.objects.filter(isStudy=True)
		suggestedStudies=[]
		for i in studyProfiles:
			if i.isSimilar(request.user.profile):
				suggestedStudies.append(i.username)
		name = request.user.username
		dateOfBirth = request.user.profile.dateOfBirth
		context = {'username':name, 'suggestedStudies':suggestedStudies, 'form':form, 'submitMsg':submitMsg}
		return HttpResponse(template.render(context,request))
	else:
		return redirect('..')
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)
        signup_form = SignUpForm(instance=request.user)
        print(signup_form)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect('dashboard')
        else:
            return render(
                request, 'settings.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'signup_form': signup_form,
                })
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
        signup_form = SignUpForm(instance=request.user)
        print('This is what you got')
        print(signup_form)
    return render(
        request, 'settings.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'signup_form': signup_form,
        })
def edit_profile(request):
	current_user = request.user
	if request.method == 'POST':
		profileform = ProfileForm(request.POST, request.FILES, prefix='profile')
		if profileform.is_valid():
			profile=profileform.save(commit=False)
			current_user.profile.delete()
			profile.user = current_user
			profile.save()
			return HttpResponseRedirect('/login/profile')
	else:
		profileform= ProfileForm(prefix='profile', initial={'name':current_user.profile.name,'enrollment_no':current_user.profile.enrollment_no,'branch':current_user.profile.branch,'age':current_user.profile.age,'gender':current_user.profile.gender,'about_me':current_user.profile.about_me})
	return render_to_response('login/edit_profile.html', dict(profileform=profileform),context_instance=RequestContext(request))
def signup(request):
	if request.method == 'POST':
		userform = UserForm(request.POST, prefix='user')
		profileform = ProfileForm(request.POST, request.FILES, prefix='profile')
		if userform.is_valid() * profileform.is_valid():
			user = userform.save()
			profile = profileform.save(commit=False)
			profile.user = user
			profile.save()
			return HttpResponse('Signup successful <br> <a href="/login/login">Login Here</a>')
	else:
		userform = UserForm(prefix='user')
		profileform = ProfileForm(prefix='profile')
	return render_to_response('login/sign_up.html',dict(userform=userform,profileform=profileform),context_instance=RequestContext(request))
def login(request):
    form = ProfileForm(request.POST)
    #print(form.errors)
    if form.is_valid():
        eid = form["emp_id"].value()
        pas = form["emp_pas"].value()
        for p in useradmin.objects.raw('select * from useradmin'):
            if p.Employee_Id == eid and p.password == pas:
                user_list = [eid]
                request.session['user_list'] = user_list
                return redirect('adminprofile/')
        for p in Employee.objects.raw('select * from Employee'):
            if p.Employee_Id == eid and p.password == pas:
                user_list = [eid]
                request.session['user_list'] = user_list
                return redirect('profile/')
    return render(request, 'login/home.html', {'form': form})
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)
        signup_form = SignUpForm(instance=request.user)
        current_profile = Profile.objects.filter(pk=request.user.id)[0]
        print('CHECK =', request.FILES)

        if 'myfile' in request.FILES and request.FILES['myfile']:
            myfile = request.FILES['myfile']
            fs = FileSystemStorage()
            filename = fs.save(
                myfile.name + '-' + datetime.datetime.now().isoformat(),
                myfile)
            uploaded_file_url = fs.url(filename)
            user = User.objects.filter(pk=request.user.id)
            current_profile = Profile.objects.get(user=user)
            current_profile.image = uploaded_file_url
            current_profile.save()
            print('UPDATED =', uploaded_file_url)
            return render(request, 'profile.html', {})

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect('settings')
        else:
            return render(
                request, 'settings.html', {
                    'user_form': user_form,
                    'signup_form': signup_form,
                    'profile': current_profile,
                })
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
        signup_form = SignUpForm(instance=request.user)
        current_profile = Profile.objects.filter(pk=request.user.id)[0]
    return render(
        request, 'settings.html', {
            'user_form': user_form,
            'signup_form': signup_form,
            'profile': current_profile
        })
Exemple #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()
            messages.success(request,
                             _('Your profile was successfully updated!'))
            return redirect('profile')
        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, 'profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemple #8
0
 def test_profileForm_case(self):
     c = Client()
     tester = User.objects.create(username='******', password='******', is_active=True, is_staff=True, is_superuser=True)
     tester.save()
     c.login(username='******', password='******')
     form = ProfileForm({
         'first_name': "Joe",
         'last_name': "Joey",
         'username': "******",
         'phone_number': "3018523444",
         'year': "Fourth",
         'bio': "testing",
         'location': "Inactive"
     }, instance=tester.profile)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertNotEqual(tester.profile.first_name, "joe")
     self.assertNotEqual(tester.profile.last_name, "joey")
     self.assertNotEqual(tester.profile.username, "tester")
     self.assertEqual(tester.profile.phone_number, "3018523444")
     tester.delete()