当前位置: 首页>>代码示例>>Python>>正文


Python TASClient.create_project方法代码示例

本文整理汇总了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})
开发者ID:,项目名称:,代码行数:70,代码来源:


注:本文中的pytas.http.TASClient.create_project方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。