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


Python forms.AddTaskForm类代码示例

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


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

示例1: new_task

def new_task():
	error = None
	form = AddTaskForm(request.form)
	# g.db = connect_db()
	# name = request.form['name']
	# due_date = request.form['due_date']
	# priority = request.form['priority']
	# if not name or not due_date or not priority:
	# 	flash("All fields are required. Please try again!")
	# 	return redirect(url_for('tasks'))
	# else:
	# 	g.db.execute("""insert into tasks (name, due_date, priority, status) values (?,?,?,1)""",
	# 		[request.form['name'],request.form['due_date'],request.form['priority']])
	# 	g.db.commit()
	# 	g.db.close()
	if request.method == 'POST':
		if form.validate_on_submit():
			new_task = Task(form.name.data, form.due_date.data, form.priority.data,'1',
				session['user_id'],datetime.utcnow())
			db.session.add(new_task)
			db.session.commit()
			flash("New entry was successfully posted. Thanks!")
		else:
			# flash('All fields are required!')
			return render_template('tasks.html', form=form, error=error)
	return render_template('tasks.html', form=form, error=error,
		open_tasks=open_tasks(), closed_tasks=closed_tasks())
开发者ID:sshimp,项目名称:flasktaskr,代码行数:27,代码来源:views.py

示例2: new_task

def new_task():
    error = []
    form = AddTaskForm(flask.request.form)
    print(flask.request.form)
    if flask.request.method == "POST":
        if form.validate_on_submit():
            new_task = Task(
                form.name.data,
                form.due_date.data,
                form.priority.data,
                datetime.datetime.utcnow(),
                "1",
                flask.session["user_id"]
            )
            db.session.add(new_task)
            db.session.commit()
            flask.flash("New entry was successfully posted.")
            return flask.redirect(flask.url_for("tasks"))
        else:
            error.append("There was an error with the task data. Make sure all fields are filled in.")
    return flask.render_template(
        "tasks.html",
        form = form,
        error = error,
        open_tasks = open_tasks(),
        closed_tasks = closed_tasks()
    )     
开发者ID:jarogers095,项目名称:flasktaskr,代码行数:27,代码来源:views.py

示例3: new_task

def new_task():
    error = None
    form = AddTaskForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_task = Task(
                form.name.data,
                session['user_id'],
                form.due_date.data,
                form.priority.data,
                '1',
                datetime.datetime.utcnow()
            )
            db.session.add(new_task)
            db.session.commit()
            flash("New entry was successfully posted. Thanks.")
            return redirect(url_for('tasks'))
        else:
            return render_template(
                'tasks.html',
                form=form,
                error=error,
                open_tasks=open_tasks(),
                closed_tasks=closed_tasks()
            )
    else:
        return render_template(
            'tasks.html',
            form=form,
            error=error,
            open_tasks=open_tasks(),
            closed_tasks=closed_tasks()
        )
开发者ID:atengler,项目名称:python-testing,代码行数:33,代码来源:views.py

示例4: add_task

def add_task():
    task_id = request.args.get('tid')
    ori_task = Task.query.filter(Task.id == task_id).first()
    form = AddTaskForm()
    if ori_task:
        form = AddTaskForm(name=ori_task.name, key=ori_task.redis_key, ctime=ori_task.start_time)

    if request.method == 'POST' and form.validate():
        tid = request.values.get('tid')
        str_key = form.key.data
        task = Task(form.name.data, str_key, form.ctime.data)
        if tid:
            # update
            tsObj = Task.query.filter(Task.id == tid).first()
            ori_str_key = tsObj.redis_key
            rd.delete(ori_str_key)
            tsObj.redis_key = str_key
            tsObj.name = form.name.data
            tsObj.start_time = form.ctime.data
            db.session.commit()
        else:
            db.session.add(task)

        rd.setex(str_key, 1, task.seconds)
        return redirect('/')
    return render_template('add.html', form=form)
开发者ID:BeginMan,项目名称:flask-timing,代码行数:26,代码来源:app.py

示例5: add

def add():
    """g.db = connect_db()
    name = request.form['name']
    due_date = request.form['due_date']
    priority = request.form['priority']
    if not name or not due_date or not priority:
        flash("Please fill all the fields")
        return redirect(url_for('tasks'))
    else:
        #g.db.execute("INSERT INTO tasks(name, due_date, priority, status) VALUES(?, ?, ?, 1)",[request.form['name'],request.form['due_date'],request.form['priority']])
        #g.db.commit()
        #g.db.close()
        flash("Your entry was successfully admitted")
        return redirect(url_for('tasks'))"""
    form = AddTaskForm(request.form)
    if request.method == "POST":
        if form.validate_on_submit():
            new_task = Task(form.name.data, form.due_date.data, form.priority.data, "1", session["user_id"])
            db.session.add(new_task)
            db.session.commit()
            flash("New entry was successfully posted. Thanks.")
            return redirect(url_for("tasks.tasks"))
        else:
            return render_template("tasks.html", form=form, error=error)
    return render_template("tasks.html", form=form, error=error, open_tasks=open_tasks(), closed_tasks=closed_tasks())
