当前位置: 首页>>代码示例>>Python>>正文


Python UploadForm.fields['step']方法代码示例

本文整理汇总了Python中forms.UploadForm.fields['step']方法的典型用法代码示例。如果您正苦于以下问题:Python UploadForm.fields['step']方法的具体用法?Python UploadForm.fields['step']怎么用?Python UploadForm.fields['step']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UploadForm的用法示例。


在下文中一共展示了UploadForm.fields['step']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import fields['step'] [as 别名]
def upload(request):
	'''
	Default view for the homepage.  Handles all public image submissions
	'''
	
	# variables passed to template
	context = {}
	
	if request.method == 'GET':
		'''
		Homepage.  Inital form.
		Step 1 - user chooses a picture to upload
		user proceeds through steps with POST requests
		'''
		form = UploadForm()
		form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="upload")
		context['form'] = form
		context['step'] = 'steps/upload.djt'
		request.session.clear() # clear submission cache, starting new submission process
	
	elif request.method == 'POST' and request.POST:
		
		if request.POST['step'] == "upload":
			''' 
			Step 2
			verfiy upload form
			if valid proceed to inspect then details form
			'''
			form = UploadForm(request.POST, request.FILES)
			form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="upload")
			if not form.is_valid():
				messages.error(request, 'Form data was invalid')
				context['form'] = form
				context['step'] = 'steps/upload.djt'
			else:
				# save and return details form
				submission = form.save()
				submission.generate_thumbnail()
				submission.auto_fill()
				submission.complete = False
				submission.save()
				request.session['submission_id'] = submission.id
				form = DetailsForm(instance=submission)
				form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="details")
				context['form'] = form
				context['submission'] = submission
				context['step'] = 'steps/details.djt'

		if request.POST['step'] == "details":
			'''
			Step 3
			complete photo submission
			'''
			submission_id = request.session.get('submission_id', None)
			try:
				submission = Submission.objects.get(pk=submission_id)
			except Submission.DoesNotExist:
				# only should happen if session was somehow destroyed
				return redirect('home')
			
			form = DetailsForm(request.POST, instance=submission)
			if not form.is_valid():
				form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="details")
				context['form'] = form
				context['submission'] = submission
				context['step'] = 'steps/details.djt'
			else:
				# all done
				submission = form.save()
				submission.complete = True
				submission.save()
				context['submission'] = submission
				context['step'] = 'steps/complete.djt'
	else:
		# major dog balls
		messages.error(request, 'Logic Error');
		
	
	# progress bar
	import uuid
	context["uuid"] = uuid.uuid1()
	
	
	response = render_to_response(request, 'home.djt', context)
	response.set_cookie('X-Progress-ID', value=context["uuid"])
	
	return response
开发者ID:UCF,项目名称:Photo-Submissions,代码行数:89,代码来源:views.py


注:本文中的forms.UploadForm.fields['step']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。