예제 #1
0
def edit_task(task_id):
    form = TaskForm()
    print(form.validate_on_submit())
    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.

        current_task = Task.query.filter_by(task_id=task_id).first_or_404()
        current_task.task_desc = form.task_desc.data
        current_task.task_status = form.task_status_completed.data

        db.session.add(current_task)
        db.session.commit()
        # After editing, redirect to the view page.
        return redirect(url_for('main.todolist'))

    # get task for the database.
    current_task = Task.query.filter_by(task_id=task_id).first_or_404()

    # update the form model in order to populate the html form.
    form.task_desc.data = current_task.task_desc
    form.task_status_completed.data = current_task.task_status

    return render_template("main/todolist_edit_view.html",
                           form=form,
                           task_id=task_id)
def modify_task(task_id):
    task = Task.query.filter_by(id=task_id).first()

    data_form = dict(title=task.title,
                     description=task.description,
                     due_date=task.due_date,
                     status=task.status,
                     user=task.user)

    form = TaskForm(data=data_form)

    if form.validate_on_submit():
        task.title = form.title.data
        task.description = form.description.data
        task.updated = datetime.now()
        task.due_date = form.due_date.data
        task.status = form.status.data
        task.user = form.user.data

        db.session.add(task)
        db.session.commit()

        flash('Your task has been modified.')
        return redirect(url_for('main.see_task', task_id=task_id))

    return render_template('insert_data.html',
                           title='Modify task',
                           form=form,
                           header='Modify task')
예제 #3
0
def user_lists(list_id):
    tform = TaskForm()
    tlist = TaskList.query.filter_by(id=int(list_id)).first()

    # check if list exists and user has access to it
    if not tlist or tlist.id not in [int(tl.id) for tl in g.user.get_task_lists()]:
        abort(404)

    if tform.validate_on_submit():
        err = tlist.add_task(Task(name=tform.name.data,
                                  state=Task.TASK_STATE_OPEN,
                                  user_id=g.user.id))
        if not err:
            flash('Task %s was added successfully' % tform.name.data, 'success')
        else:
            flash(err, 'warning')
        return redirect(url_for('main.user_lists', list_id=list_id))

    return render_template('personal.html',
                           user=g.user,
                           task_list=tlist,
                           task_lists=None,
                           tform=tform,
                           tlform=None,
                           sform=None)
