Beispiel #1
0
def task():
	form = TaskForm()
	if request.method == "POST":
		if form.validate() == False:
			flash("All fields are required")
			return render_template("task.html",form=form)
		else:
			
			task_name = form.name.data
			task_client = form.client.data
			task_capabilities = form.capabilities.data
			task_duration = int(form.duration.data)
			#insert values to Task table
				
			task_msg = task_insert(task_name,task_client,task_capabilities,task_duration)
				
                         
			
			return jsonify(name =task_name,
					client=task_client, 
					capabilities=task_capabilities,
					duration=task_duration,result = task_msg)
			#return render_template("success.html",form=form)
	elif request.method == 'GET':
		return render_template("task.html",form=form)
Beispiel #2
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'))
Beispiel #3
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)
Beispiel #4
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, "Создать задание")
Beispiel #5
0
def new_task():
    form = TaskForm(request.form)
    if request.method == 'POST' and form.validate():
        task = Task(form.name.data, form.text.data, form.memory.data, form.time_limit.data, g.user)
        task.save()
        return redirect(url_for('task', task_id=task.task_id))

    return render_template('task_form.html', form=form)
Beispiel #6
0
def new_task():
    form = TaskForm(request.form)
    if request.method == 'POST' and form.validate():
        task = Task(form.name.data, form.text.data, form.memory.data,
                    form.time_limit.data, g.user)
        task.save()
        return redirect(url_for('task', task_id=task.task_id))

    return render_template('task_form.html', form=form)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
0
def add_task():
    form = TaskForm(request.form)
    nowdate=datetime.now()
    if request.method == 'POST' and form.validate():
          task = Task(form.content.data,form.deadline.data)
          if not form.assign.data:
             assignlist = AssignList(user=g.user.username)
             task.assignlist.append(assignlist)
          else:
             for user in form.assign.data.split():
                 assignlist = AssignList(user=user)
                 task.assignlist.append(assignlist)
          task.save()
          return redirect('/task/pending')
    return render_template('add.html', form=form,nowdate=nowdate)
Beispiel #11
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}
Beispiel #12
0
def tasks():
	
	if 'userid' in session:	
		user = User.query.get_or_404(session['userid'])	
		
		if request.method == 'POST':
			form = TaskForm(request.form)
			if form.validate():
				newtask = Task(form.title.data, user, None, form.value.data)
				db.session.add(newtask)
				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=form, idform=TaskIdForm(), updateform=TaskUpdateForm(), containerclass="listcontainer")

		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=TaskUpdateForm(), containerclass="listcontainer")
	# if no session, display default home page. TODO: convert to splash page
	else:
		return redirect(url_for('front'))
Beispiel #13
0
def edit_task(project_key, task_key):
    form = TaskForm(request.form)
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    choices = [(p.id, p.name) for p in project.people]
    form.assigned_to.choices = choices
    if request.method == 'POST' and form.validate():
        flash("Task was updated")
        task.update(form.title.data, int(form.priority.data),
                    form.description.data, form.assigned_to.data)
        return redirect(
            url_for('view_task', project_key=project_key, task_key=task_key))
    form.title.data = task.title
    form.priority.data = str(task.priority)
    form.description.data = task.description
    form.assigned_to.data = task.assigned_to
    return render_template('edit_task.html',
                           task=task,
                           project=project,
                           form=form)
Beispiel #14
0
def tasks():

    if 'userid' in session:
        user = User.query.get_or_404(session['userid'])

        if request.method == 'POST':
            form = TaskForm(request.form)
            if form.validate():
                newtask = Task(form.title.data, user, None, form.value.data)
                db.session.add(newtask)
                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=form,
                                       idform=TaskIdForm(),
                                       updateform=TaskUpdateForm(),
                                       containerclass="listcontainer")

        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=TaskUpdateForm(),
                                   containerclass="listcontainer")
    # if no session, display default home page. TODO: convert to splash page
    else:
        return redirect(url_for('front'))
Beispiel #15
0
def edit_task(task_id):
    form=TaskForm(request.form)
    task=Task.objects(id=ObjectId(task_id)).first()
    namelist=[]
    for i in task.assignlist:
        namelist.append(i.user)
    namelist=" ".join(namelist)
    if request.method == 'POST' and form.validate():
        task.content=form.content.data
        task.deadline=form.deadline.data
        task.assignlist=[]
        recipients=[]
        if not form.assign.data:
           task.assignlist.append(AssignList(user=g.user.username))
        else:
           for user in form.assign.data.split():
               if User.objects(username=user):
                   assign = AssignList(user=user)
                   task.assignlist.append(assign)
        task.save()
        
        return redirect('/task/pending')
    return render_template('edit.html', form=form, task=task,task_id=task_id,namelist=namelist)
Beispiel #16
0
def task():
    page = request.args.get("page")
    
    if 'username' not in session:
        flash("No User Logged in", "warning")
        return render_template("login.html")
    form = TaskForm(request.form)
    if request.method == 'POST' and form.validate() and form.validate_end_date(form.end_date) and form.validate_sheet_url(form.sheet_url)  and form.validate_sheet_name(form.sheet_url):
        # function created by me to validate the enddate (enddate > startdate)

        new_task = Tasks(
            name=form.name.data,
            description=form.description.data,

            start_date=form.start_date.data,
            end_date=form.end_date.data,
            sheet_name=form.sheet_name.data,
            sheet_url=form.sheet_url.data,
            created_by=session["username"],
            status=Status.PE,
            bot_assigned=form.bot_assigned.data
        )

        db.session.add(new_task)
        db.session.commit()
        
        
        
        # schedule the bot here
        
       
        bot_name = str(new_task.bot_assigned.split(" ")[0])
        trigger_name = new_task.sheet_name +"_"  + str(new_task.id)
        stop_date = new_task.end_date.strftime("%Y-%m-%d")  
        
        print(bot_name)
        
        
        # parameters to be passed to the bot while scheduling
        
        
        start_date = new_task.start_date.strftime("%Y-%m-%d") 
        sheet_uri = new_task.sheet_url
        faculty_mail_id = session['email_address']
        task_id = new_task.id
        sheet = new_task.sheet_name
        curr_hour = datetime.datetime.now().today().hour 
        
        input_args = {
            
            "start_date": start_date,
            "end_date": stop_date,
            "sheet_url": sheet_uri,
            "task_id": task_id,
            "sheet": sheet,
            "faculty_mail_id": faculty_mail_id
            
            
            
        }
    
       
              
        if  "excel"  in str(new_task.bot_assigned).lower(): 
            
            long_running = True
            
        if "document" in str(new_task.bot_assigned).lower() or "synopsis" in  str(new_task.bot_assigned).lower():
            
            long_running = False
            
        
        schedule_tasks(bot_name =bot_name,trigger_name = trigger_name,input_arguments= input_args,curr_hour = curr_hour ,stop_date = stop_date,long_running =long_running)
        print("executed commad ",long_running)
        

        return redirect(url_for("dashboard", page=page))
    return render_template("task.html", form=form)