Example #1
0
def edit_task():
    """
    Edits a to-do task from modal input.

    Can be a single task or multiple, related tasks.
    """

    edit_task = Post()
    edit_task.form = TaskForm()
    edit_task.task_to_be_edited = current_user.posts.filter_by(
        id=int(edit_task.form.ident.data)
    ).first()
    if not edit_task.form.validate_on_submit():
        return redirect(url_for("main.index", date_set="ph"))
    else:
        edit_task.calc_mins_height_and_end()
        if edit_task.form.single_event.data is True:
            if (
                edit_task.task_to_be_edited.exclude
                and edit_task.task_to_be_edited.exclude
                != int(edit_task.form.ident.data)
            ):
                edit_task.edit_single_task()
            else:
                edit_task.edit_single_freq_task()
        else:
            if edit_task.task_to_be_edited.exclude:
                edit_task.edit_all_freq_parent_and_child_tasks()
            else:
                edit_task.edit_all_tasks()
        db.session.commit()
        return jsonify({"id": edit_task.form.ident.data})
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'))
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')
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #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)
Example #9
0
def view_tasks(board_id):
    form = TaskForm()
    board = TaskBoard.query.get(board_id)
    all_tasks = Task.query.filter_by(board=board)
    return render_template(
        "task_detail.html",
        all_tasks=all_tasks,
        form=form,
        board_id=board_id,
        board_title=board.title,
    )
Example #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))
Example #11
0
def new_task_with_form_helper(self, tester):
    form = TaskForm()
    form.task.data = "This is a single task"
    form.start_time.data = datetime.now().strftime("%H:%M")
    form.end_time.data = datetime.now().strftime("%H:%M")
    form.date.data = date
    form.color.data = "#fff"
    form.frequency.data = 0
    form.single_event.data = None
    response = tester.post("/new_task/", data=form.data)
    converted_response_data = json.loads(response.data)
    form.ident.data = converted_response_data["id"]
    return form, converted_response_data
Example #12
0
def new_time_limited_task_helper(self, tester):
    form = TaskForm()
    form.task.data = "This is a time limited freq task"
    form.start_time.data = datetime.now().strftime("%H:%M")
    form.end_time.data = datetime.now().strftime("%H:%M")
    form.date.data = date
    form.color.data = "#fff"
    form.frequency.data = 1
    form.single_event.data = None
    form.to_date.data = tomorrow
    response = tester.post("/new_task/", data=form.data)
    converted_response_data = json.loads(response.data)
    form.ident.data = int(converted_response_data["id"])
    return form, converted_response_data
Example #13
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))
Example #14
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
Example #15
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)
Example #16
0
def index(date_set):
    """
    Render the index page.

    date_set: argument that is used to retreive tasks for
    a specific date or, if set to 'ph', will default to today's date.
    """
    date_form = DateForm()
    if date_form.validate_on_submit():
        return redirect(
            url_for(
                "main.index", 
                date_set=datetime_to_string(date_form.datepicker.data)
            )
        )
    form = TaskForm()
    date = set_date(date_set)
    today = False
    if convert_date_format(datetime.utcnow()) == date:
        today = True
    current_user.check_if_depression_sent(date)
    date_form.datepicker.data = date
    all_frequency_tasks = current_user.posts.filter(Post.frequency != None).all()
    todos = current_user.posts.filter_by(date=date)
    exclusions = [todo.exclude for todo in todos if todo.exclude]
    frequency_tasks = [
        task
        for task in all_frequency_tasks
        if task.frequency > 0
        and (date - task.date).days > 0
        and ((date - task.date).days % task.frequency) == 0
        and task.date < date
        and task.id not in exclusions
    ]
    return render_template(
        "index.html",
        frequency_tasks=frequency_tasks,
        today=today,
        todos=todos,
        date_set=date_set,
        title="Home Page",
        form=form,
        date_form=date_form,
    )
Example #17
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)
Example #18
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')
Example #19
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)
def ShowTasks():
	task_form = TaskForm()
	assign_form = AssignmentForm()
	if current_user.role == UserRoles.admin:
		tasks = Task.query.order_by(Task.dep_id).all()
		departments = Department.query.all()
		departments_list = [(d.id, d.name) for d in departments]
	else:
		tasks = Task.query.filter(or_(Task.dep_id == current_user.dep_id, Task.dep_id == None)).order_by(Task.dep_id).all()
		departments_list = [(current_user.dep_id,current_user.department.name)]
	if current_user.role == UserRoles.manager:
		users = User.query.filter(User.dep_id == current_user.dep_id, User.id != current_user.id, User.role == UserRoles.employee).order_by(User.name).all()
		users_list = [(u.id, u.name) for u in users]
	elif current_user.role == UserRoles.employee:
		users_list = [(current_user.id,current_user.name)]
	else:
		users_list = []
	departments_list.append((0, 'Без отдела'))
	task_form.department.choices = departments_list
	assign_form.user.choices = users_list
	return render_template('tasks.html', tasks=tasks, task_form=task_form, assign_form=assign_form)
Example #21
0
def new_task():
    """Creates a new todo task."""
    new_task = Post()
    new_task.form = TaskForm()
    if not new_task.form.validate_on_submit():
        return redirect(url_for("main.index", date_set="ph"))
    else:
        new_task.calc_mins_height_and_end()
        if new_task.minutes > new_task.end:
            return redirect(url_for("main.index", date_set="ph"))
        new_task.set_frequency()
        if new_task.form.frequency.data and new_task.form.to_date.data:
            new_task.to_date = convert_date_format(new_task.form.to_date.data)
            new_task.date = new_task.string_to_datetime(new_task.form.date.data)
            if new_task.to_date > new_task.date:
                new_task.add_multiple_tasks()
                flash("Your tasks are now live!", "success")
            else:
                return redirect(url_for("main.index", date_set="ph"))
        elif not new_task.form.to_date.data:
            task_to_be_added = new_task.add_single_task(
                date=new_task.string_to_datetime(new_task.form.date.data),
                frequency=new_task.form.frequency.data,
            )
            db.session.add(task_to_be_added)
            new_task.commit_flush()
            new_task.ident = task_to_be_added.id
            flash("Your task is now live!", "success")
        else:
            return redirect(url_for("main.index", date_set="ph"))
        return jsonify(
            {
                "minutes": new_task.minutes,
                "height": new_task.height,
                "task": new_task.form.task.data,
                "id": new_task.ident,
                "color": new_task.form.color.data,
                "frequency": new_task.form.frequency.data,
            }
        )
Example #22
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)
Example #23
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)
Example #24
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
Example #25
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)