本文整理汇总了Python中forms.TaskForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python TaskForm.save方法的具体用法?Python TaskForm.save怎么用?Python TaskForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TaskForm
的用法示例。
在下文中一共展示了TaskForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def add_task(request):
# Get the context from the request.
context = RequestContext(request)
projectid = int(request.GET.get('projectid', '0'))
context_dict = {}
if request.method == 'POST':
form = TaskForm(request.POST)
# Have we been provided with a valid form?
if form.is_valid():
# Save the new category to the database.
form.save(commit=True)
return HttpResponseRedirect('/project/view_tasks?projectid=' + str(projectid))
else:
# The supplied form contained errors - just print them to the terminal.
print form.errors
else:
# If the request was not a POST, display the form to enter details.
form = TaskForm()
context_dict["form"] = form
context_dict["projectid"] = projectid
# Bad form (or form details), no form supplied...
# Render the form with error messages (if any).
return render_to_response('webapp/add_requirement.html', context_dict, context)
示例2: post
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def post(self, request):
form = TaskForm(data=request.POST)
if not form.is_valid():
return self.get(request, form)
form.save()
return redirect('index')
示例3: task_create
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def task_create(request, id):
milestone = get_object_or_404(Milestone, pk=id)
if request.method == 'POST': # If the form has been submitted...
post = request.POST.copy()
post['milestone']=milestone.id
form = TaskForm(data=post) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
form.save()
# Process the data in form.cleaned_data
# ...
return redirect('/tasks') # Redirect after POST
else:
form = TaskForm(
milestone=milestone,
initial={
'milestone': milestone,
},
)
# An unbound form
#from django import forms
#form.depends_from = forms.ModelMultipleChoiceField(queryset=Task.objects.filter(milestone=milestone))
return render(request, 'task_create.html', {
'milestone': milestone,
'form': form,
})
示例4: update_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def update_task(request, id):
task = Tasks.objects.get(pk=id)
form = TaskForm(request.POST or None, instance=task)
if request.POST:
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
return render(request, 'create_task.html', {'form': form})
示例5: new_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def new_task(request):
if request.method == 'POST':
form = TaskForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = TaskForm()
return render(request, 'create_task.html', {'form': form})
示例6: get_task_list_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def get_task_list_task(request):
t_l_id = None
if request.method == 'POST':
form = TaskForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/new_task_list/')
else:
form = TaskForm()
return render(request, "tasks_add.html", { 'form': form , 't_l_id':t_l_id})
示例7: calendar
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def calendar(request):
if request.method == "POST":
c = Calendar.objects.all()[0]
form = TaskForm(request.POST, Task())
if form.is_valid():
form.save()
# create a new empty form
form = TaskForm()
else:
form = TaskForm()
return render_to_response("calendar.html", RequestContext(request, {"form": form}))
示例8: addtask
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def addtask(request):
if request.POST:
form = TaskForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Task added!')
return HttpResponseRedirect('/tasks/')
else:
form = TaskForm()
return render(request, 'addtask.html', locals())
示例9: post
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def post(self, request, task_id):
form = TaskForm(request.POST, instance=Task.objects.get(pk=task_id))
if form.is_valid():
form.save()
messages.add_message(request, messages.INFO, "Task updated!")
return redirect("/task/%s/" % task_id)
print form.errors
context = {'form': form}
return render(request, self.template_name, context)
示例10: task_form
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def task_form(request):
context = RequestContext(request)
if request.method == 'POST':
form = TaskForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/tasks/')
else:
print(form.errors)
else:
form = Task()
return render_to_response('tasks/index.html', {'form': form}, context)
示例11: edit_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def edit_task(request):
task = Task.objects.get(id=request.POST.get('id'))
copy = request.POST.copy()
copy['user'] = request.user.id
form = TaskForm(copy, instance=task)
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS,
'Task has been updated!')
else:
messages.add_message(request, messages.ERROR,
'Error: Task is not updated!')
return HttpResponseRedirect(reverse('task:tasks'))
示例12: edit_task
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def edit_task(request, t_id):
task = Task.objects.get(id=t_id)
# instance ={'title':task.title,'body':task.body,'priority':task.priority }
# form = EditTForm(initial={'title':task.title,'body':task.body,'priority':task.priority})
form = TaskForm(request.POST or None, instance= task)
# form = TaskForm(initial={'title':instance.title,'body':instance.body,'priority':instance.priority,'dead_line':instance.dead_line,'note':instance.note,'pub_date':instance.pub_date})
if form.is_valid():
# task.title=form.cleaned_data['title']
# task.body=form.cleaned_data['body']
# task.priority=form.cleaned_data['priority']
form.save()
return HttpResponseRedirect('/')
return render(request,"task_edit.html",{'form':form})
示例13: todo
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def todo(request):
context = RequestContext(request)
tasks = Task.objects.all
if request.method == 'POST':
form = TaskForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/todo/')
else:
print(form.errors)
else:
form = Task()
return render_to_response('tasks/TODO.html', {'tasks': tasks, 'form': form}, context)
示例14: tasks
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def tasks(request):
"""Lists tasks"""
if request.method == 'GET':
order = request.GET.get('o', 'last_updated_on')
results = Task.objects.filter(created_by=request.user).order_by(order)
# Put in Pagination
return render_to_response('tasks.html', {'tasks': results},
context_instance=RequestContext(request))
# post
task = TaskForm(request.POST)
if task.is_valid():
task.save()
return HttpResponseRedirect('/task/%d'%task.id)
return HttpResponse(status=400)
示例15: test_task_form
# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import save [as 别名]
def test_task_form(self):
data = {
"title": "Write some tests",
"day": "01/04/2005",
"start_time": 2,
"end_time": 2,
"user": self.alice.pk,
"project": self.project.pk,
"status": Project.ACTIVE,
"task_type": self.et.pk,
}
form = TaskForm(data)
self.assertFalse(form.is_valid())
data["start_time"] = 11
data["count"] = 3
form = TaskForm(data)
self.assert_(form.is_valid())
tt = TaskType.objects.create(title="why?")
task = form.save(commit=False)
task.task_type = tt
task.author = self.alice
task.save()
task.add_occurrences(
form.cleaned_data["start_time"], form.cleaned_data["end_time"], count=form.cleaned_data["count"]
)
self.assertEqual(Occurrence.objects.count(), 3)