예제 #1
0
def submit_string(request):
	if request.method == 'POST':		
		form = TextForm(request.POST)
		
		if form.is_valid():			
			form.save()
			return HttpResponseRedirect(reverse('CatchShow.submit.views.submitSuccess'))			
	else:
		form = TextForm()
	return render_to_response('submitString.html',
							  {'form': form},
							  context_instance=RequestContext(request)
							 )
예제 #2
0
def submit_string_to_file(request):
	if request.method == 'POST':		
		form = TextForm(request.POST)
		store = request.POST['string_text']
		store_file = ContentFile(store.encode('UTF-8'))
		if form.is_valid():
			curtime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
			file_type = '.txt'
			file_name = curtime + file_type
			file_path = 'files/'
			handle_uploaded_file(f = store_file, filename = file_name, filepath = file_path)
			path = os.path.join(settings.MEDIA_ROOT, "%s%s" % (file_path, file_name))
			fileform = FileForm({'id':curtime,'file':path})
			if fileform.is_valid():
				fileform.save()
				return HttpResponseRedirect(reverse('CatchShow.submit.views.submitSuccess'))			
	else:
		form = TextForm()
	return render_to_response('submitString.html',
							  {'form': form},
							  context_instance=RequestContext(request)
							 )
예제 #3
0
def submit_file_to_string(request):
	if request.method == 'POST':
		form = UploadFileForm(request.POST, request.FILES)	
		if form.is_valid():
			uploadfile = request.FILES['upfile']		
			if uploadfile is None:
				return render_to_response('test.html',
									context_instance=RequestContext(request)
									)		
			content = uploadfile.read()
			ucontent = unicode(content)
			curtime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))			
			textform = TextForm({'id':curtime,'string_text':ucontent})
			if textform.is_valid():
				textform.save()
				return HttpResponseRedirect(reverse('CatchShow.submit.views.submitSuccess'))	
	else:
		form = UploadFileForm()
		return render_to_response('submitFile.html',
							  {'form': form},
							  context_instance=RequestContext(request)
							 )