示例#1
0
def happy(request):

    result = ''
    final_result = ''
    stat=''
    total='0'
    lat='31.218816'
    lng='121.416603'

    if request.method == 'POST':
        form = DefaultForm(request.POST)
        if form.is_valid():
            keyword = form.cleaned_data['keyword']
            clienttype = form.cleaned_data['clienttype']
            postype = form.cleaned_data['postype']
            sorttype = form.cleaned_data['sorttype']
            lng = form.cleaned_data['lng']
            lat = form.cleaned_data['lat']
            distance = form.cleaned_data['distance']


            if keyword != '' or distance != '':
                url = createQuery(keyword, sorttype, clienttype, postype, lng, lat, distance)
                result = urllib2.urlopen(encoding.smart_str(url)).read()
                if result != '':

                    final_result = simplejson.loads(result)['records']
                    total = simplejson.loads(result)['totalhits']
    else:
        form = DefaultForm()

    return render_to_response('happytimes.html', {'form': form, 'total':total, 'result': final_result, 'lat':lat, 'lng':lng }, context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: Yong-Lee/mysite
def defaultconfig(request):
	username = request.session.get('username','')
	if username:
		try:
			if request.method == "POST":
				fw = DefaultForm(request.POST)
				if fw.is_valid():
					fs = request.POST.get('defaultconfig')
					addmd5(fs,'default')
					default = open('/tftpboot/pxelinux.cfg/default','w+')
					default.write(fs)
					default.close()
					# temp = shellshow('service dhcpd start')
					# print temp
					# shellshow('service dhcpd start')
					return render_to_response('defaultconfig.html',{'defaultconfig':fs,'username':username})
			else:
				default = open('/tftpboot/pxelinux.cfg/default','r+')
				str = ''
				for line in default.readlines():
					str = str + line
				default.close()
				# template = loader.get_template("configfile.html")
				# context = Context({'configfile':str,'username':name})
				# return HttpResponse(template.render(context))
				return render_to_response('defaultconfig.html',{'defaultconfig':str,'username':username})
			return render_to_response('defaultconfig.html',{'defaultconfig':fw.cleaned_data['defaultconfig'],'username':username})
		except IOError: 
    			print('IOError') 
    		finally: 
    			default.close() 
	else:
		return HttpResponseRedirect('/user/login/')