def edit_task_in_list(request, storyID, taskID):
    story = mdl_story.get_story(storyID)
    task = mdl_task.get_task(taskID)
    project = story.project
    association = UserAssociation.objects.get(
        user=request.user,
        project=project
    )
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save(commit=True)
    else:
        form = TaskForm(instance=task)
    tasks = mdl_task.get_tasks_for_story(story)

    context = {
        'story': story,
        'tasks': tasks,
        'task': task,
        'editform': form,
        'project': project,
        'association': association
    }

    return render(request, 'TaskList.html', context)
Exemplo n.º 2
0
def addtask(request):
    if request.POST:
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Task added!')
            return HttpResponseRedirect('/tasks/')
    else:
        form = TaskForm()

    return render(request, 'addtask.html', locals())
Exemplo n.º 3
0
def add_task_into_list(request, storyID):
    story = mdl_story.get_story(storyID)
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            mdl_task.create_task(story, request.POST)
    else:
        form = TaskForm()
    tasks = mdl_task.get_tasks_for_story(story)
    context = {'story': story, 'tasks': tasks, 'newform': form}
    return render(request, 'TaskList.html', context)
Exemplo n.º 4
0
def calendar(request):
    if request.method == 'POST':
        c = Calendar.objects.all()[0]
        form = TaskForm(request.POST, Task())
        if form.is_valid():
            form.save()
            # create a new empty form
            form = TaskForm()
    else:
        form = TaskForm()
    return render_to_response('calendar.html',
                              RequestContext(request, {'form': form}))
Exemplo n.º 5
0
def edit_task(task_id):
    task = Task.query.get(task_id)
    if g.user.user_id != task.author_id:
        flash('You do not have proper authorization to do this!', 'danger')
        return redirect('/task/' + str(task_id))

    form = TaskForm(obj=task)
    if request.method == 'POST' and form.validate():
        form = TaskForm(request.form)
        form.populate_obj(task)
        task.save()
        return redirect(url_for('task', task_id=task.task_id))

    return render_template('task_form.html', form=form, edit=True)
Exemplo n.º 6
0
async def post_task(request):
    """ Uses for creating a task

    :param request: HTTP POST request
    :return: HTTP request
    """
    data = await request.post()
    form = TaskForm(data)
    if form.validate():
        task = Task(form.count.data, form.delta.data, form.start.data,
                    form.interval.data)
        task_queue.add_task(task)
        form = TaskForm()
        form.task_added = True
    return response(form)
Exemplo n.º 7
0
def tasks():
    form = TaskForm()

    if request.method == 'POST':

        task_details = request.form

        task_name = task_details['task_name']
        project = task_details['project']
        assignee = task_details['assignee']
        due_date = task_details['due_date']
        status = task_details['status']
        task_description = task_details['task_description']
        notag = re.sub("<.*?>", " ", task_description)

        cur = mysql.connection.cursor()
        cur.execute(
            "INSERT INTO `task`(`Task_Name`, `Task_description`, `Due_Date`, `Status`, `Project_Name`, `Assignee`) VALUES (%s, %s, %s, %s, %s, %s)",
            (task_name, notag, due_date, status, project, assignee))
        mysql.connection.commit()

        flash('Task added successfully!')
        cur.close()

        return redirect(url_for('tableList'))
    else:
        return render_template('task.html', form=form)
Exemplo n.º 8
0
def task_edit(task_id):
    if not current_user.is_authenticated:
        return is_not_auth()

    task = Task.get(Task.id == task_id)

    form = TaskForm(formdata=request.form, obj=task)

    if request.method == "GET":
        content = render_form(form=form,
                              action=url_for("task_edit", task_id=task_id),
                              button="Обновить")

        return render_content(content, "Редактировать - {}".format(task.title))

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        description = request.form['description']
        date = request.form['date']
        time = request.form['time']

        task.title = title
        task.description = description
        task.date = date
        task.user = current_user.id
        task.time = time
        task.save()

        flash('Задание <b><em>{}</em></b> успешно обновлено'.format(title),
              'success')
        return redirect(url_for('task_list'))
Exemplo n.º 9
0
def task_create():

    if not current_user.is_authenticated:
        return is_not_auth()

    form = TaskForm(request.form)

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        description = request.form['description']
        date = request.form['date']
        time = request.form['time']

        Task.create(title=title,
                    description=description,
                    date=date,
                    user=current_user.id,
                    time=time)

        flash('Задание успешно добавлено', 'success')
        return redirect(url_for('task_list'))

    content = render_form(form=form,
                          action=url_for("task_create"),
                          button="Создать")

    return render_content(content, "Создать задание")
Exemplo n.º 10
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")
Exemplo n.º 11
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")
Exemplo n.º 12
0
 def add_task_form():
     # returns a blank task_form to the gui
     form = TaskForm()
     form.volunteer_id.choices = get_volunteer_choices()
     return render_template('task_form.html',
                            form=form,
                            title="Add a New Task")
Exemplo n.º 13
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)
Exemplo n.º 14
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', ''))
Exemplo n.º 15
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")
Exemplo n.º 16
0
async def new_task(request):
    if request.method == 'POST':
        payload = await request.post()
        task_form = TaskForm(payload)
        if task_form.validate():
            task = Task(
                n=task_form.n.data,
                d=task_form.d.data,
                n1=task_form.n1.data,
                interval=task_form.interval.data,
            )
            await request.app['queue'].put(task)
            raise web.HTTPFound(request.app.router['tasks_list'].url_for())
    else:
        task_form = TaskForm()
    return {'request': request, 'form': task_form}
