def create_project(request): context = {} if request.method == 'POST': form = ProjectCreateForm(request.POST) if form.is_valid(): project = form.save(commit = False) project.creator = request.user project.save() project.allowed_users.add(request.user) return redirect('/projects/') else: context['form'] = form return create_object(request, form_class = ProjectCreateForm, extra_context = context)
def create_project(request): tas = TASClient() user = tas.get_user(username=request.user) if user['piEligibility'] != 'Eligible': messages.error(request, 'Only PI Eligible users can create new projects. ' 'If you would like to request PI Eligibility, please ' '<a href="/user/profile/edit/">submit a PI Eligibility ' 'request</a>.') return HttpResponseRedirect(reverse('projects:user_projects')) if request.POST: form = ProjectCreateForm(request.POST) if form.is_valid(): # title, description, typeId, fieldId project = form.cleaned_data.copy() project.pop('accept_project_terms', None) # pi pi_user = tas.get_user(username=request.user) project['piId'] = pi_user['id'] # allocations allocation = { 'resourceId': 39, 'requestorId': pi_user['id'], 'computeRequested': 20000, } supplemental_details = project.pop('supplemental_details', None) funding_source = project.pop('funding_source', None) #if supplemental_details == None: # raise forms.ValidationError("Justifcation is required") if not supplemental_details: supplemental_details = '(none)' if funding_source: allocation['justification'] = '%s\n\n--- Funding source(s) ---\n\n%s' % ( supplemental_details, funding_source) else: allocation['justification'] = supplemental_details project['allocations'] = [allocation] # startup project['typeId'] = 2 # source project['source'] = 'Chameleon' try: created_project = tas.create_project(project) messages.success(request, 'Your project has been created!') return HttpResponseRedirect( reverse('projects:view_project', args=[created_project['id']])) except: logger.exception('Error creating project') form.add_error('__all__', 'An unexpected error occurred. Please try again') else: form.add_error('__all__', 'There were errors processing your request. ' 'Please see below for details.') else: form = ProjectCreateForm() return render(request, 'projects/create_project.html', {'form': form})
def create_project(request): tas = TASClient() user = tas.get_user(username=request.user) if user['piEligibility'] != 'Eligible': messages.error( request, 'Only PI Eligible users can create new projects. ' 'If you would like to request PI Eligibility, please ' '<a href="/user/profile/edit/">submit a PI Eligibility ' 'request</a>.') return HttpResponseRedirect(reverse('projects:user_projects')) if request.POST: form = ProjectCreateForm(request.POST) if form.is_valid(): # title, description, typeId, fieldId project = form.cleaned_data.copy() project.pop('accept_project_terms', None) # pi pi_user = tas.get_user(username=request.user) project['piId'] = pi_user['id'] # allocations allocation = { 'resourceId': 39, 'requestorId': pi_user['id'], 'computeRequested': 20000, } supplemental_details = project.pop('supplemental_details', None) funding_source = project.pop('funding_source', None) #if supplemental_details == None: # raise forms.ValidationError("Justifcation is required") if not supplemental_details: supplemental_details = '(none)' if funding_source: allocation[ 'justification'] = '%s\n\n--- Funding source(s) ---\n\n%s' % ( supplemental_details, funding_source) else: allocation['justification'] = supplemental_details project['allocations'] = [allocation] # startup project['typeId'] = 2 # source project['source'] = 'Chameleon' try: created_project = tas.create_project(project) messages.success(request, 'Your project has been created!') return HttpResponseRedirect( reverse('projects:view_project', args=[created_project['id']])) except: logger.exception('Error creating project') form.add_error( '__all__', 'An unexpected error occurred. Please try again') else: form.add_error( '__all__', 'There were errors processing your request. ' 'Please see below for details.') else: form = ProjectCreateForm() return render(request, 'projects/create_project.html', {'form': form})