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


Python AddTaskForm.save方法代码示例

本文整理汇总了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))
开发者ID:jmstaley,项目名称:timetracker,代码行数:15,代码来源:views.py

示例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)        
开发者ID:LeoVanNierop,项目名称:todo-app,代码行数:15,代码来源:views.py

示例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)
开发者ID:QA-long,项目名称:django-projectmanager,代码行数:51,代码来源:views.py


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