Esempio n. 1
0
def media_description(request, mid):
	media_ob = MediaUpload.objects.get(id= mid)
	path = os.path.join(MEDIA_ROOT, media_ob.media.name)
	analyzer = Analyzer()
	file_descr = analyzer.analyze_file(path)
	data = {}
	data['hash']=media_ob.hash
	data['assets'] = []
	if file_descr.assets:
		for x in file_descr.assets:
			asset_data = {}
			asset_data['subname'] = x.asset.subname
			asset_data['mimetype'] = x.asset.mimetype
			asset_data['dependencies'] = []
			if x.dependencies:
				for y in x.dependencies:
					dep_data = {}
					dep_data['subname'] = y.subname
					dep_data['mimetype'] = y.mimetype
					asset_data['dependencies'].append(dep_data)
			asset_data['metadata'] = []
			if x.metadata:
				for key, value in x.metadata.items():
					metadata_data = {}
					type, val = get_metadatavalue_type(value)
					print(val)
					metadata_data['key'] = key
					metadata_data['type'] = type
					metadata_data['val'] = val
					asset_data['metadata'].append(metadata_data)
			data['assets'].append(asset_data)

	return JsonResponse(data)
Esempio n. 2
0
def capabilities(request):
    from damn_at import Analyzer
    analyzer = Analyzer()
    data = {}
    data['mimetypes'] = analyzer.get_supported_mimetypes()
    data['capabilities'] = analyzer.get_supported_metadata()
            
    return HttpResponse(json.dumps(data, indent=4), content_type="application/json")        
Esempio n. 3
0
    def search(args):
        from damn_at import Analyzer
        from damn_at.utilities import get_metadatavalue_fieldname
        m = Analyzer().get_supported_metadata()
        ret = {'aggs': {},
                'query' : {'match_all' : {}},
                'from' : 3, 'size' : 1,}
        for mime, metas in m.items():
            for meta, type in metas:
                field_name = get_metadatavalue_fieldname(type)
                ret['aggs'][meta] = { 'terms' : {'field' : 'metadata.'+meta+'.'+field_name} }

        print json.dumps(ret, indent=2)
Esempio n. 4
0
    def post(self, request, project_name):
        project = get_object_or_404(Project, pk=project_name)


        if ('path_id' not in request.POST and 'path' not in request.POST) or 'file' not in request.FILES:
            return Response('Malformed request, needs to contain filename and file fields', status=400)

        if 'path' in request.POST:
            path = Path.objects.get_or_create(project, request.POST['path'])
        else:
            path_id = request.POST['path_id']
            path = get_object_or_404(Path, project=project, pk=path_id)

        file_obj = request.FILES['file']
        filename = file_obj.name

        #Write file to temporary location
        with tempfile.NamedTemporaryFile(delete=False) as destination:
            for chunk in file_obj.chunks():
                destination.write(chunk)
            destination.flush()

            hash = calculate_hash_for_file(destination.name)

            files_dir = '/tmp/damn/files'
            if not os.path.exists(files_dir):
                os.makedirs(files_dir)
            new_path = os.path.join(files_dir, hash)
            os.rename(destination.name, new_path)

            analyzer = Analyzer()
            try:
                file_descr = analyzer.analyze_file(new_path)
            except AnalyzerException as ae:
                file_descr = FileDescription(file=FileId())

            file_descr.file.hash = hash

            file_ref = FileReference.objects.update_or_create(request.user, project, path, filename, file_descr)

            return Response(serializers.FileReferenceSerializer(file_ref, context={'request': request}).data)
Esempio n. 5
0
def media_view(request, mid):
	media_ob = MediaUpload.objects.get(id= mid)
	if request.method=='POST':
		comment = UiComment()
		comment.author = request.user
		comment.content_type = ContentType.objects.get_for_model(media_ob)
		comment.object_pk = mid
		comment.comment = request.POST['comm-text']
		try:
			comment.annotation = str(request.POST['json-data'])
		except:
			comment.annotation = None
		comment.save()
		action.send(request.user, verb='commented', action_object=comment, target=media_ob)
		return HttpResponseRedirect('.')

	path = os.path.join(MEDIA_ROOT, media_ob.media.name)
	analyzer = Analyzer()
	file_descr = analyzer.analyze_file(path)
	mdesc = pretty_print_file_description(file_descr)
	comment_content_type = ContentType.objects.get_for_model(media_ob)
	comments = UiComment.objects.filter(content_type__pk=comment_content_type.id, object_pk=str(mid))
	
	# if media_ob.mimetype == 'image/jpeg':

	context = {
		'mdesc':mdesc,
		'file_descr':file_descr,
		'media_ob':media_ob,
		'comments':comments,
		'user':request.user,
	} 
	if 'video' in media_ob.mimetype:
		return render(request, 'media_video.html', context)
	elif 'image' in media_ob.mimetype:
		return render(request, 'media_image.html', context)