开发者ID:xtreampy,项目名称:py_get_real,代码行数:25,代码来源:views.py

示例6: new_task

def new_task():
	error = None
	form = AddTaskForm(request.form)
	if request.method == 'POST':
		if form.validate_on_submit():
			new_task = Task(
				form.name.data,
				form.due_date.data,
				form.priority.data,
				datetime.datetime.utcnow(),
				'1',
				session['user_id']
			)
			db.session.add(new_task)
			db.session.commit()
			flash('New entry was successfully posted. Thanks')
			return redirect(url_for('tasks.tasks'))
			
		else:
			open_tasks = db.session.query(Task) \
				.filter_by(status='1').order_by(Task.due_date.asc())
		
			closed_tasks = db.session.query(Task) \
				.filter_by(status='0').order_by(Task.due_date.asc())
				
			return render_template('tasks.html', form=form, error=error, open_tasks = open_tasks, closed_tasks = closed_tasks)
开发者ID:zklevsha,项目名称:flasktaskr-old,代码行数:26,代码来源:views.py

示例7: new_task

def new_task():
	form = AddTaskForm(request.form)
	if request.method == "POST":
		if form.validate_on_submit():
			new_task = Task(form.name.data, form.due_date.data, form.priority.data, 1)
			db.session.add(new_task)
			db.session.commit()
			flash("New task has been added")
	return redirect(url_for("tasks"))
开发者ID:janhaans,项目名称:flasktaskr,代码行数:9,代码来源:views.py

示例8: new_task

def new_task():
    form = AddTaskForm(request.form)
    if request.method == "POST":
        if form.validate_on_submit():
            new_task = Task(form.name.data, form.due_date.data, form.priority.data, "1")
            db.session.add(new_task)
            db.session.commit()
            flash("New entry was susccessfully posted Thanks.")
    return redirect(url_for("tasks"))
开发者ID:joshphiggins,项目名称:FlashTaskr,代码行数:9,代码来源:views.py

示例9: addtask

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,代码行数:13,代码来源:views.py

示例10: add_task

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,代码行数:13,代码来源:views.py

示例11: new_task

def new_task():
    form = AddTaskForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():  # something to look into
            new_task = models.Task(
                form.name.data,
                form.due_date.data,
                form.priority.data,
                '1'
            )
            db.session.add(new_task)
            db.session.commit()
            flash('New Entry Added Successfully')
    return redirect(url_for('tasks'))
开发者ID:PansFortress,项目名称:flasktasker,代码行数:14,代码来源:views.py

示例12: new_task

def new_task():
  form = AddTaskForm(request.form)
  if request.method == 'POST':
    if form.validate_on_submit():
      new_user = User(
        form.username.data,
        form.ip_phone.data,
        form.ip_phone_type.data,
        '1'
      )
      db.session.add(new_user)
      db.session.commit()
      flash('New entry was successfully posted. Thanks.') 
  return redirect(url_for('tasks'))
开发者ID:sturmblade,项目名称:flask-cucm,代码行数:14,代码来源:views.py

示例13: tasks

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,代码行数:49,代码来源:views.py

示例14: new_task

def new_task():
    form = AddTaskForm(request.form)
    if request.method == "POST":
        if form.validate_on_submit() or True:
            new_task = Task(
                name = form.name.data,
                due_date = form.due_date.data,
                priority = form.priority.data,
                status = '1',
                posted_date = datetime.datetime.utcnow(),
                user_id = session['user_id']
                )
            db.session.add(new_task)
            db.session.commit()
    return redirect(url_for('tasks'))
开发者ID:kwikiel,项目名称:scrumtasker,代码行数:15,代码来源:views.py

示例15: new_task

def new_task():
    form = AddTaskForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_task = Task(
                form.name.data,
                form.due_date.data,
                form.priority.data,
                datetime.datetime.utcnow(),
                '1',
                '1'
            )
            db.session.add(new_task)
            db.session.commit()
            flash('New entry posted! Do it, Doug!')
    return redirect(url_for('tasks'))
开发者ID:jerodestapa,项目名称:flasktodo,代码行数:16,代码来源:views.py


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