Beispiel #1
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.sex = form.sex.data
        current_user.one_desc = form.one_desc.data
        current_user.about_me = form.about_me.data
        current_user.location = form.location.data
        current_user.industry = form.industry.data
        current_user.company = form.company.data
        current_user.job = form.job.data
        current_user.school = form.school.data
        current_user.majar = form.majar.data
        db.session.add(current_user)
        db.session.commit()
        flash('修改成功')
        return redirect(url_for('main.user', id=current_user.id))
    form.sex.data = str(current_user.sex)
    form.one_desc.data = current_user.one_desc
    form.about_me.data = current_user.about_me
    form.location.data = current_user.location
    form.industry.data = current_user.industry
    form.company.data = current_user.company
    form.job.data = current_user.job
    form.school.data = current_user.school
    form.majar.data = current_user.majar
    return render_template('edit_profile.html', form=form)
Beispiel #2
0
def editUser(request, pk):
    user = get_object_or_404(UserProfile, pk=pk)
    form = EditProfileForm (instance=user)
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            return redirect('account')
    return render_to_response('editProfile.html', {
        'form': form,
    }, RequestContext(request))
Beispiel #3
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('main.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', title=_('Edit Profile'),
                           form=form)
Beispiel #4
0
def editProfile(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = EditProfileForm(request.POST, instance=UserProfile.objects.get(user=request.user))
            if form.is_valid():
                form.save()
                return redirect('profile')
            else:
                return render_to_response('home.html', {'form': form}, RequestContext(request))
        form = EditProfileForm(instance=UserProfile.objects.get(user=request.user))
        dic = {'form': form}
        dic.update(csrf(request))
        return render_to_response('editProfile.html', dic)
    return redirect('login')
Beispiel #5
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        db.session.commit()
        flash(u'您已经成功更新了资料')
        return redirect(url_for('main.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
Beispiel #6
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        db.session.commit()
        flash(u'您已经成功更新了资料')
        return redirect(url_for('main.user',username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
Beispiel #7
0
def EditProfile(request, slug):
    slug = slug.strip()
    # query = get_object_or_404(User, username=slug)
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    try:
        query = User.objects.get(username=slug)
    except User.DoesNotExist:
        return render(
            request,
            'main/user_update_form.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )

    userextend = UserExtend.objects.get(user=query)
    data = {'gender': userextend.gender, 'brief_desc': userextend.brief_desc}
    if request.method == "POST":
        form = EditProfileForm(request.POST, request.FILES)
        if form.is_valid():
            userextend.gender = form.cleaned_data['gender']
            userextend.brief_desc = form.cleaned_data['brief_desc']
            attach_data = form.cleaned_data['attach']
            att = Attachment.objects.create(file=attach_data)
            userextend.profile_pix = att
            userextend.save()
            return HttpResponseRedirect(
                reverse('userProfile', args=(query.username, )))
    else:
        form = EditProfileForm(initial=data)

    return render(
        request,
        'main/user_update_form.html',
        {
            'sections': sections,
            'post_num': post_num,
            'user_num': user_num,
            'form': form,
        },
    )
Beispiel #8
0
def edit(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()
            return render(request, 'account/profile.html')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'account/edit_profile.html', args)
Beispiel #9
0

def logout_view(request):
	logout(request)
	return redirect('/signup/')

def profile_page(request):
	context = {}
	print request.user
	print request.user.pk
	try:
		context['user'] = CustomUser.objects.get(pk=request.user.pk)
	except Exception, e:
		raise Http404('404')
	return render(request, 'profile_page.html', context)

def edit_profile(request):
	context = {}
	try:
		user = CustomUser.objects.get(pk=request.user.pk)
	except Exception, e:
		raise Http404('404')
	form = EditProfileForm(request.POST or None, instance=user)
	context['form'] = form
	if form.is_valid():
		form.save()
		return redirect('/profile/')
	else:
		print form.errors
	return render(request, 'edit_profile.html', context)