Beispiel #1
0
def tasks():
    # imported our TaskForm class, instantiated an object from it,
    #and sent it down to the template where forms is used.
    form = TaskForm(request.form)
    tasks = Task.query.all()
    # for task in tasks:
    # 	db.session.delete(task)
    # db.session.commit()

    if request.method == 'POST' and form.validate_on_submit():
        flash('Created Async Task!')
        #save numberOfSeconds in a session hash
        session['numberOfSeconds'] = form.numberOfSeconds.data
        time = int(session['numberOfSeconds'])
        #START OF ASYNC SLEEP CALL#
        t1 = start_sleep.delay(time)
        session['TASK_ID'] = t1.id
        #add new async task to database
        new_task = Task(time=int(session['numberOfSeconds']),
                        status=t1.ready(),
                        key=session['TASK_ID'])
        db.session.add(new_task)
        db.session.commit()
        return redirect(url_for('tasks'))
    return render_template('tasks.html',
                           title='Amadeus Task',
                           form=form,
                           tasks=tasks)
Beispiel #2
0
def edit_task(id):
    """
    Edit a task
    """
    check_admin()

    add_task = False

    task = Task.query.get_or_404(id)
    form = TaskForm(obj=task)
    if form.validate_on_submit():
        task.name = form.name.data
        task.description = form.description.data
        task.status = form.status.data
        task.importance = form.importance.data
        task.towhom = form.towhom.data
        db.session.commit()
        flash('You have successfully edited the department.')

        # redirect to the taskshowall page
        return redirect(url_for('admin.list_task'))

    form.description.data = task.description
    form.name.data = task.name
    form.status.data = task.status
    form.importance.data = task.importance
    form.towhom.data = task.towhom
    return render_template('admin/task/task.html',
                           action="Edit",
                           add_task=add_task,
                           form=form,
                           task=task,
                           title="Edit Task")
Beispiel #3
0
    def add_task_submission():
        # adds a new task with data from task_form and redirects to the
        # dashboard
        form = TaskForm()
        form.volunteer_id.choices = get_volunteer_choices()

        if not form.validate_on_submit():
            # if the form has errors, display error messages and resend the
            # current page
            flash('Task could not be created because one or more data fields'
                  ' were invalid:')
            for field, message in form.errors.items():
                flash(message[0])
            return render_template('task_form.html',
                                   form=form,
                                   title="Add a New Task")

        # the form is valid
        # note volunteer_id cannot be entered when adding a task
        title = request.form['title']
        details = request.form['details']
        date_needed = request.form['date_needed']
        status = request.form['status']

        new_task = Task(title, details, date_needed, status)
        try:
            new_task.insert()
            flash('Task ' + title + ' was successfully created')
        except Exception as e:
            print('Error!', sys.exc_info())
            flash('An error occurred.  The Task could not be created')
            abort(422)

        return redirect('/dashboard')
def create_task():
    form = TaskForm()
    cell_list = Cell.query.order_by(Cell.name).all()
    for field in form.cells.entries:
        field.choices = [(cell.id, "{} ({})".format(cell.name, cell.cell_type))
                         for cell in cell_list]

    if form.validate_on_submit():
        if Task.query.filter_by(name=form.name.data).first():
            flash('A task with this name already exists.', 'danger')
        else:
            cell_ids = []
            for field in form.cells.entries:
                if field.data in cell_ids:
                    flash('You cannot add a cell to a task twice.', 'danger')
                    return render_template('task.html',
                                           form=form,
                                           action=url_for('nbg.create_task'))
                cell_ids.append(field.data)
            task = Task(form.name.data, form.short.data)
            task.description = form.description.data
            for idx, field in enumerate(form.cells.entries):
                task_cell = TaskCell(position=idx)
                task_cell.cell = Cell.query.filter_by(id=field.data).first()
                task.cells.append(task_cell)
            db.session.add(task)
            db.session.commit()
            flash('Task created', 'success')
            return redirect(url_for('nbg.list_tasks'))

    return render_template('task.html',
                           form=form,
                           action=url_for('nbg.create_task'))
Beispiel #5
0
def add_task():
    """
    Add a task to the database
    """
    check_admin()

    add_task = True

    form = TaskForm()
    if form.validate_on_submit():
        task = Task(name=form.name.data,
                    description=form.description.data,
                    status=form.status.data,
                    importance=form.importance.data,
                    towhom=form.towhom.data)
        try:
            # add task to the database
            db.session.add(task)
            db.session.commit()
            flash('You have successfully added a new Task.')
        except:
            # in case task name already exists
            flash('Error: task name already exists.')

        # redirect to tasks_showall page
        return redirect(url_for('admin.list_task'))

    # load tasks template
    return render_template('admin/task/task.html',
                           action="Add",
                           add_task=add_task,
                           form=form,
                           title="Add Task")