Exemplo n.º 17
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')
Exemplo n.º 18
0
def create_task(project_key):
    form = TaskForm(request.form)
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    current_user_id = get_user(request, project_key)
    if current_user_id is None:
        return redirect(url_for('who_are_you', project_key=project_key))
    choices = [(p.id, p.name) for p in project.people]
    form.assigned_to.choices = choices
    if request.method == 'POST' and form.validate():
        title = form.title.data
        description = form.description.data
        priority = form.priority.data
        assigned_to = form.assigned_to.data
        Task.new(project.key, title, priority, current_user_id, assigned_to,
                 description)
        flash("Your task was created")
        project.touch()
        return redirect('/project/' + project_key)
    else:
        assigned_to = current_user_id
        form.assigned_to.default = current_user_id
        form.process()
    return render_template('edit_task.html',
                           form=form,
                           project=project,
                           assigned_to=assigned_to)
Exemplo n.º 19
0
def taskupdate():
    if 'userid' in session:
        user = User.query.get_or_404(session['userid'])
        if request.method == 'POST':
            updateform = TaskUpdateForm(request.form)
            if updateform.validate():
                task = Task.query.get_or_404(updateform.taskid.data)
                if task.userid == user.id:
                    # update fields
                    task.title = updateform.title.data
                    task.value = updateform.value.data
                    #task.datedue = updateform.datedue.data
                    db.session.commit()
                return redirect(url_for('tasks'))
            else:
                tasks = user.tasks.filter(Task.complete == False).order_by(
                    desc(Task.dateadded)).all()
                return render_template('tasks.html',
                                       username=user.username,
                                       points=user.points,
                                       tasks=tasks,
                                       form=TaskForm(),
                                       idform=TaskIdForm(),
                                       updateform=updateform,
                                       containerclass="listcontainer")
        else:
            return redirect(url_for('tasks'))
    else:
        return redirect(url_for('front'))
Exemplo n.º 20
0
async def index(request):
    """ Represents main web page

    :param request: HTTP request
    :return: HTTP response
    """
    return response(TaskForm())
Exemplo n.º 21
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)
Exemplo n.º 22
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)
Exemplo n.º 23
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")
Exemplo n.º 24
0
def worksheet(week_id=None):
    """Main route of the one-page site."""
    week = ''
    week_list = Week.query.all()
    interruption = ''
    goals = ''
    tasks = ''
    review = ''

    task_form = TaskForm()
    goal_form = GoalForm()
    interruption_form = InterruptionForm()
    review_form = ReviewForm()

    if week_id:
        interruption = Interruption.query.filter_by(week_id=week_id).all()
        goals = Goal.query.filter_by(week_id=week_id).all()
        tasks = Tasks.query.filter_by(week_id=week_id).all()
        review = Review.query.filter_by(week_id=week_id).all()
        week = Week.query.get(week_id)
    return render_template('base.html',
                           week=week,
                           week_list=week_list,
                           interruptions=interruption,
                           interruption_form=interruption_form,
                           goals=goals,
                           goal_form=goal_form,
                           tasks=tasks,
                           task_form=task_form,
                           review=review,
                           review_form=review_form)
Exemplo n.º 25
0
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'))
Exemplo n.º 26
0
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))
Exemplo n.º 27
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="Редактировать задачу")
Exemplo n.º 28
0
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")
Exemplo n.º 29
0
    def update_task_submission(task_id):
        # updates the task having id = task_id and returns the updated task
        # to the gui  Use route /tasks/task_id method='patch'to return the
        # task to the api
        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 ' + request.form['title'] + ' could not be updated be'
                  'cause one or more fields'
                  ' were invalid:')
            for field, message in form.errors.items():
                flash(field + ' ' + message[0])
            task = form.data
            task['id'] = task_id
            return render_template('task_form.html',
                                   form=form,
                                   task=task,
                                   title="Update Task")

        # form is valid
        # form.volunteer_id.data will = 0 when no volunteer is selected but
        # since 0 is not an id in the volunteer database, it throws a
        # ForeignKeyViolation error.  The only way I found around this error
        # is to set a local variable that is not in the form to 'None' and then
        # overlay the form value with the local variable after the
        # form.populate_obj statement.  Changing volunteer_id.data to 'None'
        # did not have any effect.
        volunteer_id = form.volunteer_id.data
        if volunteer_id == 0:
            volunteer_id = None
        try:
            task = Task.query.get(task_id)
            form = TaskForm(obj=task)
            form.populate_obj(task)
            task.volunteer_id = volunteer_id
            task.update()
        except Exception as e:
            flash('Task ' + request.form['title'] + ' could not be updated')
            print('422 error', e)
            abort(422)

        flash('Task ' + task.title + ' was successfully updated')
        return redirect('/tasks')
Exemplo n.º 30
0
def setupb(request, userid):
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            a = form.cleaned_data['task']
            b = form.cleaned_data['deadline']
            c = form.cleaned_data['list']
            d = userid
            new = Task.objects.create(task=a, deadline=b, user_id=d)
            new.save()

            return redirect("setupb", d)
    else:
        form = TaskForm()
    data = {'form': form}

    return render(request, 'setupb.html', data)