示例#1
0
def save_video(request,metastory_id,story_id,multimedia_id=None):
	if request.method == 'POST':
		metastory= get_object_or_404(MetaStory, pk=metastory_id)
		story = get_object_or_404(Story, pk=story_id, metastory=metastory)

		if not multimedia_id:
			multimedia = Video(created_by = request.user, story=story, created_at = datetime.now())
			multimedia_title = 'New Video'
			multimedia_url = reverse('video_new', args=[metastory_id,story_id])
			form_url = reverse('video_create', args=[metastory_id,story_id])
		else:	 
			multimedia = get_object_or_404(Video, pk=multimedia_id, story=story)
			multimedia_title = multimedia
			multimedia_url = reverse('video_edit', args=[metastory_id,story_id,multimedia.id])
			form_url = reverse('video_update', args=[metastory_id,story_id,multimedia.id])

		multimedia.updated_by = request.user
		multimedia.updated_at = datetime.now()
		form = VideoForm(request.POST, request.FILES,instance=multimedia)

		if form.is_valid():
			form.save()
			request.user.message_set.create(message="1|Your video asset was saved successfully.")

			multimedia.authors = request.POST.getlist('authors')
			
			if request.POST.get("geo_tag_lat",None) is not None:
				point = Geotag(tagged_obj=multimedia,point='SRID=4326;POINT ('+request.POST.get("geo_tag_lon")+' '+request.POST.get("geo_tag_lat")+')' )
				multimedia._remove_geotag()
				point.save()
			
			stags = ''
			for tag in Tag.objects.all():
				if request.POST.__contains__('tag_%d' % tag.id):
					stags += ' '+tag.name
			multimedia._set_tags(stags)
			
			return HttpResponseRedirect( reverse('video_edit', args=[metastory_id,story_id,multimedia.id]) )
		else:
			request.user.message_set.create(message="0|An error has occured.")
			members = metastory.get_members()
			authors = []
			
			inherited_tags = []
			inherited_tag_ids = []
			for mtag in metastory._get_tags():
				inherited_tags.append(mtag)
				inherited_tag_ids.append(mtag.id)
			for stag in story._get_tags():
				inherited_tags.append(stag)
				inherited_tag_ids.append(stag.id)
			tags = Tag.objects.exclude(id__in=inherited_tag_ids)
			used_tags = multimedia._get_tags()

			breadcrumb = [ {'title':metastory,'url':reverse('metastory_edit', args=[metastory_id])} , {'title':story,'url':reverse('story_edit', args=[metastory_id,story_id])} , {'title':multimedia_title,'url':multimedia_url} ]
			return render_to_response("multimedia/video.html", {'breadcrumb':breadcrumb,'form':form,'image':multimedia,'authors':authors,'inherited_tags':inherited_tags,'tags':tags,'used_tags':used_tags,'newsrooms_members':members,'form_url':form_url}, context_instance=RequestContext(request))
		
	else:
		return HttpResponseRedirect( settings.LOGIN_REDIRECT_URL )