예제 #4
0
def index():
    form = TaskForm()
    if form.validate_on_submit():
        language = guess_language(form.task.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        task = Task(body=form.task.data,
                    author=current_user,
                    language=language)
        db.session.add(task)
        db.session.commit()
        flash(_('Your task has been added.'))
        return redirect(url_for('main.index'))
    page = request.args.get('page', 1, type=int)
    tasks = current_user.followed_tasks().paginate(
        page, current_app.config['TASKS_PER_PAGE'], False)
    next_url = url_for('main.index', page=tasks.next_num) \
        if tasks.has_next else None
    prev_url = url_for('main.index', page=tasks.prev_num) \
        if tasks.has_prev else None
    return render_template('index.html',
                           title=_('Home'),
                           form=form,
                           tasks=tasks.items,
                           next_url=next_url,
                           prev_url=prev_url)
예제 #5
0
def ModifyTask(task_id):
	form = TaskForm()
	if current_user.role == UserRoles.admin:
		departments = Department.query.all()
		departments_list = [(d.id, d.name) for d in departments]		
	else:
		departments_list = [(current_user.dep_id,current_user.department.name)]		
	departments_list.append((0, 'Без отдела'))
	form.department.choices = departments_list
	if form.validate_on_submit():
		if task_id is None:
			task = Task()
			db.session.add(task)
		else:
			task = Task.query.filter(Task.id == task_id).first()
		task.name = form.task_name.data.strip()
		task.metric = form.metric.data.strip()
		if form.department.data != 0:
			task.dep_id = form.department.data
		else:
			task.dep_id = None
		db.session.commit()
		flash('Задача успешно сохранена.')
	else:
		for error in form.task_name.errors + form.metric.errors + form.department.errors:
			flash(error)
	return redirect(url_for('main.ShowTasks'))
예제 #6
0
def todolist(sort):
    form = TaskForm()

    if form.validate_on_submit() and request.form['date'] != "":
        # Get the data from the form, and add it to the database.
        new_task = Task()
        new_task.task_desc = form.task_desc.data
        new_task.task_status = form.task_status_completed.data
        new_task.task_date = request.form['date']
        new_task.task_customer = form.task_customer.data
        new_task.task_location = form.task_location.data
        db.session.add(new_task)
        db.session.commit()
        # Redirect to this handler - but without form submitted - gets a clear form.
        return redirect("/todolist/0")

    if sort == 1:
        todo_list = Task.query.order_by(Task.task_status)
    elif sort == 2:
        todo_list = Task.query.order_by(Task.task_date)
    elif sort == 3:
        todo_list = Task.query.order_by(Task.task_customer)
    else:
        todo_list = Task.query.order_by(Task.task_id)

    date = datetime.now().date()
    for i in todo_list:
        task_date = datetime.strptime(i.task_date, "%Y-%m-%d").date()
        if task_date < date and i.task_status != "done":
            i.task_status = "overdue"

    return render_template("main/todolist.html",
                           todo_list=todo_list,
                           form=form)
예제 #7
0
def edit_appointment(appointment_id):
    form = TaskForm()
    print(form.validate_on_submit())
    if form.validate_on_submit():

        current_appointment.app_title = form.app_title.data
        current_appointment.app_date = form.app_date.data
        current_appointment.start_time = form.start_time.data
        current_appointment.app_duration = form.app_duration.data
        current_appointment.app_notes = form.app_notes.data
        current_appointment.app_status = form.app_status.data

        db.session.add(current_appointment)
        db.session.commit()
        # After editing, redirect to the view page.
        return redirect(url_for(''))  #edit for appointments list route
예제 #8
0
def index(city=None):

    city = City.query.filter_by(name=city).first()

    available_citys = City.query.all()
    folder = os.environ.get('ICON_FOLDER')
    filelist = []
    for x in os.listdir(folder):
        filelist.append(x)
    citys_list = [(i.id, i.name) for i in available_citys]

    form_task = TaskForm()

    form_task.city.choices = citys_list

    if form_task.validate_on_submit():
        print('in form')
        city = City.query.get(form_task.city.data)
        print('in form')
        task = Task(body=form_task.body.data,
                    author=current_user,
                    internet=form_task.internet.data,
                    summary=form_task.summary.data,
                    price=form_task.price.data,
                    currency=form_task.currency.data,
                    status='open')

        folder = form_task.folder_name.data

        for x in os.listdir(folder):
            print(x)

        tags = form_task.tags.data
        tags = tags[:-1]
        tags = tags.split('%')

        db.session.add(task)
        db.session.commit()

        for tag in tags:
            tagout = Tags.query.filter_by(name=tag).first()
            if tagout is not None:
                task.tags.append(tagout)
            else:
                tagout = Tags(name=tag)
                task.tags.append(tagout)

        db.session.commit()

        scity = City.query.get(form_task.city.data)
        scity.citytasks.append(task)
        db.session.commit()
        return redirect(url_for('main.index'))

    return render_template('index.html',
                           form_task=form_task,
                           filelist=filelist)
예제 #9
0
def new_task():
    form = TaskForm()
    print(form.validate_on_submit())
    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.
        new_task = Task()
        new_task.task_title = form.task_title.data
        new_task.task_desc = form.task_desc.data
        new_task.task_status = form.task_status_completed.data
        new_task.task_date = request.form['date']
        new_task.task_time = form.task_time.data
        new_task.task_duration = form.task_duration.data
        new_task.task_address = form.task_location.data
        new_task.task_Cname = form.task_CName.data
        db.session.add(new_task)
        db.session.commit()
        todo_list = db.session.query(Task).all()
        return redirect(url_for('main.todolist', todo_list=todo_list,
                                sortby=0))
    return render_template("main/todolist_new.html", form=form)
예제 #10
0
def update_Task(board_id, task_id):
    form = TaskForm()
    task_to_update = Task.query.get(task_id)
    if form.validate_on_submit():
        task_to_update.title = form.title.data
        task_to_update.description = form.description.data
        task_to_update.status = form.status.data
        task_to_update.due_date = form.due_date.data
        db.session.add(task_to_update)
        db.session.commit()
        flash("Task was updated successfully.")
    return redirect(url_for("main.view_tasks", board_id=board_id))
예제 #11
0
def create_Task(board_id):
    form = TaskForm()
    board = TaskBoard.query.get(board_id)
    if form.validate_on_submit():
        new_task = Task(
            title=form.title.data,
            description=form.description.data,
            status=form.status.data,
            due_date=form.due_date.data,
            board=board,
        )
        db.session.add(new_task)
        db.session.commit()
        flash("New task was created successfully.")
    return redirect(url_for("main.view_tasks", board_id=board_id))
예제 #12
0
def edit_task(task_id):
    form = TaskForm()
    print(form.validate_on_submit())
    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.

        current_task = Task.query.filter_by(task_id=task_id).first()
        current_task.task_title = form.task_title.data
        current_task.task_desc = form.task_desc.data
        current_task.task_date = request.form['date']
        current_task.task_status = form.task_status_completed.data
        current_task.task_duration = form.task_duration.data
        current_task.task_time = form.task_time.data
        current_task.task_location = form.task_location.data
        current_task.task_CName = form.task_CName.data
        db.session.commit()
        # After editing, redirect to the view page.
        return redirect(url_for('main.todolist', sortby=0))

    # get task for the database.
    current_task = Task.query.filter_by(task_id=task_id).first_or_404()

    # update the form model in order to populate the html form.
    form.task_title.data = current_task.task_title
    form.task_desc.data = current_task.task_desc
    form.task_status_completed.data = current_task.task_status
    form.task_date = current_task.task_date
    form.task_CName.data = current_task.task_Cname
    form.task_location.data = current_task.task_address
    form.task_time.data = current_task.task_time
    form.task_duration.data = current_task.task_duration

    return render_template("main/todolist_edit_view.html",
                           form=form,
                           task_id=task_id,
                           sortby=0)
예제 #13
0
def todolist():
    form = TaskForm()

    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.
        new_task = Task()
        new_task.task_desc = form.task_desc.data
        new_task.task_status = form.task_status_completed.data

        db.session.add(new_task)
        db.session.commit()

        # Redirect to this handler - but without form submitted - gets a clear form.
        return redirect(url_for('main.todolist'))

    todo_list = db.session.query(Task).all()

    return render_template("main/todolist.html", todo_list=todo_list, form=form)
예제 #14
0
def add_task():
    form = TaskForm()

    if form.validate_on_submit():
        task = Task(title=form.title.data,
                    description=form.description.data,
                    due_date=form.due_date.data,
                    status=form.status.data,
                    user=form.user.data)

        db.session.add(task)
        db.session.commit()

        flash('Your task  is now live!', 'success')
        return redirect(url_for('main.see_task_list'))

    return render_template('insert_data.html',
                           title='Add task',
                           form=form,
                           header='Add task')
예제 #15
0
def task(taskid):
    task = Task.query.filter_by(id=taskid).first_or_404()
    if task.executor != -1 and not (task.executor == current_user.id
                                    or task.customer == current_user.id):
        return redirect(url_for('main.index'))
    form = TaskForm()
    if task.executor != -1:
        form.submit.label.text = 'Done'
    if form.validate_on_submit():
        if task.customer != current_user.id:
            if task.executor == -1:
                task.executor = current_user.id
            else:
                task.is_end = True
            db.session.add(task)
            db.session.commit()
            return redirect(url_for('main.index'))
    executor = User.query.get(task.executor)
    customer = User.query.get(task.customer)
    task = {'task': task, 'executor': executor, 'customer': customer}
    return render_template('task.html', title='Task', task=task, form=form)
예제 #16
0
def task():
    form = TaskForm()
    if form.validate_on_submit():
        language = guess_language(form.name.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        task = Task(name=form.name.data, description=form.description.data, author=current_user,
                    language=language)
        db.session.add(task)
        db.session.commit()
        flash(_('Your task has been added!'))
        return redirect(url_for('main.task'))

    page = request.args.get('page', 1, type=int)
    tasks = current_user.owned_tasks().paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('main.explore', page=tasks.next_num) \
        if tasks.has_next else None
    prev_url = url_for('main.explore', page=tasks.prev_num) \
        if tasks.has_prev else None
    return render_template('tasks.html', title='Tasks', form=form,
                                tasks=tasks.items, next_url=next_url,
                                prev_url=prev_url)
예제 #17
0
def render_create_task():
    if current_user.is_boss:
        form = TaskForm()
        executors = db.session.query(User).filter(
            User.is_boss.is_(False)).order_by(User.username).all()
        projects = db.session.query(Project).filter(
            Project.is_relevant.is_(True)).all()
        form.users.choices = [(executor.id, executor.username)
                              for executor in executors]
        form.project.choices = [(project.id, project.name)
                                for project in projects]
        if form.validate_on_submit():
            executors_lst = [
                db.session.query(User).get_or_404(executor_id)
                for executor_id in form.users.data
            ]
            deadline = form.deadline_date.data.strftime(
                "%Y-%m-%d") + ' ' + form.deadline_time.data.strftime(
                    "%H:%M:%S")
            deadline = datetime.strptime(deadline, "%Y-%m-%d %H:%M:%S")
            new_task = Task(name=form.name.data,
                            description=form.description.data,
                            deadline=deadline.astimezone(tzutc()),
                            author=current_user,
                            users=executors_lst,
                            priority=form.priority.data,
                            project=db.session.query(Project).get_or_404(
                                form.project.data))
            db.session.add(new_task)
            db.session.commit()
            return redirect(
                url_for('main.render_task_created', task_id=new_task.id))
        return render_template('create_task.html',
                               title="Создать задачу",
                               form=form)
    return abort(403)
예제 #18
0
def todolist():
    form = TaskForm()

    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.
        new_appointment = Appointment()
        new_appointment.app_title = form.app_title.data
        new_appointment.app_date = form.app_date.data
        new_appointment.start_time = form.start_time.data
        new_appointment.app_duration = form.app_duration.data
        new_appointment.app_notes = form.app_notes.data
        new_appointment.app_status = form.app_status.data

        db.session.add(new_appointment)
        db.session.commit()

        # Redirect to this handler - but without form submitted - gets a clear form.
        return redirect(url_for(''))  # Add route for the appointment list

    todo_list = db.session.query(Appointment).all()

    return render_template("main/todolist.html",
                           todo_list=todo_list,
                           form=form)  # edit for appointments list route