本文整理汇总了Python中models.Project.set_user_from_request方法的典型用法代码示例。如果您正苦于以下问题:Python Project.set_user_from_request方法的具体用法?Python Project.set_user_from_request怎么用?Python Project.set_user_from_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Project
的用法示例。
在下文中一共展示了Project.set_user_from_request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project_add_typed
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import set_user_from_request [as 别名]
def project_add_typed(request, project_id, response_format='html'):
"""Project add to preselected parent project"""
parent_project = None
if project_id:
parent_project = get_object_or_404(Project, pk=project_id)
if not request.user.profile.has_permission(parent_project, mode='x'):
parent_project = None
if request.POST:
if 'cancel' not in request.POST:
project = Project()
form = ProjectForm(
request.user.profile, project_id, request.POST, instance=project)
if form.is_valid():
project = form.save()
project.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
else:
return HttpResponseRedirect(reverse('projects'))
else:
form = ProjectForm(request.user.profile, project_id)
context = _get_default_context(request)
context.update({'form': form, 'project': parent_project})
return render_to_response('projects/project_add_typed', context,
context_instance=RequestContext(request), response_format=response_format)
示例2: project_add
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import set_user_from_request [as 别名]
def project_add(request, response_format='html'):
"""New project form"""
if request.POST:
if 'cancel' not in request.POST:
project = Project()
form = ProjectForm(
request.user.profile, None, request.POST, instance=project)
if form.is_valid():
project = form.save()
project.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
else:
return HttpResponseRedirect(reverse('projects'))
else:
form = ProjectForm(request.user.profile, None)
context = _get_default_context(request)
context.update({'form': form})
return render_to_response('projects/project_add', context,
context_instance=RequestContext(request), response_format=response_format)