示例#2
0
def save_photo(request,metastory_id,story_id,multimedia_id=None):
	if request.method == 'POST':
		metastory= get_object_or_404(MetaStory, pk=metastory_id)
		story = get_object_or_404(Story, pk=story_id, metastory=metastory)
		flickr_outlet = Outlet.objects.get(name='Flickr')
		saveSocial = False
		form = PhotoForm()
		upload_form = ImageForm(request.POST, request.FILES)
		if not multimedia_id:
			if upload_form.is_valid():
				multimedia = Photo(created_by = request.user, story=story, created_at = datetime.now())
				image = upload_form.save()
				
				multimedia.updated_by = request.user
				multimedia.updated_at = datetime.now()
				
				multimedia.title = image.image.name
				
				multimedia.summary = image.image.name
				try:
					multimedia.summary = image.MinimalEXIF().imageDescription()
				except:
					multimedia.summary = image.image.name
				
				if image.EXIF().has_key("EXIF DateTimeOriginal"):
					dt = datetime.strptime(str(image.MinimalEXIF().dateTimeOriginal()), '%Y:%m:%d %H:%M:%S').timetuple()
					multimedia.date_taken = datetime(*dt[0:6])
				
				multimedia.image = image
				multimedia.save()
				
				# save flickr info
				saveSocial = True
				
				form = PhotoForm(instance=multimedia)
			else:
				emsg = ''
				for value in upload_form.errors:
					emsg +=' '+value+' '+str(upload_form.errors[value])
				request.user.message_set.create(message="0|A file is required for upload."+emsg)
				return HttpResponseRedirect( reverse('photo_new', args=[metastory_id,story_id]) )
		else:	 
			multimedia = get_object_or_404(Photo, pk=multimedia_id, story=story)
			image_url = multimedia.image.image.name
			multimedia.updated_by = request.user
			multimedia.updated_at = datetime.now()
			multimedia.authors = request.POST.getlist('authors')
			form = PhotoForm(request.POST,instance=multimedia)

			if form.is_valid():
				form.save()
				request.user.message_set.create(message="1|Your photo asset was saved successfully.")
				
				# save flickr info
				saveSocial = True
				
				
				if request.POST.get("geo_tag_lat",None) is not None:
					point = Geotag(tagged_obj=multimedia,point='SRID=4326;POINT ('+request.POST.get("geo_tag_lon")+' '+request.POST.get("geo_tag_lat")+')' )
					multimedia._remove_geotag()
					point.save()
				
				stags = ''
				for tag in Tag.objects.all():
					if request.POST.__contains__('tag_%d' % tag.id):
						stags += ' '+tag.name
				multimedia._set_tags(stags)
				
			else:
				request.user.message_set.create(message="0|An error has occured.")
		
		flickr_payload = {}
		if saveSocial:
			ctype = ContentType.objects.get_for_model(multimedia)
			# first check to see if there is already an instance
			try:
				flickr_payload = Payload.objects.get(outlet=flickr_outlet,object_id=multimedia.id,content_type=ctype)
			except Payload.DoesNotExist:
				flickr_payload = Payload(outlet=flickr_outlet, object_id=multimedia.id,content_type=ctype, created_by=request.user,created_at=datetime.now())
			
			flickr_payload.updated_by=request.user
			flickr_payload.updated_at=datetime.now()
			flickr_payload.blurb = request.POST.get('flickr_description')
			
			if request.POST.get('flickr_placement_url') is not None:
				flickr_payload.placement_url = request.POST.get('flickr_placement_url')
				flickr_payload.placed_at = datetime.now()
				flickr_payload.placed_by = request.user
			
			flickr_payload.save()
		
		authors = multimedia.authors.all()
		
		geotag = multimedia._get_geotag()
		
		inherited_tags = []
		inherited_tag_ids = []
		for newsroom in metastory.newsrooms.all():
			for tag in newsroom.get_tags():
				inherited_tags.append(tag)
				inherited_tag_ids.append(tag.id)
		for mtag in metastory._get_tags():
			inherited_tags.append(mtag)
			inherited_tag_ids.append(mtag.id)
		for stag in story._get_tags():
			inherited_tags.append(stag)
			inherited_tag_ids.append(stag.id)
		tags = Tag.objects.exclude(id__in=inherited_tag_ids)	
		used_tags = multimedia._get_tags()

		members = metastory.get_members()
		breadcrumb = [ {'title':metastory,'url':reverse('metastory_edit', args=[metastory_id])} , {'title':story,'url':reverse('story_edit', args=[metastory_id,story_id])} , {'title':multimedia,'url':reverse('photo_edit', args=[metastory_id,story_id,multimedia.id])} ]
		return render_to_response("multimedia/photo.html", {'breadcrumb':breadcrumb,'form':form,'image':multimedia,'upload_form':upload_form,'authors':authors,'inherited_tags':inherited_tags,'tags':tags,'used_tags':used_tags,'newsrooms_members':members,'form_url':reverse('photo_update', args=[metastory_id,story_id,multimedia.id]),'upload_form_url':'','flickr_payload':flickr_payload,'geotag':geotag}, context_instance=RequestContext(request))
	else:
		return HttpResponseRedirect( settings.LOGIN_REDIRECT_URL )