Beispiel #6
0
def task_update(link):
    if not current_user.is_admin:
        flash(f'You are not allowed to edit tasks.', 'error')
        return redirect(url_for('index'))

    task = Task.query.filter(Task.link == link).first()

    if not task:
        flash('task not found', 'warning')
        return redirect(url_for('tasks.index'))

    form = TaskForm()

    if form.validate_on_submit():
        task.title = form.title.data
        task.content = form.content.data
        task.is_active = form.is_active.data
        db.session.commit()
        flash('Task has been updated.', 'success')
        return redirect(url_for('tasks.task_details', link=task.link))

    if request.method == 'GET':
        form.title.data = task.title
        form.content.data = task.content
        form.is_active.data = task.is_active

    return render_template('tasks/new.html', title='Update Task', form=form)
Beispiel #7
0
def index():
	form = TaskForm()
	if form.validate_on_submit(): 
		r.table('todos').insert({"name":form.label.data}).run(g.rdb_conn)
		return redirect(url_for('index'))
	selection = list(r.table('todos').run(g.rdb_conn))
	return render_template('index.html', form = form, tasks = selection)
Beispiel #8
0
def index():
        form = TaskForm()
        if form.validate_on_submit(): 
                r.table('todos').insert({"name":form.label.data}).run(g.rdb_conn)
                return redirect(url_for('index'))
        selection = list(r.table('todos').run(g.rdb_conn))
        return render_template('index.html', form = form, tasks = selection)
def edit_task(task_id):
    task = Task.query.get_or_404(task_id)
    form = TaskForm(obj=task)
    cell_list = Cell.query.order_by(Cell.name).all()
    for idx, field in enumerate(form.cells.entries):
        field.choices = [(cell.id, "{} ({})".format(cell.name, cell.cell_type))
                         for cell in cell_list]
        if request.method == 'GET':
            field.data = task.cells[idx].cell.id if len(
                task.cells) > idx else None
    if form.validate_on_submit():
        if form.name.data != task.name and Task.query.filter_by(
                name=form.name.data).first():
            flash('A task with this name already exists.', 'danger')
        else:
            task.name = form.name.data
            task.description = form.description.data
            task.short = form.short.data
            for task_cell in task.cells:
                db.session.delete(task_cell)
            for idx, field in enumerate(form.cells.entries):
                task_cell = TaskCell(position=idx)
                task_cell.cell = Cell.query.filter_by(id=field.data).first()
                task.cells.append(task_cell)
            db.session.commit()
            flash('Saved changes', 'success')
    return render_template('task.html',
                           form=form,
                           task=task,
                           action=url_for('nbg.edit_task', task_id=task_id))
Beispiel #10
0
def add_task():
    form = TaskForm()
    form.author.choices = [(u.id, u.username) for u in User.query.all()]
    if form.validate_on_submit():
        t = Task(
            task=form.name.data,
            description=form.description.data.replace('\r\n', '\n'),
            category=form.category.data,
            points=form.points.data,
            link=form.link.data or None,
            flag=form.flag.data,
            is_hidden=form.is_hidden.data
        )
        for user_id in form.author.data:
            author = User.query.get(user_id)
            t.authors.append(author)
            author.points += t.points
        db.session.add(t)
        db.session.commit()
        for file in request.files.getlist('files'):
            filename = secure_filename(file.filename)
            base_dir = (Path(app.static_folder) / f'files/tasks/{t.id}').resolve()
            base_dir.mkdir(parents=True, exist_ok=True)
            file.save(str(base_dir / filename))
            db_file = TaskFiles(file=filename)
            db.session.add(db_file)
            t.files.append(db_file)
        db.session.add(Event.NEW_TASK.trigger(task_id=t.id))
        db.session.commit()
        flash('Таск добавлен!', 'success')
        return redirect(url_for('task', task_id=t.id))
    return render_template('admin_task.html', form=form, new=True,
                           flag_pattern=app.config.get('FLAG_REGEXP', ''))
