コード例 #1
0
ファイル: views.py プロジェクト: zhyq0826/linkus-django
def setting(request,template_name='setting/setting.html'):
	try:
		u = request.session['user']
		errors={}
		G={}
		if request.method=='GET':
			data={'nickname':u.nickname,'blog':u.blog,'url':u.url,'signature':u.signature}
			form = UserForm(data,auto_id='%s')
			return render_to_response(template_name,{'form':form},context_instance=RequestContext(request))
		else:
			form = UserForm(request.POST,auto_id='%s')
			if form.is_valid():
				nickname = form.cleaned_data['nickname']
				if not check_nick_name(nickname):
					errors['ni_error']='昵称2-12位,支持中文,数字,字母'
					return render_to_response(template_name,{'form':form,'errors':errors},context_instance=RequestContext(request))	
				form.update(u.id)
				u = get_user(u.id)
				request.session['user']=u
				G['success']='success'
				return render_to_response(template_name,{'form':form,'G':G},context_instance=RequestContext(request))
			else:
				return render_to_response(template_name,{'form':form},context_instance=RequestContext(request))

	except Exception, e:
		raise 
コード例 #2
0
ファイル: views.py プロジェクト: zhyq0826/linkus-django
def setting_url(request,template_name='setting/setting_url.html'):
	try:
		u = request.session['user']
		errors={}
		G={}
		if request.method=='GET':
			data={'url':u.url}
			form = UserUrl(data,auto_id='%s')
			return render_to_response(template_name,{'form':form},context_instance=RequestContext(request))
		else:
			form = UserUrl(request.POST,auto_id='%s')
			if form.is_valid():
				url = form.cleaned_data['url']
				if not check_url(url):
					errors['url_error']='个性域名必须由4-20位数字和字母组成'
					return render_to_response(template_name,{'form':form,'errors':errors},context_instance=RequestContext(request))	
				form.update(u.id)
				u = get_user(u.id)
				request.session['user']=u
				G['success']='success'
				return render_to_response(template_name,{'form':form,'G':G},context_instance=RequestContext(request))
			else:
				return render_to_response(template_name,{'form':form},context_instance=RequestContext(request))


	except Exception, e:
		raise
コード例 #3
0
ファイル: views.py プロジェクト: zhyq0826/linkus-django
def setting_crop_avatar(request):
	try:
		u = request.session['user']
		if request.method=="POST":
			x1 = request.POST.get('x1')
			y1 = request.POST.get('y1')
			x2 = request.POST.get('x2')
			y2 = request.POST.get('y2')
			filename = request.POST.get('filename')
			try:
				x1 = float(x1)
				x2 = float(x2)
				y1 = float(y1)
				y2 = float(y2)
			except Exception, e:
				raise
			cordinate=(x1,y1,x2,y2)
			avatar_name=handle_avatar(filename,cordinate)
			update_user_avatar(u.id,avatar_name[0],avatar_name[1],filename)
			request.session['user']=get_user(u.id)
			return redirect('/setting/')
		else: