Exemplo n.º 1
0
def file_handler_helper(post, uploadedfile):
	f = Attachment()
	# Save first to generate pk for random file system
	f.save()
	f.uploader = User.objects.get(pk=40) 	# Hardcoded for now
	f.attachment = uploadedfile
	if post.get('description'):
		f.description = post['description']
	f.save()
Exemplo n.º 2
0
def file_handler_helper(uploadedfile, description):
	f = Attachment()
	# Save first to generate pk for random file system
	f.save()
	f.uploader = User.objects.get(pk=40) 	# Hardcoded for now
	f.attachment = uploadedfile
	if description:
		f.description = description
	f.save()
	return f
Exemplo n.º 3
0
def create_movement(request):
	if request.method == 'POST':
		form = MovementForm(request.POST, request.FILES)
		if form.is_valid():
			clean_form = form.cleaned_data
			# Hardcoded user for now
			uploader = User.objects.get(pk=40)

			# Get and create attachment if possible
			try:
				attach = clean_form['attachment']
				attachment = Attachment()
				attachment.save()
				attachment.attachment = attach
				attachment.uploader = uploader
				attachment.description = clean_form.get('description')
				attachment.save()
			except KeyError:
				attachment = None

			# Handle tags
			tags = tag_handler(clean_form['tags'])

			# Handle objects
			piece = object_handler(Piece, clean_form['piece'])
			corpus = object_handler(Corpus, clean_form.get('corpus'))
			composer = composer_handler(clean_form.get('composer'))

			# Create movement
			movement = Movement(title=clean_form['title'],
							composer=composer,
							corpus=corpus,
							piece=piece,
							date_of_composition=clean_form.get('date_of_composition'),
							number_of_voices=clean_form.get('number_of_voices'),
							comment=clean_form.get('comment'),
							attachment=attachment,
							tags=tags,
							uploader=uploader )
			movement.save()
	else:
		form = MovementForm(initial={'title':'Movement title', 
									'composer': 'Composer', 
									'corpus': 'Corpus',
									'piece': 'Piece',
									'date_of_composition':'date of composition',
									'comment': 'Add a comment...',
									'tags': 'Comma-separated list of tags',
									'description':'Description of movement file...'})
	return render(request, 'forms/movement.html', {'form':form})