def add_task():
    """
    Add a department to the database
    """
    check_admin()

    add_task = True

    form = TaskForm()
    if form.validate_on_submit():
        task = Task(name=form.name.data, description=form.description.data)
        try:
            # add department to the database
            db.session.add(task)
            db.session.commit()
            flash('You have successfully added a new department.')
        except:
            # in case department name already exists
            flash('Error: department name already exists.')

        # redirect to departments page
        return redirect(url_for('admin.list_departments'))

    # load department template
    return render_template('admin/task/task.html',
                           action="Add",
                           add_task=add_task,
                           form=form,
                           title="Add Task")
Beispiel #12
0
def edit_task(id):
    """
    Edit a task
    """
    # check_admin()

    add_task = False

    task = Task.query.get_or_404(id)
    form = TaskForm(obj=task)
    if form.validate_on_submit():
        task.name = form.name.data
        task.description = form.description.data
        db.session.add(task)
        db.session.commit()
        flash('You have successfully edited the task.')

        # redirect to the roles page
        return redirect(url_for('home.list_tasks', id=id))

    form.taskdescription.data = task.description
    form.taskname.data = task.taskname
    return render_template('home/tasks/addedittask.html',
                           add_task=add_task,
                           form=form,
                           title="Edit Task")
Beispiel #13
0
def add_task(id):
    """
    Add a Task
    """

    add_event = True

    event = Event.query.get_or_404(id)
    # tasks = Task.query.get_or_404(id)
    form = TaskForm()
    if form.validate_on_submit():
        task = Task(taskname=form.taskname.data,
                    description=form.taskdescription.data,
                    listeventid=id,
                    taskowner=event)

        try:
            # add role to the database
            db.session.add(task)
            db.session.commit()
            flash('You have successfully added a new task.')
        except:
            # in case role name already exists
            flash('Error: task name already exists.')

        return redirect(url_for('home.eventdashboard', id=id, task=task))

    return render_template('admin/events/addeditevent.html',
                           action="Edit",
                           add_event=add_event,
                           form=form,
                           event=event,
                           title="Add Task")
Beispiel #14
0
def edit_task(t_id):
    task, tags = get_task(t_id)
    form = TaskForm(name=task['name'],
                    statement=task['statement'],
                    short_statement=task['short_statement'],
                    todo=task['todo'],
                    tutorial=task['tutorial'],
                    complexity=task['complexity'],
                    source=task['source'])

    form.set_choices()

    if form.validate_on_submit():
        d = _to_dict(form)
        d['tags'] = [t['tag'] for t in d['tags']]
        update_task(d, t_id)
        return redirect(url_for('render_task', t_id=t_id))

    if tags != []:
        form.tags.pop_entry()

        for tag in tags:
            t = Tag()
            t.set_choices()
            t.tag = tag['id']
            t.csrf_token = form.csrf_token
            form.tags.append_entry(t)

    form.set_choices()

    return render_template(form.template,
                           form=form,
                           name="Редактировать задачу")
Beispiel #15
0
def tasks():
	# imported our TaskForm class, instantiated an object from it,
	#and sent it down to the template where forms is used.
	form = TaskForm(request.form)
	tasks = Task.query.all()
	# for task in tasks:
	# 	db.session.delete(task)
	# db.session.commit()

	if request.method == 'POST' and form.validate_on_submit():
		flash('Created Async Task!')
		#save numberOfSeconds in a session hash
		session['numberOfSeconds'] = form.numberOfSeconds.data
		time = int(session['numberOfSeconds'])
		#START OF ASYNC SLEEP CALL#
		t1 = start_sleep.delay(time)
		session['TASK_ID'] = t1.id
		#add new async task to database
		new_task = Task(time = int(session['numberOfSeconds']),status= t1.ready(),key =session['TASK_ID'])
		db.session.add(new_task)
		db.session.commit()
		return redirect(url_for('tasks'))
	return render_template('tasks.html',
					title = 'Amadeus Task', 
					form = form,
					tasks = tasks)
def index():
	form = TaskForm()
	if form.validate_on_submit(): # if it is a POST request
		task = Task(label = form.label.data)
		task.save()
		return redirect(url_for('index'))
	
	tasks = Task.objects.all()
	return render_template('index.html', form = form, tasks = tasks)
Beispiel #17
0
def add_task():
    errors = ""
    task = TaskForm()
    if request.method == "POST":
        # 判断一个是否是有效的post请求
        if task.validate_on_submit():
            form_data = task.data
        else:
            errors = task.errors
    return render_template("add_task.html", **locals())
