本文整理汇总了Python中pytas.http.TASClient.create_project方法的典型用法代码示例。如果您正苦于以下问题:Python TASClient.create_project方法的具体用法?Python TASClient.create_project怎么用?Python TASClient.create_project使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytas.http.TASClient
的用法示例。
在下文中一共展示了TASClient.create_project方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_project
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import create_project [as 别名]
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})