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


Python TaskForm.is_valid方法代码示例

本文整理汇总了Python中forms.TaskForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python TaskForm.is_valid方法的具体用法?Python TaskForm.is_valid怎么用?Python TaskForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.TaskForm的用法示例。


在下文中一共展示了TaskForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_task_form

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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)
开发者ID:rob-b,项目名称:Jung,代码行数:29,代码来源:tests.py

示例2: add_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:liukoo,项目名称:crawl,代码行数:27,代码来源:views.py

示例3: add_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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)
开发者ID:levvism,项目名称:tracker,代码行数:29,代码来源:views.py

示例4: test_should_be_invalid_from_blank_description

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
 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())
开发者ID:freyes,项目名称:django-todo,代码行数:9,代码来源:tests.py

示例5: task_create

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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,
        })
开发者ID:isergey,项目名称:proman,代码行数:27,代码来源:views.py

示例6: create_subtask

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
def create_subtask(request, task_id):
    parent = Task.objects.get(id=task_id)
    pr = Project.objects.get(id=parent.project_id)
    if request.method == 'POST':
        form = TaskForm(request.POST, request.FILES)
        if form.is_valid():
            c = form.save(commit=False)
            c.creator = auth.get_user(request)
            c.project = pr
            c.parent_task = parent
            c.save()
            form.save_m2m()
            task = Task.objects.get(id=c.id)
            assign_newtask_perm(task, pr, request.user)
            loger(auth.get_user(request), 'task_created', c.name, c, pr)

            return HttpResponseRedirect('/projector/project/{}'.format(parent.project_id))
    else:
        form = TaskForm()
    args = {}
    args.update(csrf(request))
    args['project'] = pr
    args['form'] = form
    args['parent'] = parent
    args['username'] = auth.get_user(request).username

#    import pdb; pdb.set_trace()

    return render_to_response('create_task.html',args)
开发者ID:i-k-i,项目名称:tolk,代码行数:31,代码来源:views.py

示例7: create_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:saursuma,项目名称:telecom-v1,代码行数:31,代码来源:views.py

示例8: task_add_subtask

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:tovmeod,项目名称:anaf,代码行数:31,代码来源:views.py

示例9: task_edit

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:tovmeod,项目名称:anaf,代码行数:28,代码来源:views.py

示例10: task_add_to_milestone

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:tovmeod,项目名称:anaf,代码行数:36,代码来源:views.py

示例11: post

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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')
开发者ID:freyes,项目名称:django-todo,代码行数:9,代码来源:views.py

示例12: edit_task_in_list

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [as 别名]
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)
开发者ID:ayodele1,项目名称:Final_Project,代码行数:27,代码来源:stories.py

示例13: update_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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})
开发者ID:IzmaylovR,项目名称:Task-manager,代码行数:11,代码来源:views.py

示例14: new_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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})
开发者ID:IzmaylovR,项目名称:Task-manager,代码行数:11,代码来源:views.py

示例15: get_task_list_task

# 需要导入模块: from forms import TaskForm [as 别名]
# 或者: from forms.TaskForm import is_valid [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})
开发者ID:Gkastrin,项目名称:gorilist,代码行数:12,代码来源:views.py


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