Beispiel #1
0
	def create_release_form(modeladmin, request, queryset):
		images = dict()
		for image in queryset:
			if images.get(image.submitter_name, None) is None:
				images[image.submitter_name] = list()
			
			images[image.submitter_name].append(image)
		return render_to_response(request, 'release_form.djt', {
			'images' : images,
		})
Beispiel #2
0
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