def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.job_title = form.cleaned_data.get('job_title') user.email = form.cleaned_data.get('email') user.profile.web_page = form.cleaned_data.get('web_page') user.profile.city = form.cleaned_data.get('city') user.profile.state = form.cleaned_data.get('state') user.profile.country = form.cleaned_data.get('country') user.profile.institution = form.cleaned_data.get('institution') user.profile.bio = form.cleaned_data.get('bio') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: form = ProfileForm(instance=user, initial={ 'job_title': user.profile.job_title, 'web_page': user.profile.web_page, 'city': user.profile.city, 'state': user.profile.state, 'country': user.profile.country, 'institution': user.profile.institution, 'bio': user.profile.bio, }) return render(request, 'core/settings.html', {'form': form})
def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.department = form.cleaned_data.get('department') user.email = form.cleaned_data.get('email') user.profile.joiningyear = form.cleaned_data.get('joiningyear') user.profile.location = form.cleaned_data.get('location') user.profile.phone = form.cleaned_data.get('phone') user.profile.gphone = form.cleaned_data.get('gphone') user.profile.room_num = form.cleaned_data.get('room_num') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: form = ProfileForm(instance=user, initial={ 'department': user.profile.department, 'joiningyear': user.profile.joiningyear, 'location': user.profile.location, 'phone': user.profile.phone, 'gphone': user.profile.gphone, 'room_num': user.profile.room_num }) return render(request, 'core/settings.html', {'form': form})
def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.job_title = form.cleaned_data.get('job_title') user.email = form.cleaned_data.get('email') user.profile.url = form.cleaned_data.get('url') user.profile.location = form.cleaned_data.get('location') user.profile.type = form.cleaned_data.get('type') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: form = ProfileForm(instance=user, initial={ 'job_title': user.profile.job_title, 'url': user.profile.url, 'location': user.profile.location, 'type': user.profile.type, }) return render(request, 'core/settings.html', {'form': form})
def settings(request): user = request.user if request.method == "POST": form = ProfileForm(request.POST) if form.is_valid(): # user.first_name = form.cleaned_data.get('first_name') # user.last_name = form.cleaned_data.get('last_name') # user.profile.job_title = form.cleaned_data.get('job_title') user.profile.url = form.cleaned_data.get("url") # user.profile.location = form.cleaned_data.get('location') user.email = form.cleaned_data.get("email") user.profile.self_introduction = form.cleaned_data.get("self_introduction") user.profile.area = form.cleaned_data.get("area") user.save() messages.add_message(request, messages.SUCCESS, "Your profile were successfully edited.") else: form = ProfileForm( instance=user, initial={ "birthday": user.profile.birthday, "self_introduction": user.profile.self_introduction, "language": user.profile.language, "area": user.profile.area, "url": user.profile.url, "gender": user.profile.gender, }, ) return render(request, "core/settings.html", {"form": form})
def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.email = form.cleaned_data.get('email') user.phone = form.cleaned_data.get('phone') user.dob = form.cleaned_data.get('dob') user.ten = form.cleaned_data.get('ten') user.tenpy = form.cleaned_data.get('tenpy') user.twelve = form.cleaned_data.get('twelve') user.twelvepy = form.cleaned_data.get('twelvepy') user.branch = form.cleaned_data.get('branch') user.cgpa = form.cleaned_data.get('cgpa') user.live_kt = form.cleaned_data.get('live_kt') user.dead_kt = form.cleaned_data.get('dead_kt') # user.profile = form.cleaned_data.get('profile') user.interest = form.cleaned_data.get('interest') user.skills = form.cleaned_data.get('skills') user.awards = form.cleaned_data.get('awards') user.experience = form.cleaned_data.get('experience') user.project = form.cleaned_data.get('project') user.facebook = form.cleaned_data.get('facebook') user.twitter = form.cleaned_data.get('twitter') user.linkedin = form.cleaned_data.get('linkedin') user.google_plus = form.cleaned_data.get('google_plus') user.iframe_maps = form.cleaned_data.get('iframe_maps') user.passing_year = form.cleaned_data.get('passing_year') # user.profile.url = form.cleaned_data.get('url') # user.profile.location = form.cleaned_data.get('location') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: form = ProfileForm( instance=user, initial={ # 'job_title': user.profile.job_title, # 'url': user.profile.url, # 'location': user.profile.location }) return render(request, 'core/settings.html', {'form': form})
def settings(request): user = request.user if request.method == "POST": form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get("first_name") user.last_name = form.cleaned_data.get("last_name") user.profile.job_title = form.cleaned_data.get("job_title") user.email = form.cleaned_data.get("email") user.profile.url = form.cleaned_data.get("url") user.profile.location = form.cleaned_data.get("location") user.save() messages.add_message(request, messages.SUCCESS, "Your profile were successfully edited.") else: form = ProfileForm( instance=user, initial={"job_title": user.profile.job_title, "url": user.profile.url, "location": user.profile.location}, ) return render(request, "core/settings.html", {"form": form})
def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.job_title = form.cleaned_data.get('job_title') user.email = form.cleaned_data.get('email') user.profile.url = form.cleaned_data.get('url') user.profile.location = form.cleaned_data.get('location') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile were successfully edited.') else: form = ProfileForm(instance=user, initial={ 'job_title': user.profile.job_title, 'url': user.profile.url, 'location': user.profile.location }) return render(request, 'core/settings.html', {'form':form})
def settings(request): # 因为已经登录了,所以从request中可以去的user user = request.user if request.method == 'POST': # 处理表单保存 # 用post过来的属性 初始化一个form form = ProfileForm(request.POST) # 如果form合法的话 if form.is_valid(): # cleaned_data 获取合法数据 user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') # profile 关联到 user , 一对一 user.profile.job_title = form.cleaned_data.get('job_title') user.email = form.cleaned_data.get('email') user.profile.url = form.cleaned_data.get('url') user.profile.location = form.cleaned_data.get('location') # 因为设置了信号,所以保存user就可以了 user.save() # 创建一个flash message, 告诉已经成功创建 messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: # 如果是get方法的话, 初始化一个默认的form form = ProfileForm(instance=user, initial={ 'job_title': user.profile.job_title, 'url': user.profile.url, 'location': user.profile.location }) # 用form去渲染html return render(request, 'core/settings.html', {'form': form})
def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.year = form.cleaned_data.get('year') user.email = form.cleaned_data.get('email') user.profile.branch = form.cleaned_data.get('branch') user.profile.stream = form.cleaned_data.get('stream') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: form = ProfileForm(instance=user, initial={ 'year': user.profile.year, 'branch': user.profile.branch, 'stram': user.profile.stream }) return render(request, 'core/settings.html', {'form': form})