本文整理汇总了Python中forms.AddTaskForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python AddTaskForm.save方法的具体用法?Python AddTaskForm.save怎么用?Python AddTaskForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.AddTaskForm
的用法示例。
在下文中一共展示了AddTaskForm.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import save [as 别名]
def add_task(request):
if request.method == 'POST':
form = AddTaskForm(data=request.POST)
if form.is_valid():
new_task = form.save(commit=False)
new_task.author = request.user
new_task.save()
return HttpResponseRedirect(new_task.get_absolute_url())
else:
form = AddTaskForm()
return render_to_response('timetracker/add_task.html',
{'form': form},
context_instance = RequestContext(request))
示例2: addtask
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import save [as 别名]
def addtask(request):
form = AddTaskForm(request.POST)
if request.user.is_authenticated():
if form.is_valid():
list = request.user.list_set.filter(listname=form.cleaned_data['list'])
if not list:
return HttpResponse("list name not found", status=400)
newtask = form.save()
return HttpResponse(json.dumps([]))
else:
return HttpResponse("form validation failed" + str(form.errors), status=400)
else:
return HttpResponse("Url is only available to logged in users", status=401)
示例3: tasks
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import save [as 别名]
def tasks(request, project_pk=None):
completed_task_list = Task.objects.for_user(request.user).filter(completed=True).order_by('-completion_date')
pending_task_list = Task.objects.for_user(request.user).filter(completed=False)
project_list = Project.objects.for_user(request.user).filter(completed=False)
if not project_pk and 'tasks_latest_project_pk' in request.session:
#print reverse('view-tasks', int(request.session['tasks_latest_project_pk']))
return HttpResponseRedirect("/tasks/%s/" % request.session['tasks_latest_project_pk'])
elif project_pk == 'all':
project_pk = None
if project_pk:
project = get_object_or_404(Project, pk=project_pk)
completed_task_list = completed_task_list.filter(project=project)
pending_task_list = pending_task_list.filter(project=project)
initial = {'project': project.pk}
request.session['tasks_latest_project_pk'] = project.pk
else:
project = None
initial = {}
TaskListFormSet = modelformset_factory(Task, fields=('completed',), extra=0)
if request.POST and 'task_list-INITIAL_FORMS' in request.POST:
task_list_formset = TaskListFormSet(request.POST, queryset=pending_task_list, prefix='task_list')
if task_list_formset.is_valid():
task_list_formset.save()
return HttpResponseRedirect(request.path_info)
else:
task_list_formset = TaskListFormSet(queryset=pending_task_list, prefix='task_list')
if request.POST and 'addtask-task' in request.POST:
task_form = AddTaskForm(request.POST, prefix='addtask')
if task_form.is_valid():
task = task_form.save()
return HttpResponseRedirect(request.path_info)
else:
task_form = AddTaskForm(prefix='addtask', initial=initial)
data = {
'project': project,
'completed_task_list': completed_task_list,
'project_list': project_list,
'task_form': task_form,
'task_list_formset': task_list_formset,
}
return render_to_response('projectmanager/tasks.html', data)