Пример #1
0
def change_tasks(id_task, page, select_date_task):
    form = TasksForm()
    session = db_session.create_session()
    tasks = session.query(models.tasks.Tasks).filter(
        models.tasks.Tasks.id_task == id_task,
        models.tasks.Tasks.user == current_user).first()
    if request.method == 'GET':
        if tasks:
            form.text_task.data = tasks.text_task
            date_task = datetime.strptime(tasks.data, '%d-%m-%Y').date()
            form.data.data = date_task
            form.start_time.data = tasks.start_time
            form.important.data = tasks.id_important
        else:
            abort(404)
    if form.validate_on_submit():
        if tasks:
            tasks.text_task = form.text_task.data
            tasks.data = form.data.data.strftime('%d-%m-%Y')
            tasks.start_time = form.start_time.data
            tasks.id_important = form.important.data
            session.commit()
            if page == 'index':
                return redirect('/' + page)
            else:
                return redirect('/' + page + '/' + select_date_task)
        else:
            abort(404)
    return render_template('tasks.html', title='Изменение Задачи', form=form)
Пример #2
0
def add_task():
    form = TasksForm()
    if form.validate_on_submit():
        task = Tasks(
            form.taskname.data,
            form.task.data,
            form.roles.data,
            form.parallel.data,
            form.sendmail.data,
        )
        db.session.add(task)
        db.session.commit()
        return redirect(url_for('tasks'))
    tasks = Tasks.query.order_by(db.desc(Tasks.taskname))
    return render_template('tasks/add_task.html', tasks=tasks, form=form)
Пример #3
0
def edit_task(task_id):
    form = TasksForm()
    entry = Tasks.query.filter_by(id = task_id).first_or_404()
    if form.validate_on_submit():
        tasks = Tasks(
            form.taskname.data,
            form.task.data,
            form.roles.data,
            form.parallel.data,
            form.sendmail.data,
        )
        entry.taskname = form.taskname.data
        entry.task = form.task.data
        entry.roles = form.roles.data
        entry.parallel = form.parallel.data
        entry.sendmail = form.sendmail.data
        db.session.commit()
        return redirect(url_for('tasks'))
    else:
        form = TasksForm(obj=entry)
        form.populate_obj(entry)
    return render_template('tasks/edit_task.html', entry=entry, form=form)
Пример #4
0
def add_tasks(page, date_task):
    form = TasksForm()
    if request.method == 'GET':
        form.data.data = datetime.strptime(date_task, '%d-%m-%Y').date()
    if form.validate_on_submit():
        session = db_session.create_session()
        tasks = models.tasks.Tasks()
        tasks.text_task = form.text_task.data
        tasks.data = form.data.data.strftime('%d-%m-%Y')
        tasks.start_time = form.start_time.data
        tasks.id_important = form.important.data
        tasks.user = current_user
        session.merge(tasks)
        session.commit()
        if page == 'index':
            return redirect('/' + page)
        else:
            return redirect('/' + page + '/' + date_task)
    return render_template('tasks.html',
                           title='Добавление Задачи',
                           form=form,
                           data=date_task)