Beispiel #18
0
def add_task():
    errors = ""
    task = TaskForm()
    if request.method == "POST":
        if task.validate_on_submit():
            formData = task.data
        else:
            errors_list = list(task.errors.keys())
            errors = task.errors
            print(errors)
    return render_template("add_task.html", **locals())
Beispiel #19
0
def edit_task(task_id=None):
    model = get_object_or_404(Task, Task.id == task_id)
    form = TaskForm(obj=model)

    if form.validate_on_submit():
        form.populate_obj(model)
        db.session.add(model)
        db.session.commit()
        flash('Task updated', category='success')
        return redirect(url_for('admin'))
    return render_template('edit_task.html', task=model, form=form)
Beispiel #20
0
def index(id=None):
    form = TaskForm()
    if form.validate_on_submit(): 
        # Create document
        task =  {  "_id" :  form.id.data , "title": form.title.data , "status": "Open" }
        document_to_save = connection.new_document(dictionary=task)
        todos_table.insert_or_replace(doc=document_to_save)
        return redirect(url_for('index'))

    open_todos_query = {'$select': ['*'] }
    query_result = todos_table.find( open_todos_query , options=options)
    return render_template('index.html', form = form, tasks = query_result)
Beispiel #21
0
def post_task():
    form = TaskForm()
    if form.validate_on_submit():
        title = form.title.data
        description = form.description.data
        current_user.tasks.append(Task(title=title, description=description))
        db.session.add(current_user)
        db.session.commit()
        return redirect(url_for('user_profile',
                                username=current_user.username))
    tasks = Task.query.all()
    return render_template('tasks.html', form=form, tasks=tasks)
Beispiel #22
0
def todo_add(*args, **kwargs):
    user = kwargs.get('user')
    form=TaskForm()
    if form.validate_on_submit():
        field_content = form.content.data
        field_status = int(form.status.data)
        task = Task(content=field_content, status=field_status, user_id=user.id)
        db.session.add(task)
        db.session.commit()
        flash('Task has been added!')
        return redirect(url_for('todo_list'))

    return render_template('todo/add.html', form=form, title="Add Task | TodoApp")
Beispiel #23
0
def add_task():
    form = TaskForm(request.form)
    if form.validate_on_submit():
        task = mongo.db.tasks
        task.insert_one({
            'name': request.form['name'],
            'description': request.form['description'],
            'due_day': request.form['due_day'],
            'important': request.form.get('important'),
        })
        return redirect(url_for('all_tasks',
                                title='You\'re back to main list'))
    return render_template('add_task.html', title='Add task', form=form)
Beispiel #24
0
def add_task():
    task = TaskForm()
    if request.method == "POST":
        if task.validate_on_submit():  # 有效的post请求
            from_data = task.data  # 校验成功

            time = from_data.get("time")
            public = from_data.get("public")
            description = from_data.get("description")
            name = from_data.get("name")
        else:
            error = task.errors  # 校验失败
            print(error)
    return render_template("add_task.html", **locals())
Beispiel #25
0
def task_create():
    if not g.user.is_authenticated:
        return redirect(url_for('index'))

    form = TaskForm(request.form)
    if request.method == 'GET':
        return render_template('task.html', form=form, form_action="/task")

    if form.validate_on_submit():
        Task.create(user=g.user.get_id(),
                    text=form.text.data,
                    deadline_date=form.date.data)
        return redirect(url_for('index'))
    return render_template('task.html', form=form, form_action="/task")
Beispiel #26
0
def todo_list(*args, **kwargs):
    user = kwargs.get('user')
    task_list = Task.query.filter_by(user_id=user.id).all()
    return render_template('todo/list.html', data_list=task_list, title="Ta Do List | TodoApp"
    

@app.route('/todos/edit/<int:id>', methods=['GET', 'POST'])
@login_required
def todo_edit(*args, **kwargs):
    user = kwargs.get('user')
    id = kwargs.get('id')
    current_task = Task.query.get_or_404(id)
    form = TaskForm(
        content=current_task.content,
        status=current_task.status
    )
    if form.validate_on_submit():
        current_task.content = form.content.data
        current_task.status = form.status.data
        db.session.add(current_task)
        db.session.commit()
        flash('Your Task has been updated!')
        return redirect(url_for('todo_list'))
    return render_template('todo/add.html', form=form, title='Edit Task | TodoApp')


@app.route('/todos/delete/<int:id>', methods=['GET','POST'])
def todo_delete(*args, **kwargs):
    id = kwargs.get('id')
    current_task = Task.query.get_or_404(id)
    form = DeleteForm()
    if form.validate_on_submit():
        db.session.delete(current_task)
        db.session.commit()
        flash('Your Task has been deleted!')
        return redirect(url_for('todo_list'))
    return render_template('todo/del.html', form=form, title='Delete Task | TodoApp')
def add_task():
    print('add_task')
    form = TaskForm()
    print(form.validate_on_submit())
    print(request.method)
    if request.method == 'POST' and form.validate_on_submit():
        if current_user.id is None:
            abort(404)
        user = genmai.query.filter_by(id=current_user.id).first()
        if user is None:  # 因为没有设置外建,所以这里一定要去查询一下
            abort(404)

        # TODO: 检测一下输入是否合法
        if test_inject_sql_username_string(
                request.form['asin']) and test_inject_sql_username_string(
                    request.form['seller']):
            flash('不合法的输入,请勿尝试注入')
            return redirect('/')

        new_task = genmai_tasks(user_id=user.id,
                                asin=request.form['asin'],
                                country=request.form['country'],
                                seller=request.form['seller'],
                                youxian=request.form['youxian'])
        db.session.add(new_task)
        db.session.commit()

        print(current_user.id)
        print(current_user.username)
        print(request.form)
        print(request.form['asin'])
        print(request.form['country'])
        print(request.form['seller'])
        print(request.form['youxian'])
        return redirect(url_for('targets'))
    else:
        abort(404)
Beispiel #28
0
def goaltree(goalid):

    me = User.objects(id=g.user.id).first()
    goal = Goal.objects(id=goalid).first()
    tasks = Task.objects(goal=goalid).order_by('-end')

    form = TaskForm()
    if form.validate_on_submit():
        task = Task(goal=goal,
                    name=form.name.data,
                    description=form.description.data,
                    end=form.end.data,
                    people=[me])
        task.save()

        feeditem = TaskRequest(
            message='A task was added to a goal you are working on',
            user=me,
            task=task,
            goal=goal)

        for person in goal.people:
            if person != me:
                person.feed.append(feeditem)
                person.save()

        return redirect(url_for('goaltree', goalid=goalid))

    megacounts = {}
    for person in goal.people:
        counts = {'active': [], 'completed': [], 'missed': []}

        for task in tasks:
            if person in task.people:
                counts['active'].append(task)
            if person in task.completed:
                counts['completed'].append(task)
            if person in task.missed:
                counts['missed'].append(task)

        megacounts[person.id] = counts

    return render_template('goaltreelite.html',
                           me=me,
                           goal=goal,
                           tasks=tasks,
                           today=datetime.datetime.now(),
                           form=form,
                           allCounts=megacounts)
Beispiel #29
0
def todo_edit(*args, **kwargs):
    user = kwargs.get('user')
    id = kwargs.get('id')
    current_task = Task.query.get_or_404(id)
    form = TaskForm(content=current_task.content, status=current_task.status)
    if form.validate_on_submit():
        current_task.content = form.content.data
        current_task.status = form.status.data
        db.session.add(current_task)
        db.session.commit()
        flash('Your Task has been updated!')
        return redirect(url_for('todo_list'))
    return render_template('todo/add.html',
                           form=form,
                           title='Edit Task | TodoApp')
Beispiel #30
0
def new_task():
    form = TaskForm()
    if form.validate_on_submit():
        task = Task(title=form.title.data,
                    lastdate=form.lastdate.data,
                    note=form.note.data,
                    author=current_user)
        db.session.add(task)
        db.session.commit()
        flash("Task Added", 'success')
        return redirect(url_for('tasks'))
    return render_template("create_task.html",
                           title="New Task",
                           form=form,
                           legend='Add')
Beispiel #31
0
def add_task():
    form = TaskForm()
    c_id = request.args.get('c_id', None)

    form.set_choices()

    if form.validate_on_submit():
        d = _to_dict(form)
        d['c_id'] = c_id
        form.add(d)
        if c_id != None:
            return redirect(url_for('render_contest', c_id=c_id))
        else:
            return redirect(url_for('table_tasks'))

    return render_template(form.template, form=form, name="Add task")
Beispiel #32
0
def newTask():
    form = TaskForm()
    if form.validate_on_submit():
        task = taskDB()
        task.user_id = current_user.id
        task.title = form.title.data.strip()
        task.note = form.note.data.strip()
        task.status = 'todo'
        task.duration = form.duration.data
        task.start_time = form.start_time.data.strip()
        task.finish_time = finishTime(form.start_time.data.strip(),
                                      form.duration.data)
        db.session.add(task)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('newtask.html', form=form, today=present_date)
Beispiel #33
0
def new():
    if not current_user.is_admin:
        flash(f'You are not allowed to add tasks.', 'error')
        return redirect(url_for('index'))

    form = TaskForm()
    if form.validate_on_submit():
        task = Task(title=form.title.data,
                    content=form.content.data,
                    is_active=form.is_active.data,
                    author=current_user)
        db.session.add(task)
        db.session.commit()
        flash('Task has been created!', 'success')
        return redirect(url_for('tasks.task_details', link=task.link))
    return render_template('tasks/new.html', title='New Task', form=form)
Beispiel #34
0
def task(id_project, id_task=None):
    project = Project.query.get(id_project)
    
    from forms import TaskForm
    if id_task != None:
        task = task.query.get(id_task)
        action = "Save"
    else:
        task = Task()
        action = "Add"
        
    form = TaskForm(obj=task)
    if form.validate_on_submit():
        form.populate_obj(task)
        db.session.add(task)
        db.session.commit()
        return redirect('/tasks')
    
    return render_template('project/task/form.html', form=form, action=action, project=project)
Beispiel #35
0
def add():
    # Create a new chore form
    form = TaskForm()

    # Check for a POST and validate the form data
    if form.validate_on_submit():
        # Create a new chore with the current user as the parent
        newTask = Task(parent=ndb.Key("User", users.get_current_user().email()))

        # Fill in the details and insert it into the database
        newTask.name = form.name.data
        newTask.description = form.description.data
        newTask.points = form.points.data
        newTask.point_type = form.point_type.data
        newTask.put()

        # Automatically redirect the user to the chore list
        return redirect(url_for('.list'))

    # If not POSTing then display the default new chore form
    return render_template('tasks/new_task.html', form=form)
Beispiel #36
0
def create_tasks(record_id=False, **post):
    user = False
    project_id = request.args.get('project_id', 0, type=int)
    form = TaskForm()
    if project_id:
        form.project_id.data = project_id
    state = request.args.get('state', '', type=str)
    if project_id:
        form.state.data = state
    if form.validate_on_submit():
        values = {
            'name': form.name.data,
            'description': form.description.data,
            'color': form.color.data,
            'date': form.date.data,
            'user_id': form.user_id.data,
            'project_id': form.project_id.data,
            'date_deadline': form.date_deadline.data,
            'state': form.state.data
        }
        if record_id:
            table_registry.tasks.write([record_id], values)
        else:
            table_registry.tasks.create(values)
        return json.dumps({'redirect': url_for('tasks') + '/' + str(form.project_id.data)})
    elif record_id:
        project_data = table_registry.tasks.search_read([['id', '=', record_id]])[0]
        form.name.data = project_data['name']
        form.description.data = project_data['description']
        form.color.data = project_data['color']
        form.date.data = project_data['date'].strftime('%m/%d/%Y %I:%M %p')
        form.date_deadline.data = project_data['date_deadline'].strftime('%m/%d/%Y %I:%M %p')
        form.project_id.data = project_data['project_id']._get()['id']
        user = project_data['user_id']._get()
        form.user_id.data = user['id']
        form.state.data = project_data['state']

    return render_template('backend/task_model.html', form=form, record_id=record_id and str(record_id), user_name=user and user['name'] or "")
Beispiel #37
0
def goaltree(goalid):

    me = User.objects(id = g.user.id).first()
    goal = Goal.objects(id = goalid).first()
    tasks = Task.objects(goal = goalid).order_by('-end')

    form = TaskForm()
    if form.validate_on_submit():
        task = Task(goal=goal,name = form.name.data, description = form.description.data, end = form.end.data, people = [me])
        task.save()
    
        feeditem = TaskRequest(message='A task was added to a goal you are working on',user=me,task=task,goal=goal) 

        for person in goal.people:
            if person != me:
                person.feed.append(feeditem)
                person.save()

        return redirect(url_for('goaltree',goalid=goalid))

    megacounts = {}
    for person in goal.people:
        counts = {'active':[],'completed':[],'missed':[]}

        for task in tasks:
            if person in task.people:
                counts['active'].append(task)
            if person in task.completed:
                counts['completed'].append(task)
            if person in task.missed:
                counts['missed'].append(task)

        megacounts[person.id] = counts


    return render_template('goaltreelite.html',me = me, goal = goal, tasks = tasks, today = datetime.datetime.now(), form = form, allCounts=megacounts)