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 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 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 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 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 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 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 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 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 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 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 user_profile(): #修改教师/学生资料 if request.method == 'GET': uid=request.args.get('id') if uid is None: return redirect("/admin/userlist") user=Student.query.get(uid) if user is None: user=Teacher.query.get(uid) if user is None: return redirect("/admin/userlist") return render_template('admin/user_profile.html',stu=None,tea=user) return render_template('admin/user_profile.html',stu=user,tea=None) form=UserProfileForm(request.form) if form.validate(): form.save() flash(u"资料成功更新!") #current_app.logger.debug(3) for fieldName, errorMessages in form.errors.iteritems(): for err in errorMessages: flash(err) #current_app.logger.debug(2) if form.stuid is not None and form.stuid.data!='': user=Student.query.get(form.stuid.data) return render_template('admin/user_profile.html',stu=user,tea=None) else: user=Teacher.query.get(form.teaid.data) return render_template('admin/user_profile.html',stu=None,tea=user)
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 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 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 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 update_userprofileimg(request): if request.method == "POST": uprofile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.get_profile()) print uprofile_form.errors if uprofile_form.is_valid(): uprofile_form.save() return HttpResponseRedirect("/accounts/userinfo/" + str(request.user.id)) raise Http404
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() else: form = UserProfileForm(instance=request.user.userprofile) return render(request, "users/user_profile.html", {"form":form})
def save_profile_json(request): answer = { 'success': True } if request.is_ajax(): try: form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) form.save() except: answer["success"] = False; return HttpResponse(json.dumps(answer), mimetype="application/json")
def profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() messages.add_message(request, messages.INFO, u'Profile was successfully updated') else: form = UserProfileForm(instance=request.user) return render(request, 'accounts/profile.html', {'form': form, 'user': request.user,})
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 profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user) if form.is_valid(): form.save() else: form = UserProfileForm(instance=request.user) return render(request, "accounts/profile.html", { 'form': form, })
def user_profile(request): if request.method == "POST": form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/loggedin/') else: profile = request.user.profile # create profile if needed (property in model) form = UserProfileForm(instance=profile) args = {'form': form} args.update(csrf(request)) return render_to_response('profile.html', args)
def profile_edit_action(request): profile = try_get_profile(request) if request.POST: form = UserProfileForm(request.POST, instance=profile) if form.is_valid(): messages.success(request, 'Your changes saved successfuly.') form.save() redirect('/user/profile/view') pass else: form = UserProfileForm(instance =profile) return { 'form': form }
def profile_edit_action(request): if request.POST: form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) if form.is_valid(): messages.success(request, 'Your changes saved successfuly.') form.save() return redirect('/user/profile/view') else: messages.success(request, 'Your changes saved successfuly.') else: form = UserProfileForm(instance=request.user.profile) return { 'form': form }
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 profile(request): form = UserProfileForm(request.POST or None, instance=request.user.Profile) data = {} if request.method == 'POST': if form.is_valid(): form.save() else : data['errors'] = form.errors data['form'] = form data['title'] = 'Profile' return render(request,'accounts/profile.html', data)
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())
def userprofileold(request): if request.method == "POST": form = UserProfileForm(request.POST) if form.is_valid(): form.instance.user = request.user form.save() return HttpResponseRedirect("signup_success") else: args = {} args.update(csrf(request)) args["form"] = UserProfileForm() return render_to_response("userprofile.html", args)
def MyAccount(request, slug): if not request.user.is_authenticated(): return redirect('/accounts/login') profile = UserProfile.objects.get(slug = slug) if request.method == 'POST': form = UserProfileForm(request.POST, instance=profile) if form.is_valid(): form.save() profile = UserProfile.objects.get(slug = slug) form = UserProfileForm(instance=profile) return render(request, 'accounts/edit.html', {'form': form}) form = UserProfileForm(instance=profile) return render(request, 'accounts/edit.html', {'form': form})
def userprofile(request): if request.method == "POST": form = UserProfileForm(request.POST) if form.is_valid(): form.instance.user = request.user form.save() return HttpResponseRedirect('signup_success') else: args = {} args.update(csrf(request)) args['form'] = UserProfileForm() return render_to_response('userprofile.html', args)
def update_profile_save_page(request): if request.method != "POST" : return HttpResponseRedirect('/') else: user = UserProfile.objects.get(user=request.user) profile_form = UserProfileForm(request.POST, request.FILES, instance=user) if profile_form.is_valid(): profile_form.save() else: return HttpResponseRedirect('/') return HttpResponseRedirect(user.get_absolute_url())
def edit_profile(request): args = {} args.update(csrf(request)) #test navbar func self = navbar(request.user.id) #self = request.user if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile) #follow = userFollowActivity.objects.get(user=request.user) follow = bandFollow.objects.values_list( 'band_id', flat=True).filter(user_id=request.user.id) generes = Generes.objects.get(user=request.user) # generes =u','.join(self.cleaned_data['generes']) 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) try: generes = Generes.objects.get(user=request.user) except Generes.DoesNotExist: generes = None try: #follow = userFollowActivity.objects.get(user=request.user) follow = bandFollow.objects.values_list( 'band_id', flat=True).filter(user_id=request.user.id) except bandFollow.DoesNotExist: follow = None 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', { 'from_user': self, 'self': self, 'form': form, 'follow': follow, 'first_name': first_name, 'last_name': last_name, 'generes': generes }, context_instance=RequestContext(request))
def user_profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance= request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/he') else: user= request.user profile = user.profile form = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['form']= form return render_to_response('userprofile/profile.html', args, context_instance=RequestContext(request))
def user_profile(request): if request.method=="POST": form=UserProfileForm(request.POST,instance=request.user.profile) if form.is_valid(): form.save() return HttpResponse('sucessfully registered your extra details!!!') else: user=request.user profile=user.profile form=UserProfileForm(instance=profile) args={} args.update(csrf(request)) args['form']=form return render_to_response('profile.html',args)
def profile(request): flash = None form = None if request.method == "POST": form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): flash = "Profile saved successfully!" form.save() else: form = UserProfileForm(instance=request.user.profile) return render_to_response( "profiles/profile.html", {"form": form, "flash": flash}, context_instance=RequestContext(request) )
def user_profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/loggedin') else: user = request.user profile = user.profile form = UserProfileForm(instance=profile) args = {} args['form'] = form return render(request, 'profile.html', args)
def user_profile(request): if request.POST: form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/loggedin') else: user = request.user profile = user.profile form = UserProfileForm(instance=profile) context = {} context.update(csrf(request)) context['form'] = form return render(request, 'profile.html', context)
def user_profile(request): if request.method == "POST": form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect("/accounts/desktop") else: form = UserProfileForm() args = {} args.update(csrf(request)) args["form"] = form return render_to_response("user_profile.html", args)
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) # Don't allow users whose accounts were created via oauth to change # their email, since that would kill the connection between the # accounts. can_change_email = (request.user.password != OAUTH_PASSWORD_STORE) # We may have a contributor record - and we only show that part of the # form if we have it for this user. try: contrib = Contributor.objects.get(user=request.user.pk) except Contributor.DoesNotExist: contrib = None contribform = None if request.method == 'POST': # Process this form userform = UserForm(data=request.POST, instance=request.user) profileform = UserProfileForm(data=request.POST, instance=profile) if contrib: contribform = ContributorForm(data=request.POST, instance=contrib) if userform.is_valid() and profileform.is_valid() and ( not contrib or contribform.is_valid()): userform.save() profileform.save() if contrib: contribform.save() return HttpResponseRedirect("/account/") else: # Generate form userform = UserForm(instance=request.user) profileform = UserProfileForm(instance=profile) if contrib: contribform = ContributorForm(instance=contrib) return render_pgweb( request, 'account', 'account/userprofileform.html', { 'userform': userform, 'profileform': profileform, 'contribform': contribform, 'can_change_email': can_change_email, })
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 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 profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance = request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/loggedin/') else: user = request.user profile = user.profile form = UserProfileForm(instance = profile) args = {} args.update(csrf(request)) args['form'] = form return render_to_response('user_profile.html', args)
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 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 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 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): # 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 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 user_profile(request): if request.method == "POST": form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect("/accounts/loggedin/") else: user = request.user profile = user.profile form = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['form'] = form return render(request, 'user_profile.html', args)
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): 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 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 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_profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, instance=request.user.profile) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/loggedin') else: user = request.user profile = user.profile # instance pre-populates any existing data from the models form = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['form'] = form return render_to_response('profile.html', args)