Ejemplo n.º 1
0
def newProjectAjax(request):
	try:
		#get information from the Ajax post data
		r_projectType = request.POST.get('projectType')
		r_projectName= request.POST.get('projectName')
		r_projectDescription = request.POST.get('projectDescription')
		user = request.user
		newProject = Project(project_name=r_projectName, project_type=r_projectType, description=r_projectDescription)
		newProject.save()
		member = Member(project= newProject, user = user, mem_type = "Owner")
		member.save()
		root = Directory(parent = None, name = "Root", project_id = newProject, level = '0')
		root.save()
		newfile = File(parent = root, data= "", project_id = newProject.project_id, file_name = "readme", file_type = "txt")
		newfile.save()
		return JsonResponse({'response':'success', 'projectid': newProject.project_id})
	except:
		pass
	#if here then somthing went wrong	
	return JsonResponse({'response':'fail'})
Ejemplo n.º 2
0
def newDirAjax(request):
	try:
		r_name = request.POST.get('name')
		r_project_id = request.POST.get('projectid')
		r_parent = request.POST.get('parent')
		print("got request")
		try:
			if Directory.objects.get(project_id = project, name = r_name):
				print("that file exists")
				return JsonResponse({'response':'fail','message' :'A file with that name already exists.'})
		except:
			pass
		print("after try")

		pdir = Directory.objects.get(project_id = r_project_id, name = r_parent)
		proj = get_object_or_404(Project, project_id = r_project_id)
		print("got parent")
		newDir = Directory(parent = pdir, name = r_name, project_id =proj, level = 0)
		print("newdir")
		newDir.save()
		return JsonResponse({'response':'success'})
	except:
		pass
	return JsonResponse({'response':'fail'})
Ejemplo n.º 3
0
from codeapp.models import Project, Member, File, Directory
#
p = Project(project_name = "new project1", description = "new p", )
p.save()
r = Directory(parent = None, name = "Root", project_id = p, level = 0)
r.save()
d1= Directory(parent = r, name = "D1", project_id = p, level = 1)
d1.save()
d2= Directory(parent = r, name = "D2", project_id = p, level = 1)
d2.save()
d1a= Directory(parent = d1, name = "D1a", project_id = p, level = 2)
d1a.save()
f = File(parent = d1a, data = '', file_name = 'test', file_type = 'txt', share_link='ffsafsa')
f.save()
f2= File(parent = d1, data = '', file_name = 'test2', file_type = 'txt', share_link='ffsafsa')
f2.save()
root = Directory.objects.get(project_id= p, name="Root")
rootdirs = root.children.all()


# def getDirectoryTree(project):
# 	tree = {}
# 	root = Directory.objects.get(project_id= project, name="Root")
# 	rootdirs = root.children.all()
# 	for d0 in rootdirs: # lvl 0 directory
# 		tree['lvl0dirs'] = rootdirs
# 		for d1 in d0.children.all(): # lvl 1 directory
# 			tree[d0.name+'_dirs'] = d0.children.all()
# 			files = File.objects.filter(parent = d1)
# 			if files:
# 				tree[d1.name+'_files'] = files