Esempio n. 6
0
def project_page(request, author_name, project_slug):
	user = request.user
	user_profile = Profile.objects.get(pk=user)
	user_membership = Membership.objects.filter(member=user)
	project_list=[]
	for x in user_membership:
		project_list.append(x.project)
	author_ob = User.objects.get(username = author_name)
	project_ob = Project.objects.filter(author = author_ob, slug = project_slug)[0]
	members_list = project_ob.members.all()
	project_media = MediaUpload.objects.filter(project=project_ob)
	roles = Role.objects.filter(project = project_ob)
	task_list = TaskUI.objects.filter(project=project_ob)
	relation_list = AssignedResource_Relation.objects.filter(project = project_ob)
	priority_list = Priority.objects.filter(project=project_ob)
	type_list = TaskType.objects.filter(project=project_ob)



	profile_list = []	
	for x in members_list:
		p = Profile.objects.get(pk = x)
		profile_list.append(p)
	context={
		'project_ob':project_ob,
		'profile_list':profile_list,
		'user_profile' : user_profile,
		'user' : user,
		'user_project_list':project_list,
		'project_media':project_media,
		'roles':roles,
		'members_list':members_list,
		'task_list':task_list,
		'relation_list':relation_list,
		'type_list':type_list,
		'priority_list':priority_list,
	}
	if request.method == 'POST':
		# for x in 
		if request.POST.get('update-role'):
			role = Role.objects.get(id = int(request.POST['id']))
			role.name = request.POST['name']
			role.save()
			return HttpResponseRedirect('.')

		elif request.POST.get('delete-role'):
			role = Role.objects.get(id = int(request.POST['id']))
			role.delete()
			return HttpResponseRedirect('.')

		elif request.POST.get('new-role'):
			role = Role()
			role.name = request.POST['name']
			role.project = project_ob
			role.save()
			return HttpResponseRedirect('.')
		
		elif request.POST.get('update-rel'):
			rel = AssignedResource_Relation.objects.get(id = int(request.POST['id']))
			rel.task = TaskUI.objects.get(id = int(request.POST['task']))
			rel.user = User.objects.get(id = int(request.POST['user']))
			rel.role = Role.objects.get(id = int(request.POST['role']))
			rel.effort = request.POST['effort'] 
			rel.save()
			return HttpResponseRedirect('.')

		elif request.POST.get('delete-rel'):
			rel = AssignedResource_Relation.objects.get(id = int(request.POST['id']))
			rel.delete()
			return HttpResponseRedirect('.')

		elif request.POST.get('new-rel'):
			rel = AssignedResource_Relation.objects.get(id = int(request.POST['id']))
			rel.task = TaskUI.objects.get(id = int(request.POST['task']))
			rel.user = User.objects.get(id = int(request.POST['user']))
			rel.role = Role.objects.get(id = int(request.POST['role']))
			rel.effort = request.POST['effort'] 
			rel.project = project_ob
			rel.save()
			return HttpResponseRedirect('.')
	
		elif request.POST.get('update-task'):	
			task = TaskUI.objects.get(id = int(request.POST['id']))
			task.name = request.POST['name']
			task.short_name = request.POST['short-name']
			task.level = request.POST['level']
			task.summary = request.POST['summary']
			task.description = request.POST['description']
			task.status = request.POST['status']
			task.priority = Priority.objects.get(id = int(request.POST['priority']))
			task.type = TaskType.objects.get(id = int(request.POST['type']))
			if request.POST.get('start-is-milestone'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('end-is-milestone'):
				task.end_is_milestone = True
			else:
				pass
			if request.POST.get('has-child'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('can-write'):
				task.start_is_milestone = True
			else:
				pass
			task.depends = request.POST['depends']
			task.save()
			return HttpResponseRedirect('.')

		elif request.POST.get('del-task'):	
			task = TaskUI.objects.get(id = int(request.POST['id']))
			task.delete()
			return HttpResponseRedirect('.')

		elif request.POST.get('update-task'):	
			task = TaskUI.objects.get(id = int(request.POST['id']))
			task.name = request.POST['name']
			task.short_name = request.POST['short-name']
			task.level = request.POST['level']
			task.summary = request.POST['summary']
			task.description = request.POST['description']
			task.status = request.POST['status']
			task.priority = Priority.objects.get(id = int(request.POST['priority']))
			task.type = TaskType.objects.get(id = int(request.POST['type']))
			if request.POST.get('start-is-milestone'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('end-is-milestone'):
				task.end_is_milestone = True
			else:
				pass
			if request.POST.get('has-child'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('can-write'):
				task.start_is_milestone = True
			else:
				pass
			task.depends = request.POST['depends']
			task.save()
			return HttpResponseRedirect('.')

		elif request.POST.get('del-task'):	
			task = TaskUI.objects.get(id = int(request.POST['id']))
			task.delete()
			return HttpResponseRedirect('.')

		elif request.POST.get('new-task'):	
			task = TaskUI()
			task.name = request.POST['name']
			task.short_name = request.POST['short-name']
			task.project = request.POST['project']
			task.author = request.POST['author']
			task.level = request.POST['level']
			task.summary = request.POST['summary']
			task.description = request.POST['description']
			task.status = request.POST['status']
			task.priority = Priority.objects.get(id = int(request.POST['priority']))
			task.type = TaskType.objects.get(id = int(request.POST['type']))
			task.project = project_ob
			task.author = request.user
			if request.POST.get('start-is-milestone'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('end-is-milestone'):
				task.end_is_milestone = True
			else:
				pass
			if request.POST.get('has-child'):
				task.start_is_milestone = True
			else:
				pass
			if request.POST.get('can-write'):
				task.start_is_milestone = True
			else:
				pass
			task.depends = request.POST['depends']
			task.save()
			return HttpResponseRedirect('.')

		# elif request.POST.get() 
			# for key in request.POST.iterkeys():
			# 	v
			# 	if key == 'new_role':
			# 		if request.POST[key] != "":
			# 			role = Role()
			# 			role.name = request.POST[key]
			# 			role.project = project_ob
			# 			role.save()
			# 		else:
			# 			pass
			# 	elif key == 'save_role':
			# 		pass
			# 	else:
			# 		role.name = request.POST[key]
			# 		role.save()
		
		# elif request.POST.get('save_relation'):
		# 	flag = 0
		# 	for key in request.POST.iterkeys():
		# 		if key in ['new_task','new_role','new_effort','new_user']:
		# 			if flag == 0:
		# 				if request.POST.get('add_new_relation'):	
		# 					flag = 1
		# 					rel = AssignedResource_Relation()
		# 					rel.project = project_ob
		# 					rel.task = TaskUI.objects.get(id = int(request.POST['new_task']))
		# 					rel.user = User.objects.get(id = int(request.POST['new_user']))
		# 					rel.role = Role.objects.get(id = int(request.POST['new_role']))
		# 					rel.effort = request.POST['new_effort'] 
		# 					action.send(rel.user, verb='assigned', action_object=rel.role, target=rel.task)
		# 					rel.save()
		# 				else:
		# 					pass
		# 		elif key == 'save_relaltion':
		# 			pass
		# 		else:
		# 			for rel in relation_list:
		# 				if str(rel.id) == key:
		# 					rel.task = TaskUI.objects.get(id = int(request.POST[key]))
		# 					rel.role = Role.objects.get(id = int(request.POST[key+'_role']))
		# 					rel.user = User.objects.get(id = int(request.POST[key+'_user']))
		# 					rel.effort = int(request.POST[key+'_effort'])
							# rel.save()

			# if request.POST.get('save_reelaltion'):
								# for x in roles:
			# 	try:
			# 		role = Role.objects.get(id = int(request.POST[x.id]))
			# 		role.name = 
			# 	role.	
		
		else:
			media_ob = MediaUpload.objects.create(project=project_ob)
			media_ob.media = request.FILES['file']
		# media_ob.project = project_ob
			media_ob.save()
			if media_ob.media.url:
				analyzer = Analyzer()
				path = os.path.join(MEDIA_ROOT, media_ob.media.name)
				media_ob.mimetype = mimetypes.guess_type(path, False)[0]
				file_descr = analyzer.analyze_file(path)
				print(file_descr)
				file_descr.hash = calculate_hash_for_file(path)
				media_ob.file_description = file_descr
				media_ob.hash = file_descr.hash
				media_ob.save()
				action.send(request.user, verb='uploaded', action_object=media_ob, target=project_ob)
				if 'video' in media_ob.mimetype:	
					transcdoer_path = MEDIA_ROOT
					transcoder = Transcoder(transcdoer_path)
					asset_name = get_asset_names_in_file_descr(file_descr)
					asset_name = asset_name[0]
					asset_id = find_asset_ids_in_file_descr(file_descr, asset_name)
					asset_id = asset_id[0]
					target_mimetype = transcoder.get_target_mimetype(media_ob.mimetype, 'image/jpeg')	
					height = file_descr.assets[0].metadata['height'].int_value
					width = file_descr.assets[0].metadata['width'].int_value
					print('height', height)
					print('height', width)					
					duration = file_descr.assets[0].metadata['duration'].string_value					
					# new_width = 200
					# new_height = 200*(height/width)
					try:
						time = duration.split(':')
						time = eval(time[0])*3600 + eval(time[1])*60 + eval(time[2])
					except:
						time = duration.split('.')
						time = eval(time[0])
					if time < 10:
						options = {'second':-1,'size':(width, height)}
					else:
						options = {'second':5,'size':(width, height)}
					get_image = transcoder.transcode(file_descr, asset_id, target_mimetype, **options)
					media_ob.resource_link = get_image[0]
					media_ob.save()				 

		return HttpResponse('done')
	else:
		return render(request, 'project_page.html', context)