def register(request): if request.method == 'POST': userForm = UserForm(data=request.POST) profileForm = UserProfileForm(data=request.POST) locationForm = LocationForm(data=request.POST) if userForm.is_valid() and profileForm.is_valid() and \ locationForm.is_valid(): userObj = userForm.save() userObj.set_password(userObj.password) userObj.save() location = locationForm.save(commit=False) location.name = 'Home' location.save() profileObj = profileForm.save(commit=False) profileObj.user = userObj profileObj.address = location profileObj.save() profileObj.locations.add(location) profileObj.save() userObj = authenticate(username=userObj.username, password=userObj.password) login(request, userObj) return render(request, 'socketbox/index.html', {}) else: if not locationForm.is_valid(): print("Location is bad!") print locationForm.errors if not userForm.is_valid(): print("user is bad!") print userForm.errors print request.POST if not profileForm.is_valid(): print("profile is bad!") print profileForm.errors return index(request) else: profileForm = UserProfile() locationForm = Location() userForm = User() contextDict = {'profileForm': profileForm, 'locationForm': locationForm, 'userForm': userForm} return render(request, "registration/registration_form.html", contextDict)
def user_profile(request): if request.method == 'POST': basicform = UserBasicForm(request.POST, instance=request.user) extraform = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) if extraform.is_valid() and basicform.is_valid(): basicform.save() extraform.save() messages.success(request, "Changes saved") return HttpResponseRedirect('/') else: user = request.user profile = user.profile basicform = UserBasicForm(instance=user) extraform = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['basicform'] = basicform args['extraform'] = extraform return render(request, 'profile.html', args)
def editprofile(request): user = User.objects.get(username=request.user) if request.method == "POST": email = request.POST['email'] try: existent_email = User.objects.get(email=email) except: existent_email = None if existent_email: return render(request, 'fhs/editprofile.html', {"existent": True}) form = EmailForm(data=request.POST, instance=request.user) picform = UserProfileForm(data=request.POST, instance=request.user) try: up = UserProfile.objects.get(user=request.user) except: up = None if form.is_valid() and picform.is_valid(): if email: user = form.save(commit=False) user.save() if 'picture' in request.FILES: up.picture = request.FILES['picture'] up.save() return HttpResponseRedirect('/fhs/profile/' + user.username) else: return render(request, 'fhs/editprofile.html', {})
def user_private(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) profile_form = UserProfileForm(request.POST, instance=request.user.get_profile()) # Forms are displayed together thus both of them # should be valid before saving the whole user data if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() profile = profile_form.save(commit=False) profile.user = request.user profile.save() user_profile = request.user.get_profile() profile_form = UserProfileForm(instance=user_profile) user_form = UserForm(instance=request.user) api_consumer = Consumer.objects.get(user=request.user) api_access_token = api_consumer.token_set.get(token_type=Token.ACCESS, user=request.user) extra_context = { 'profile_form': profile_form, 'user_form': user_form, 'api_consumer': api_consumer, 'api_access_token': api_access_token } return object_detail(request, object_id=request.user.pk, queryset=User.objects.all(), template_name='users/user_private.html', extra_context=extra_context)
def view_profile(request, pk=""): title = "Profiles" latest_data = fetch_latest() if not pk: try: profile = request.user.get_profile() except: return HttpResponseRedirect(reverse('profile-home')) else: try: # FIXME: UserProfile pk doesn't necessarily match that of the User's. # Solution: Grab User(pk=pk), then UserProfile from that profile = UserProfile.objects.get(pk=pk) except: return HttpResponseRedirect(reverse('profile-home')) if request.method == 'POST': f = UserProfileForm(request.POST, request.FILES, instance=profile) if f.is_valid(): f.save() else: f = UserProfileForm(instance=profile) # TODO: set title based on User's name return render_to_response('profile.djt', locals(), context_instance=RequestContext(request))
def edit_user_profile(request): user = get_object_or_404(User, username=request.user.username) profile = user.get_profile() if request.method == "POST": form = UserProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.email = form.cleaned_data['email'] user.save() profile.bio = form.cleaned_data['bio'] profile.save() return redirect("/profile/%s/" % request.user.username) else: pass else: initial_data = { 'first_name' : user.first_name, 'last_name' : user.last_name, 'email' : user.email, 'bio' : profile.bio, } form = UserProfileForm(initial=initial_data) return render_to_response( 'userprofile/edit_profile.html', {'form': form}, context_instance=RequestContext(request))
def signup(request): try: if request.method == 'POST': user_data = dict(zip(request.POST.keys(), request.POST.values())) import ipdb; ipdb.set_trace() dept_name = user_data.get('department', 'resistance') or 'resistance' designation = user_data.get('designation', 'Engineer') or 'Engineer' is_exists = Department.objects.filter( designation=designation).exists() if is_exists: messages.error(request, """Sorry, Leader has been Set!!""") raise Exception('Leader Exists Error.') form = UserProfileForm(user_data) if form.is_valid(): form.save() user = form.instance dept_details = {'name': dept_name, 'designation': designation, 'user': user} dept_obj = Department.objects.create(**dept_details) return HttpResponseRedirect(reverse('login_view')) except Exception as ex: print ex.message form = UserProfileForm() return render_to_response('registration.html', {'form': form}, context_instance=RequestContext(request))
def send_update_profile(request): if request.method == 'POST': form = UserProfileForm(request.POST) if form.is_valid(): userProfile = UserProfile.objects.get(user=request.user) description = form.cleaned_data['description'] rank = form.cleaned_data['rank'] weapon = form.cleaned_data['weapon'] friend_code = form.cleaned_data['friend_code'] hunter_name = form.cleaned_data['hunter_name'] nintendo_name = form.cleaned_data['nintendo_name'] skype_name = form.cleaned_data['skype_name'] teamspeak_name = form.cleaned_data['teamspeak_name'] userProfile.description = description userProfile.rank = rank userProfile.weapon = weapon userProfile.friend_code = friend_code userProfile.hunter_name = hunter_name userProfile.nintendo_name = nintendo_name userProfile.skype_name = skype_name userProfile.teamspeak_name = teamspeak_name userProfile.save() return redirect('/roster/profile/' + str(userProfile.id)) else: form = UserProfileForm() return redirect('/roster/send_update_profile/')
def add_user(request): if request.method == "POST": uform = UserForm(data = request.POST) pform = UserProfileForm(data = request.POST) if uform.is_valid() and pform.is_valid(): user = uform.save() user.set_password(user.password) user.save() profile = UserProfile(user=user, country=pform.cleaned_data['country'], profile=pform.cleaned_data['profile'], dob=pform.cleaned_data['dob']) profile.save() return HttpResponseRedirect('/registration_success/') # Redirect after POST data, errors = {}, {} uform = UserForm() pform = UserProfileForm() pagequerydict = pushitem.objects.none() r = makepage(request,pagequerydict,{'title':LANGUAGE['Register'], 'uform': uform, 'pform': pform, 'errors': {},}, "registration/registration_form.html", ) return r
def profile_form(request,username,use_openid=False): if request.user.username != username: return HttpResponse( "You cannot access another user's profile.", status=401) else: user = User.objects.get(username=username) try: user_profile = UserProfile.objects.get(user=user) except UserProfile.DoesNotExist: user_profile = UserProfile.objects.create(user=user) user_assoc = UserAssociation.objects.filter(user__id=user.id) if request.method == 'GET': uform = UserForm(instance=user) pform = UserProfileForm(instance=user_profile) return render_to_response('user_profile/user_profile_form.html', {'profile': user_profile, 'assoc': user_assoc, 'uform': uform, 'pform': pform, 'group_request_email': settings.GROUP_REQUEST_EMAIL, 'use_openid': use_openid, 'MEDIA_URL':settings.MEDIA_URL}) elif request.method == 'POST': uform = UserForm(data=request.POST, instance=user) pform = UserProfileForm(data=request.POST, instance=user_profile) if uform.is_valid(): user.save() if pform.is_valid(): user_profile.save() #return HttpResponseRedirect(reverse('user_profile-form', args=[username])) return HttpResponseRedirect(reverse('map')) else: return HttpResponse( "Received unexpected " + request.method + " request.", status=400 )
def addUserView(request): if request.method == 'POST': permission_list = [int(i) for i in request.POST.getlist('permission')] print permission_list user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): # import pdb; pdb.set_trace() user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() for i in permission_list: profile.permission.add(Game.objects.get(id=i)) return HttpResponseRedirect(reverse('userlisturl')) else: user_form = UserForm() profile_form = UserProfileForm() context_dict = { 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'common/adduser.html', context_dict)
def editUserView(request, ID): user_info = User.objects.get(id=ID) profile_info = UserProfile.objects.get(user=user_info) if request.method == 'POST': permission_list = [int(i) for i in request.POST.getlist('permission')] user_form = UserForm(request.POST, instance=user_info) profile_form = UserProfileForm(request.POST, instance=profile_info) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() for i in profile.permission.all(): profile.permission.remove(i) for i in permission_list: profile.permission.add(Game.objects.get(id=i)) return HttpResponseRedirect(reverse('userlisturl')) else: user_form = UserForm(instance=user_info) profile_form = UserProfileForm(instance=profile_info) context_dict = { 'ID': ID, 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'common/edituser.html', context_dict)
def user_(request): # user = User.objects.get(pk=get_user(request).pk) # u_profile = MyUserModel.objects.get(user=user) # profile_form = MultiUserForm(instance=u_profile) # return render(request, 'userprofile/user.html', {'profile_form': profile_form}) user = User.objects.get(pk=get_user(request).pk) try: u_profile = MyUserModel.objects.get(user=user) except(Exception): u_profile = MyUserModel(user=user) if request.method == "POST": profile_form = UserProfileForm(request.POST, request.FILES, instance=u_profile) if profile_form.is_valid(): profile_form.save() user_form = UserForm(request.POST, instance=user) if user_form.is_valid(): user_form.save(commit=False) if "password" in request.POST: user.set_password(request.POST["password"]) user_form.save() else: profile_form = UserProfileForm(instance=u_profile) user_form = UserForm(instance=user) return render(request, 'userprofile/user.html', {'profile_form': profile_form, 'user_form': user_form})
def profile_set(request): user = request.user if not user.is_authenticated(): return HttpResponseNotFound('You must be logged in to see this page.') profile = user.get_profile() is_journalist = profile.is_journalist() if request.method == 'POST': # If the form has been submitted... profile_form = UserProfileForm(request.POST, request.FILES) if profile_form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data and return to the admin profile.full_name = profile_form.cleaned_data['full_name'] profile.avatar = request.POST.get('avatar') #profile.bio = profile_form.cleaned_data['bio'] #profile.major = profile_form.cleaned_data['major'] profile.profile_set = True user.email = profile_form.cleaned_data['email'] user.save() profile.save() return HttpResponseRedirect('/') # Redirect after POST else: if profile.profile_set == False: # if the user has not submitted their information profile_form = UserProfileForm(initial={'full_name': profile.full_name, 'email': user.email}) # An unbound form return render_to_response('journalism/user_profile_edit.html', { 'profile_form': profile_form, }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save() profile.user = user profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() context_dict = { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered } return render(request, "register.html", context_dict)
def user_profile(request): user = User.objects.get_or_create(pk=request.user.id) if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user) if form.is_valid(): form.save() form.user = request.user return HttpResponseRedirect('/accounts/loggedin') else: form= UserProfileForm(instance=request.user) args={} args.update(csrf(request)) args['form'] = form return render_to_response('profile.html',args, context_instance=RequestContext(request)) # # # def user_profile(request): # success = False # user = User.objects.get(pk=request.user.id) # if request.method == 'POST': # upform = UserProfileForm(request.POST, instance=user.get_profile()) # if upform.is_valid(): # up = upform.save(commit=False) # up.user = request.user # up.save() # success = True # else: # upform = UserProfileForm(instance=request.user) # # return render_to_response('profile.html', # locals(), context_instance=RequestContext(request)) #
def user_profile(request): user = User.objects.get(email = request.user.email) try: profiles = UserProfile.objects.get(user = user) except: profiles = "" if request.method == 'POST': email = request.user.email form = UserProfileForm(request.POST,request.FILES,instance=request.user.profile) if form.is_valid(): save_it = form.save(commit = False) save_it.email_id = email save_it.save() return HttpResponseRedirect('/profile/') else: user = request.user profile = user.profile form = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['form'] = form args['profiles'] = profiles try: profile_name = UserProfile.objects.get(user = user) args['email'] = profile_name.name except: args['email'] = request.user.email return render_to_response('profile/profile.html', args,context_instance=RequestContext(request))
def profile_edit(request, username=None, dialog=False): if dialog is True: t = loader.get_template("torpedo/profile_dlg.html") else: t = loader.get_template("torpedo/profile.html") user = get_user(request, username) user_profile = user.profile if request.method == "POST": # If the form has been submitted... form = UserProfileForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data user.first_name = form.cleaned_data["firstname"] user.last_name = form.cleaned_data["lastname"] user.email = form.cleaned_data["email"] user_profile.phonenumber = form.cleaned_data["phonenumber"] user.save() user_profile.save() return HttpResponseRedirect(request.META["HTTP_REFERER"]) # Redirect after POST else: form = UserProfileForm( initial={ "firstname": user.first_name, "lastname": user.last_name, "email": user.email, "phonenumber": user.profile.phonenumber, } ) c = RequestContext(request, {"form": form, "profileuser": user}) return HttpResponse(t.render(c))
def change_profile(request): notifications = Notification.objects.filter(user = request.user, viewed = False).order_by('time').reverse() args = {} args.update(csrf(request)) args['notifications'] = notifications if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance = request.user.profile,) if form.is_valid(): form.save() #request.user.profile.picture = form.cleaned_data['picture'] #request.user.profile.save() #messages.success(request,'You have updated the profile') args['form'] = form args['email'] = request.user.email args['profile'] = request.user.profile messages.success(request,u'修改资料成功!') return render(request,'page-settings.html',args) else: user = request.user profile = user.profile if profile.level: level = profile.level else: level = '3' form = UserProfileForm(instance=profile, initial={'phone':profile.phone, 'picture':profile.picture, 'level': level}) args['form'] = form args['email'] = request.user.email args['profile'] = request.user.profile return render(request, 'page-settings.html',args)
def user_profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/diary/%s' % request.user.profile.id) else: user = request.user profile = user.profile form = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['form'] = form args['username'] = request.user.username args['user_profile_id'] = request.user.profile.id return render_to_response('profile.html', args) # def list_api(request): # item_list = UserProfile.objects.all() # output_list = [] # # for item in item_list: # output_item = {} # output_item["system_id"] = item.id # output_item["first_name"] = item.first_name # output_list.append(output_item) # # return HttpResponse( # json.dumps(output_list), # content_type="application/json" # )
def user_profile(request): if request.session['email']: if request.method =='POST': a=Join.objects.get(email=request.session['email']) try: b=UserProfile.objects.get(user=a) except: b = UserProfile(user=a) b.save() b=UserProfile.objects.get(user=a) form = UserProfileForm(request.POST,instance=b) if form.is_valid(): f= form.save(commit=False) f.user=a f.save() return HttpResponseRedirect('/fb/login/') else: return render(request,'fb/profile.html',{'form':form}) else: a=Join.objects.get(email=request.session['email']) try: b=UserProfile.objects.get(user=a) except: b = UserProfile(user=a) b.save() b=UserProfile.objects.get(user=a) form=UserProfileForm(instance=b) return render(request,'fb/profile.html',{'form':form}) else: return HttpResponseRedirect('/fb/login/')
def edit_profile(request): args = {} args.update(csrf(request)) if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) follow = userFollowActivity.objects.get(user=request.user) generes = Generes.objects.get(user=request.user) first_name = request.user.first_name last_name = request.user.last_name if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/loggedin/') else: form = UserProfileForm(instance=request.user.profile) generes = Generes.objects.get(user=request.user) follow = userFollowActivity.objects.get(user=request.user) first_name = request.user.first_name last_name = request.user.last_name args = {} args.update(csrf(request)) args['form'] = form return render_to_response('editprofilepage.html', { 'form': form, 'follow': follow, 'first_name': first_name, 'last_name': last_name, 'generes': generes }, context_instance=RequestContext(request))
def login(request): if request.user.is_authenticated(): # if there is a user logged in already user_name = UserProfile(name=request.user.username) if request.POST: form = UserProfileForm(request.POST, instance=user_name) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = UserProfileForm(instance=user_name) args = {} args.update(csrf(request)) args['form'] = UserProfileForm() print args context = {"full_name": request.user.username, "args": args} return HttpResponseRedirect("", context) else: c = {} c.update(csrf(request)) context = {"c": c} return render(request, "login.html", context)
def profile(request): # We always have the user, but not always the profile. And we need a bit # of a hack around the normal forms code since we have two different # models on a single form. (profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk) if request.method == "POST": # Process this form userform = UserForm(data=request.POST, instance=request.user) profileform = UserProfileForm(data=request.POST, instance=profile) if userform.is_valid() and profileform.is_valid(): userform.save() profileform.save() return HttpResponseRedirect("/account/") else: # Generate form userform = UserForm(instance=request.user) profileform = UserProfileForm(instance=profile) return render_to_response( "account/userprofileform.html", {"userform": userform, "profileform": profileform}, NavContext(request, "account"), )
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'register.html', { 'user_form': user_form, 'profile_form':profile_form, 'registered':registered } )
def profile_form(request,username,use_openid=False): if request.user.username != username: return HttpResponse("You cannot access another user's profile.", status=401) else: user = User.objects.get(username=username) try: user_profile = UserProfile.objects.get(user=user) except UserProfile.DoesNotExist: user_profile = UserProfile.objects.create(user=user) user_assoc = UserAssociation.objects.filter(user__id=user.id) if request.method == 'GET': uform = UserForm(instance=user) pform = UserProfileForm(instance=user_profile) return render_to_response('user_profile/user_profile_form.html', {'profile': user_profile, 'assoc': user_assoc, 'uform': uform, 'pform': pform, 'group_request_email': settings.GROUP_REQUEST_EMAIL, 'use_openid': use_openid, 'MEDIA_URL':settings.MEDIA_URL}) elif request.method == 'POST': uform = UserForm(data=request.POST, instance=user) pform = UserProfileForm(data=request.POST, instance=user_profile) if uform.is_valid(): user.save() if pform.is_valid(): user_profile.save() #return HttpResponseRedirect(reverse('user_profile-form', args=[username])) return HttpResponseRedirect(reverse('map')) else: return HttpResponse("Received unexpected " + request.method + " request.", status=400)
def user_profile(request): if request.session['email']: if request.method == 'POST': a = Join.objects.get(email=request.session['email']) try: b = UserProfile.objects.get(user=a) except: b = UserProfile(user=a) b.save() b = UserProfile.objects.get(user=a) form = UserProfileForm(request.POST, instance=b) if form.is_valid(): f = form.save(commit=False) f.user = a f.save() return HttpResponseRedirect('/fb/login/') else: return render(request, 'fb/profile.html', {'form': form}) else: a = Join.objects.get(email=request.session['email']) try: b = UserProfile.objects.get(user=a) except: b = UserProfile(user=a) b.save() b = UserProfile.objects.get(user=a) form = UserProfileForm(instance=b) return render(request, 'fb/profile.html', {'form': form}) else: return HttpResponseRedirect('/fb/login/')
def register(request, type): if type not in ['subject', 'tester']: raise Exception('register: invalid type.') if request.method == 'POST': rform = RegistrationForm(request.POST) pform = UserProfileForm(request.POST) if rform.is_valid() and pform.is_valid(): user = rform.save() if type == 'subject': group = Group.objects.get(name='Subjects') elif type == 'tester': group = Group.objects.get(name='Testers') user.groups.add(group) profile = pform.save(commit=False) profile.user = user profile.save() if type == 'tester': create_log_entry(profile, 'joined', []) return HttpResponseRedirect(reverse('home')) else: rform = RegistrationForm() pform = UserProfileForm() return render_to_response('testtool/registration/register.html', { 'rform': rform, 'pform': pform }, context_instance=RequestContext(request))
def register(request): registered = False if request.method =='POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.save_initials() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'lendborrow/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, )
def editprofile(request): user = User.objects.get(username=request.user) if request.method == "POST": email = request.POST['email'] try: existent_email = User.objects.get(email=email) except: existent_email = None if existent_email: return render(request, 'fhs/editprofile.html',{"existent": True}) form = EmailForm(data=request.POST, instance=request.user) picform = UserProfileForm(data=request.POST, instance=request.user) try: up = UserProfile.objects.get(user=request.user) except: up = None if form.is_valid() and picform.is_valid(): if email: user = form.save(commit=False) user.save() if 'picture' in request.FILES: up.picture = request.FILES['picture'] up.save() return HttpResponseRedirect('/fhs/profile/'+user.username) else: return render(request, 'fhs/editprofile.html',{})
def register(request): if request.user.is_authenticated(): return redirect('index') registered = False if request.method == 'POST': user_form = UserForm(data = request.POST) profile_form = UserProfileForm(data = request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.groups.add(Group.objects.get(name="Author")) user.set_password(user.password) user.save() profile = profile_form.save(commit = False) profile.user = user profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'account/signup.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, RequestContext(request))
def edit_profile(request): user = User.objects.get(username=request.user) if request.method == "POST": form = UserProfileForm(request.POST, request.FILES) if form.is_valid(): model_instance = form.save(commit=False) user_profile = UserProfile.objects.filter(user=user)[0] model_instance.id = user_profile.id model_instance.user_id = user_profile.user_id if request.FILES: model_instance.picture = request.FILES['picture'] else: model_instance.picture = user_profile.picture if request.POST['description']: model_instance.description = request.POST['description'] else: model_instance.description = user_profile.description model_instance.save() message = 'Your edit was successful!' context = {'message': message, 'model_instance': model_instance} return render(request, "thanks.html", context) else: form = UserProfileForm() context = {'form': form} return render(request, "edit_profile.html", context)
def my_profile(request): context = get_context(request) if not request.user.is_authenticated(): return redirect('login') else: user_profile = UserProfile.objects.get(user=request.user) if request.method == "POST": user_form = UserForm(request.POST, instance=request.user) user_profile_form = UserProfileForm(request.POST, instance=user_profile) if user_form.is_valid() and user_profile_form.is_valid(): user_form.save() user_profile_form.save() return redirect_after_profile_save(request, 'data') else: user_form = UserForm(instance=request.user) user_profile_form = UserProfileForm(instance=user_profile) user_form.helper.form_tag = False user_profile_form.helper.form_tag = False context['user_form'] = user_form context['user_profile_form'] = user_profile_form context['user_profile_page_form'] = UserProfilePageForm(instance=user_profile) context['user_cover_letter_form'] = UserCoverLetterForm(instance=user_profile) context['user_info_page_form'] = UserInfoPageForm(instance=user_profile.user_info) context['is_editing_profile'] = True context['title'] = u'Mój profil' return render(request, 'profile.html', context)
def register(request): if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] print profile.picture print type(profile.picture) profile.save() username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username=username, password=password) login(request, user) return redirect('/blog/') else: print user_form.errors error = user_form.errors.as_data().values()[0][0].messages[0] print type(error) return render(request, 'blog/auth/register.html', {'error': error}) else: return render(request, 'blog/auth/register.html')
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'rango/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def user_profile(request): user = User.objects.get(pk=request.user.id) user_profile_form = UserProfileForm(instance=user) ProfileInlineFormset = inlineformset_factory(User, UserProfile, fields=("phone_number",)) UserProfileFormset = ProfileInlineFormset(instance=user) if request.user.is_authenticated(): # and request.user.id == user.id: if request.method == "POST": user_profile_form = UserProfileForm(request.POST, request.FILES, instance=user) UserProfileFormset = ProfileInlineFormset(request.POST, request.FILES, instance=user) if user_profile_form.is_valid(): created_user = user_profile_form.save(commit=False) UserProfileFormset = ProfileInlineFormset(request.POST, request.FILES, instance=created_user) if UserProfileFormset.is_valid(): created_user.save() UserProfileFormset.save() return HttpResponseRedirect("/", user.username) context = { "user_name": user.username, "user_profile_form": user_profile_form, "user_profile_formset": UserProfileFormset, } return render(request, "user_profile.html", context) else: raise PermissionDenied
def register(request): registerd = False context_dict = {} context_dict["registerd"] = registerd if request.method == "POST": user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if "picture" in request.FILES: profile.picture = request.FILES["pictures"] profile.save() registerd = True context_dict["registerd"] = registerd else: print user_form.errors, profile_form.errors else: context_dict["user_form"] = UserForm context_dict["profile_form"] = UserProfileForm return render(request, "rango/register.html", context_dict)
def register(request): registerd = False context_dict = {} context_dict['registerd'] = registerd if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['pictures'] profile.save() registerd = True context_dict['registerd'] = registerd else: print user_form.errors, profile_form.errors else: context_dict['user_form'] = UserForm context_dict['profile_form'] = UserProfileForm return render(request, 'rango/register.html', context_dict)
def edit_profile(request): if request.method == "POST": form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) #succesful profil update view if form.is_valid(): originalform = UserProfileForm(instance = request.user.profile) form.save() return HttpResponseRedirect('/accounts/profile') else: user = request.user profile = user.profile form = UserProfileForm(instance = profile) args = {} args.update(csrf(request)) u = User.objects.get(username=user.username) # Get the first user in the system args['uname'] = u.username args['name'] = u.first_name args['last'] = u.last_name args['email'] = u.email args['thumbnail'] = request.user.profile.user_avatar args['form'] = form return render_to_response('edit_profile.html', args, context_instance=RequestContext(request))
def login(request): if request.user.is_authenticated(): # if there is a user logged in already user_name = UserProfile(name=request.user.username) if request.POST: form = UserProfileForm(request.POST, instance=user_name) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = UserProfileForm(instance=user_name) args = {} args.update(csrf(request)) args['form'] = UserProfileForm() print args context = {"full_name": request.user.username, "args" :args} return HttpResponseRedirect("", context) else: c={} c.update(csrf(request)) context = {"c": c} return render(request, "login.html", context)
def edit_profile(request): user = User.objects.get(username=request.user) if request.method == "POST": form = UserProfileForm(request.POST, request.FILES) if form.is_valid(): model_instance = form.save(commit=False) user_profile = UserProfile.objects.filter(user=user)[0] model_instance.id = user_profile.id model_instance.user_id = user_profile.user_id if request.FILES: model_instance.picture = request.FILES['picture'] else: model_instance.picture = user_profile.picture if request.POST['description']: model_instance.description = request.POST['description'] else: model_instance.description = user_profile.description model_instance.save() message = 'Your edit was successful!' context = {'message' : message, 'model_instance' : model_instance} return render(request, "thanks.html", context) else: form = UserProfileForm() context = { 'form' : form} return render(request, "edit_profile.html", context)
def add_user(request): registered = False if request.method == 'POST': profile_form = UserProfileForm(data=request.POST) device_form = UserDeviceForm(data=request.POST) if profile_form.is_valid(): userprofile = profile_form.save() userprofile.last_played = datetime.datetime.now() if 'song' in request.FILES: userprofile.song = request.FILES['song'] userprofile.save() if device_form.is_valid(): deviceform = device_form.save() deviceform.user_profile = userprofile deviceform.save() registered = True else: profile_form = UserProfileForm() device_form = UserDeviceForm() return render( request, 'add_user.html', { 'profile_form': profile_form, 'device_form': device_form, 'registered': registered })
def my_profile(request): context = get_context(request) if not request.user.is_authenticated(): return redirect('login') else: user_profile = UserProfile.objects.get(user=request.user) if request.method == "POST": user_form = UserForm(request.POST, instance=request.user) user_profile_form = UserProfileForm(request.POST, instance=user_profile) if user_form.is_valid() and user_profile_form.is_valid(): user_form.save() user_profile_form.save() return redirect_after_profile_save(request, 'data') else: user_form = UserForm(instance=request.user) user_profile_form = UserProfileForm(instance=user_profile) user_form.helper.form_tag = False user_profile_form.helper.form_tag = False context['user_form'] = user_form context['user_profile_form'] = user_profile_form context['user_profile_page_form'] = UserProfilePageForm( instance=user_profile) context['user_cover_letter_form'] = UserCoverLetterForm( instance=user_profile) context['user_info_page_form'] = UserInfoPageForm( instance=user_profile.user_info) context['is_editing_profile'] = True context['title'] = u'Mój profil' return render(request, 'profile.html', context)
def register(request): # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(request.POST,request.FILES) # p = UserProfileForm(data=request.FILES) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid():# and p.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: # p.picture = request.FILES['picture'] # p.save() profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() # Update our variable to tell the template registration was successful. registered = True # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def user_profile_edit(request): instance1 = get_object_or_404(User, id=request.user.id) instance2 = get_object_or_404(UserProfile, id=request.user.profile.id) args = {} args.update(csrf(request)) if request.method == "POST": form1 = RegistrationForm(request.POST, instance=instance1) form2 = UserProfileForm(request.POST, request.FILES, instance=instance2) args["err"] = form1.errors args["err2"] = form2.errors if form1.is_valid() * form2.is_valid(): user = form1.save() userprofile = form2.save(commit=False) userprofile.user = user userprofile.save() return HttpResponseRedirect('/dashboard') args["form"] = RegistrationForm(instance=instance1) args["form2"] = UserProfileForm(instance=instance2) args["form_title"] = "Edit Profile Info" return render(request, 'register.html', args, RequestContext(request))
def profile_edit(request): if request.method == "POST": user_form = UserEditForm(request.POST, request.FILES, instance=request.user) profile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.user) if user_form.is_valid(): user_form.save() if profile_form.is_valid(): profile_form.save() return redirect('profile') else: if not request.user: return redirect('login') else: user_form = UserEditForm(instance=request.user) profile_form = UserProfileForm(instance=request.user.user) return render(request, 'campusthrift/profile_edit.html', { 'user_form': user_form, 'profile_form': profile_form })
def register(request): context = RequestContext(request) registered = False cat_list = get_category_list() if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'rango/register.html', {'user_form': user_form, 'profile_form':profile_form, 'cat_list':cat_list, 'registered': registered}, context)
def register(request): # Like before, get the request's context. context = RequestContext(request) if request.user.is_authenticated: #return HttpResponseRedirect('/profile') #else: # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) validation_form = ValidationForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid( ) and validation_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.user_since = datetime.datetime.today() if 'picture' in request.FILES: profile.picture = request.FILES['picture'] user_id = user.id if user_id % 2 is 0: profile.condition = 1 elif user_id % 2 is not 0: profile.condition = 2 profile.save() registered = True new_user = authenticate(username=request.POST['username'], password=request.POST['password']) login(request, new_user) else: print user_form.errors, profile_form.errors, validation_form.errors else: user_form = UserForm() profile_form = UserProfileForm() validation_form = ValidationForm() return render_to_response( 'badsearch/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'validation_form': validation_form, 'registered': registered }, context)
def register(request): if request.session.test_cookie_worked(): print(">>>>>TEST COOKIE WORKED!") request.session.delete_test_cookie() # Request the context. context = RequestContext(request) context_dict = {} # Boolean telling us whether registration was successful or not. # Initially False; presume it was a failure until proven otherwise! registered = False # If HTTP POST, we wish to process form data and create an account. if request.method == 'POST': # Grab raw form data - making use of both FormModels. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # Two valid forms? if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data. That one is easy. user = user_form.save() # Now a user account exists, we hash the password with the set_password() method. # Then we can update the account with .save(). user.set_password(user.password) user.save() # Now we can sort out the UserProfile instance. # We'll be setting values for the instance ourselves, so commit=False prevents Django from saving the instance automatically. profile = profile_form.save(commit=False) profile.user = user # Profile picture supplied? If so, we put it in the new UserProfile. if 'picture' in request.FILES: profile.picture = request.FILES['picture'] # Now we save the model instance! profile.save() # We can say registration was successful. registered = True # Invalid form(s) - just print errors to the terminal. else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render the two ModelForms to allow a user to input their data. else: user_form = UserForm() profile_form = UserProfileForm() context_dict['user_form'] = user_form context_dict['profile_form'] = profile_form context_dict['registered'] = registered # Render and return! return render_to_response('rango/register.html', context_dict, context)
def profile(request): form = UserProfileForm(request.POST) if request.method == 'POST': if form.is_valid(): userprofile = form.save(commit=False) userprofile.user = request.user userprofile.save() else: print(messages.error(request, "Error")) return render(request, "profileform.html", RequestContext(request, {'form': form, 'profile': profile,}))
def profile_data_save(request): form = UserProfileForm(data=request.POST.copy() or None, instance=request.user.get_profile()) if form.is_bound and form.is_valid() and form.save(request.user): request.session['user_timezone'] = pytz.timezone( form.data.get('timezone')) messages.success(request, _(u'Changed your profile data.')) return redirect('app_auth_profile')
def user_profile(request): ensure_profile(request.user) if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user.userprofile) if form.is_valid(): form.save() return redirect(request.user.get_absolute_url()) else: form = UserProfileForm(instance=request.user.userprofile) return render(request, "users/user_profile.html", {"form": form})
def update_usermessage(request): if request.method == "POST": umessage_form = UserProfileForm(request.POST, instance=request.user.get_profile()) print umessage_form.errors if umessage_form.is_valid(): userprofile = umessage_form.save() #return HttpResponseRedirect("/accounts/userinfo/" + str(request.user.id)) return HttpResponse(userprofile.message) return HttpResponse(request.user.get_profile().message)
def register(request): # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # if post, process form data if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True # invalid form else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render( request, "register.html", { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): # Register users in the system context = RequestContext(request) email_in_db = False registered = False username_taken = False if request.method == 'POST': user_data = request.POST user_data['username'] = user_data['username'].strip() user_form = UserForm(user_data) profile_form = UserProfileForm(user_data) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) # c heck if email is in the database email_to_be_checked = user.email # if no user has this email, the query will result in an error, then # the except statement will be executed, resulting in a successful registration try: test_user = User.objects.get(email=email_to_be_checked) email_in_db = True except User.DoesNotExist: # save user and user_profile, and sign in the user with the non-hashed password non_hashed_password = user.password user.set_password(non_hashed_password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True # In the end, log the user into the system user2 = authenticate(username=user.username, password=non_hashed_password) login(request, user2) else: # convert the errors into a json format user_form_errors = json.loads(user_form.errors.as_json()) # check if the user_form error was raised because someone tried to register with a username that is already in the dbs if user_form_errors.has_key("username") and \ user_form_errors['username'][0]['message'] == "User with this Username already exists.": username_taken = True else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'ArtVillage/register.html', { 'user_form': user_form, 'registered': registered, 'email_in_db': email_in_db, 'username_taken': username_taken, 'profile_form': profile_form }, context)
def userprofile(request): (profile, created) = UserProfile.objects.get_or_create(user=request.user) form = mailform = None if request.method == 'POST': if request.POST['submit'] == 'Save': form = UserProfileForm(request.user, request.POST, instance=profile) if form.is_valid(): form.save() messages.add_message(request, messages.INFO, "User profile saved.") return HttpResponseRedirect('.') elif request.POST['submit'] == 'Add email': mailform = MailForm(request.POST) if mailform.is_valid(): m = UserExtraEmail(user=request.user, email=mailform.cleaned_data['email'], confirmed=False, token=generate_random_token(), tokensent=datetime.now()) m.save() send_template_mail( settings.NOTIFICATION_FROM, request.user.username, m.email, 'Your email address for commitfest.postgresql.org', 'extra_email_mail.txt', { 'token': m.token, 'user': m.user }) messages.info( request, "A confirmation token has been sent to %s" % m.email) return HttpResponseRedirect('.') else: messages.error(request, "Invalid submit button pressed! Nothing saved.") return HttpResponseRedirect('.') if not form: form = UserProfileForm(request.user, instance=profile) if not mailform: mailform = MailForm() extramails = UserExtraEmail.objects.filter(user=request.user) return render_to_response('userprofileform.html', { 'form': form, 'extramails': extramails, 'mailform': mailform, }, context_instance=RequestContext(request))
def user_profile(request): usuario = request.user if request.method == 'POST': form = UserProfileForm(request.POST, instance=usuario) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('home')) else: form = UserProfileForm(instance=usuario) return render(request, 'mi_perfil.html', locals())