本文整理汇总了Python中pytas.http.TASClient.create_allocation方法的典型用法代码示例。如果您正苦于以下问题:Python TASClient.create_allocation方法的具体用法?Python TASClient.create_allocation怎么用?Python TASClient.create_allocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytas.http.TASClient
的用法示例。
在下文中一共展示了TASClient.create_allocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_allocation
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import create_allocation [as 别名]
def create_allocation(request, project_id, allocation_id=-1):
tas = TASClient()
user = tas.get_user(username=request.user)
if user['piEligibility'] != 'Eligible':
messages.error(request,
'Only PI Eligible users can request allocations. 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'))
project = Project(project_id)
allocation = None
if allocation_id > 0:
for a in project.allocations:
if a.id == int(allocation_id):
allocation = a
# goofiness that we should clean up later; requires data cleansing
abstract = project.description
if '--- Supplemental details ---' in abstract:
additional = abstract.split('\n\n--- Supplemental details ---\n\n')
abstract = additional[0]
additional = additional[1].split('\n\n--- Funding source(s) ---\n\n')
justification = additional[0]
if len(additional) > 1:
funding_source = additional[1]
else:
funding_source = ''
elif allocation:
justification = allocation.justification
if '--- Funding source(s) ---' in justification:
parts = justification.split('\n\n--- Funding source(s) ---\n\n')
justification = parts[0]
funding_source = parts[1]
else:
funding_source = ''
else:
justification = ''
funding_source = ''
if request.POST:
form = AllocationCreateForm(request.POST,
initial={'description': abstract,
'supplemental_details': justification,
'funding_source': funding_source})
if form.is_valid():
allocation = form.cleaned_data.copy()
allocation['computeRequested'] = 20000
# Also update the project
project.description = allocation.pop('description', None)
supplemental_details = allocation.pop('supplemental_details', None)
logger.error(supplemental_details)
funding_source = allocation.pop('funding_source', None)
#if supplemental_details == None:
# raise forms.ValidationError("Justifcation is required")
# This is required
if not supplemental_details:
supplemental_details = '(none)'
logger.error(supplemental_details)
if funding_source:
allocation['justification'] = '%s\n\n--- Funding source(s) ---\n\n%s' % (
supplemental_details, funding_source)
else:
allocation['justification'] = supplemental_details
allocation['projectId'] = project_id
allocation['requestorId'] = tas.get_user(username=request.user)['id']
allocation['resourceId'] = '39'
if allocation_id > 0:
allocation['id'] = allocation_id
try:
logger.info('Submitting allocation request for project %s: %s' %
(project.id, allocation))
updated_project = tas.edit_project(project.as_dict())
tas.create_allocation(allocation)
messages.success(request, 'Your allocation request has been submitted!')
return HttpResponseRedirect(
reverse('projects:view_project', args=[updated_project['id']]))
except:
logger.exception('Error creating allocation')
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 = AllocationCreateForm(initial={'description': abstract,
'supplemental_details': justification,
'funding_source': funding_source})
#.........这里部分代码省略.........