本文整理汇总了Python中forms.TaskForm类的典型用法代码示例。如果您正苦于以下问题:Python TaskForm类的具体用法?Python TaskForm怎么用?Python TaskForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: task_create
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,
})
示例2: add_task
def add_task(request):
from forms import TaskForm
form = TaskForm(request.POST)
scrapy_error = False
if form.is_valid():
data = form.cleaned_data['data']
print data
mail = data['address']
task_list = data['urls']
http = httplib2.Http()
data={'project':"dirbot","spider":"taobao"}
header={'Content-Type': 'application/x-www-form-urlencoded'}
for item in task_list:
Q = Queue(url=item,mail=mail)
Q.save()
try:
s,c = http.request("http://localhost:6800/schedule.json","POST",urlencode(data),headers=header)
except Exception:
c = {'status':'error','msg':'爬虫服务器连接失败'}
scrapy_error = True
else:
return HttpResponse(json.dumps({'status':'error','msg':form['data'].errors}))
if scrapy_error:
return HttpResponse(json.dumps(c,ensure_ascii=False))
return HttpResponse(c)
示例3: tasks
def tasks():
# imported our TaskForm class, instantiated an object from it,
#and sent it down to the template where forms is used.
form = TaskForm(request.form)
tasks = Task.query.all()
# for task in tasks:
# db.session.delete(task)
# db.session.commit()
if request.method == 'POST' and form.validate_on_submit():
flash('Created Async Task!')
#save numberOfSeconds in a session hash
session['numberOfSeconds'] = form.numberOfSeconds.data
time = int(session['numberOfSeconds'])
#START OF ASYNC SLEEP CALL#
t1 = start_sleep.delay(time)
session['TASK_ID'] = t1.id
#add new async task to database
new_task = Task(time = int(session['numberOfSeconds']),status= t1.ready(),key =session['TASK_ID'])
db.session.add(new_task)
db.session.commit()
return redirect(url_for('tasks'))
return render_template('tasks.html',
title = 'Amadeus Task',
form = form,
tasks = tasks)
示例4: create_task
def create_task(request):
if request.method == "POST":
f = TaskForm(request.POST)
if f.is_valid():
c = f.save(commit=False)
c.CreatedOn = timezone.now()
c.CreatedBy = request.user
c.LastUpdatedOn = timezone.now()
c.LastUpdatedBy = request.user
c.save()
messages.success(request, "Your Task was added")
return HttpResponseRedirect('/persons/all')
else:
f = TaskForm()
args = {}
args.update(csrf(request))
args['form'] = f
return render_to_response('create_task.html', args)
message.add_message(request, settings.DELETE_MESSAGE, "Your task was deleted successfully")
return HttpResponseRedirect('/persons/all' % person_id)
示例5: post
def post(self, request):
form = TaskForm(data=request.POST)
if not form.is_valid():
return self.get(request, form)
form.save()
return redirect('index')
示例6: test_should_be_invalid_from_blank_description
def test_should_be_invalid_from_blank_description(self):
"""
A Task Form should be invalid, due to blank desc.
"""
task = Task()
task_form = TaskForm(instance=task)
self.assertFalse(task_form.is_valid())
示例7: index
def index():
form = TaskForm()
if form.validate_on_submit():
r.table('todos').insert({"name":form.label.data}).run(g.rdb_conn)
return redirect(url_for('index'))
selection = list(r.table('todos').run(g.rdb_conn))
return render_template('index.html', form = form, tasks = selection)
示例8: task_edit
def task_edit(request, task_id, response_format='html'):
"""Task edit page"""
task = get_object_or_404(Task, pk=task_id)
if not request.user.profile.has_permission(task, mode='w'):
return user_denied(request, message="You don't have access to this Task")
if request.POST:
if 'cancel' not in request.POST:
form = TaskForm(
request.user.profile, None, None, None, request.POST, instance=task)
if form.is_valid():
task = form.save()
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
else:
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
else:
form = TaskForm(
request.user.profile, None, None, None, instance=task)
context = _get_default_context(request)
context.update({'form': form,
'task': task})
return render_to_response('projects/task_edit', context,
context_instance=RequestContext(request), response_format=response_format)
示例9: edit_task_in_list
def edit_task_in_list(request, storyID, taskID):
story = mdl_story.get_story(storyID)
task = mdl_task.get_task(taskID)
project = story.project
association = UserAssociation.objects.get(
user=request.user,
project=project)
if request.method == 'POST':
form = TaskForm(request.POST, instance=task)
if form.is_valid():
task = form.save(commit=True)
else:
form = TaskForm(instance=task)
tasks = mdl_task.get_tasks_for_story(story)
context = {
'story': story,
'tasks': tasks,
'task': task,
'editform': form,
'project': project,
'association': association
}
return render(request, 'TaskList.html', context)
示例10: task_add_subtask
def task_add_subtask(request, task_id=None, response_format='html'):
"""New subtask form"""
parent = None
if task_id:
parent = get_object_or_404(Task, pk=task_id)
if not request.user.profile.has_permission(parent, mode='x'):
parent = None
if request.POST:
if 'cancel' not in request.POST:
task = Task()
form = TaskForm(
request.user.profile, parent, None, None, request.POST, instance=task)
if form.is_valid():
task = form.save()
task.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_task_view', args=[parent.id]))
else:
return HttpResponseRedirect(reverse('projects_task_view', args=[parent.id]))
else:
form = TaskForm(request.user.profile, parent, None, None)
context = _get_default_context(request)
context.update({'form': form,
'task': parent})
return render_to_response('projects/task_add_subtask', context,
context_instance=RequestContext(request), response_format=response_format)
示例11: task_add_to_milestone
def task_add_to_milestone(request, milestone_id=None, response_format='html'):
"""Task add to preselected project"""
milestone = None
if milestone_id:
milestone = get_object_or_404(Milestone, pk=milestone_id)
if not request.user.profile.has_permission(milestone, mode='x'):
milestone = None
project = milestone.project
project_id = milestone.project.id
if request.POST:
if 'cancel' not in request.POST:
task = Task()
form = TaskForm(request.user.profile, None,
project_id, milestone_id, request.POST, instance=task)
if form.is_valid():
task = form.save()
task.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
else:
return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
else:
form = TaskForm(
request.user.profile, None, project_id, milestone_id)
context = _get_default_context(request)
context.update({'form': form,
'project': project,
'milestone': milestone})
return render_to_response('projects/task_add_to_milestone', context,
context_instance=RequestContext(request), response_format=response_format)
示例12: task
def task():
form = TaskForm()
if request.method == "POST":
if form.validate() == False:
flash("All fields are required")
return render_template("task.html",form=form)
else:
task_name = form.name.data
task_client = form.client.data
task_capabilities = form.capabilities.data
task_duration = int(form.duration.data)
#insert values to Task table
task_msg = task_insert(task_name,task_client,task_capabilities,task_duration)
return jsonify(name =task_name,
client=task_client,
capabilities=task_capabilities,
duration=task_duration,result = task_msg)
#return render_template("success.html",form=form)
elif request.method == 'GET':
return render_template("task.html",form=form)
示例13: test_task_form
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)
示例14: add_task
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)
示例15: new_task
def new_task():
form = TaskForm(request.form)
if request.method == 'POST' and form.validate():
task = Task(form.name.data, form.text.data, form.memory.data, form.time_limit.data, g.user)
task.save()
return redirect(url_for('task', task_id=task.task_id))
return render_template('task_form.html', form=form)