def restore(request): if request.method == 'POST': if 'RestoreProject' in request.POST: form = CreateProjectForm(request.POST) if form.is_valid(): token = form.cleaned_data['token'] host = "localhost" project = form.cleaned_data['project'] dataset = form.cleaned_data['dataset'] datatype = form.cleaned_data['datatype'] dataurl = "http://openconnecto.me/ocp" readonly = form.cleaned_data['readonly'] exceptions = form.cleaned_data['exceptions'] nocreate = 0 resolution = form.cleaned_data['resolution'] openid = request.user.username print "Creating a project with:" # print token, host, project, dataset, dataurl,readonly, exceptions, openid # Get database info pd = ocpcaproj.OCPCAProjectsDB() pd.newOCPCAProj ( token, openid, host, project, datatype, dataset, dataurl, readonly, exceptions , nocreate ,resolution) bkupfile = request.POST.get('backupfile') path = '/data/scratch/ocpbackup/'+ request.user.username + '/' + bkupfile if os.path.exists(path): print "File exists" proj= pd.loadProject(token) db=proj.getDBName() user ="******" password ="******" proc = subprocess.Popen(["mysql", "--user=%s" % user, "--password=%s" % password, db],stdin=subprocess.PIPE,stdout=subprocess.PIPE) proc.communicate(file(path).read()) messages.success(request, 'Sucessfully restored database '+ db) return redirect(profile) else: #Invalid Form context = {'form': form} print form.errors return render_to_response('profile.html',context,context_instance=RequestContext(request)) else: #Invalid post - redirect to profile for now return redirect(profile) else: #GET DATA randtoken = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(64)) form = CreateProjectForm(initial={'token': randtoken}) path = '/data/scratch/ocpbackup/'+ request.user.username if os.path.exists(path): file_list =os.listdir(path) else: file_list={} context = Context({'form': form, 'flist': file_list}) return render_to_response('restoreproject.html',context,context_instance=RequestContext(request))
def create_project(request): template_name = 'create_project.html' if(request.method=="POST"): organization=request.user.organization form = CreateProjectForm(request.POST,organization=organization) if(form.is_valid()): slug = slugify(request.POST['name']) project_obj = Project.objects.create(name=request.POST['name'],slug=slug,description=request.POST['description'],modified_date=timezone.now(),organization=organization) project_id = project_obj.id json_data = {'error':False,'errors':form.errors, 'project_id': project_id} return HttpResponse(json.dumps(json_data), content_type="application/json") else: return HttpResponse(json.dumps({'error':True,'errors':form.errors}), content_type="application/json") return render(request,template_name)
def createproject(request): if request.method == 'POST': if 'CreateProject' in request.POST: form = CreateProjectForm(request.POST) if form.is_valid(): token = form.cleaned_data['token'] host = form.cleaned_data['host'] description = form.cleaned_data['description'] project = form.cleaned_data['project'] dataset = form.cleaned_data['dataset'] datatype = form.cleaned_data['datatype'] kvengine=form.cleaned_data['kvengine'] kvserver=form.cleaned_data['kvserver'] overlayproject=form.cleaned_data['overlayproject'] nocreateoption = request.POST.get('nocreate') if nocreateoption =="on": nocreate = 1 else: nocreate = 0 dataurl = "http://openconnecto.me/ocp" readonly = form.cleaned_data['readonly'] exceptions = form.cleaned_data['exceptions'] openid = request.user.username resolution =form.cleaned_data['resolution'] public =form.cleaned_data['public'] propogate =form.cleaned_data['propogate'] print "Creating a project with:" print token, project, dataset, dataurl,readonly, exceptions, openid , resolution # Get database info try: pd = ocpcaproj.OCPCAProjectsDB() pd.newOCPCAProj ( token, openid, host, project, datatype, dataset, dataurl, readonly, exceptions , nocreate, int(resolution), int(public),kvserver,kvengine ,propogate) #pd.insertTokenDescription ( token, description ) return redirect(profile) except OCPCAError, e: messages.error(request, e.value) return redirect(profile) else: #Invalid Form context = {'form': form} print form.errors return render_to_response('createproject.html',context,context_instance=RequestContext(request)) else: #default return redirect(profile)
def create_new_project(request): if request.method == 'POST': form = CreateProjectForm(request.POST) if form.is_valid(): form.save() messages.success(request, 'New project created successfully!') return HttpResponseRedirect('project_view_all_projects') else: messages.error(request, 'New project information contains errors!') return HttpResponse("Sorry, project could not be created") else: form = CreateProjectForm(initial={ 'created_by' : request.user.username, 'created_on' : time.strftime("%Y-%m-%d", time.gmtime()) }) user = request.user.username return TemplateResponse(request, 'project/create_new_project.html', { 'form': form, })
def project_details(request,slug): project = Project.objects.get(slug=slug) dictionary = {'project':project} template_name = 'Project-Project_Details.html' if(request.method=='POST'): organization=request.user.organization form = CreateProjectForm(request.POST,organization=organization) if(form.is_valid()): slug = slugify(request.POST['name']) project = Project.objects.get(slug=request.POST['oldname'],organization=organization) project.name=request.POST['name'] project.slug = slug project.modified_date = timezone.now() project.save() return HttpResponse(json.dumps({'error':False,'slug':slug}), content_type="application/json") else: return HttpResponse(json.dumps({'error':True,'errors':form.errors}), content_type="application/json") return render(request, template_name, dictionary)
def create_project(request): """View to create a new project. In the past I just linked to the page in the admin, but that doesn't automatically create users and admins for you. And it may be a pain to create project memberships manually. Perhaps the Django admin is customizable enough to fix this, but for now I'll just code it myself. At least this way I can make sure no one (but me) makes any major errors and destroys the site First check if the user is a superuser...""" if not request.user.is_superuser: return handle_privilege( request, "Only the site administrator can create a new project!", '/') if request.method == 'POST': form = CreateProjectForm(request.POST) if form.is_valid(): newproject = CollabProject() newproject = form.save(commit=False) newproject.start_date = datetime.date.today() newproject.save() form.save_m2m() for admin in form.cleaned_data["admins"]: p = ProjectMembership(person=admin, project=newproject, is_admin=True) p.save() return handle_privilege( request, 'The collaboration group "' + newproject.name + '" has been created!', reverse('project_summary', args=[newproject.slug])) else: form = CreateProjectForm() return render_to_response('project/create_project.html', {'form': form}, context_instance=RequestContext(request))