def new_task(): form = TaskForm() # list of groups to add form.groups.choices = [(group.groupname, group.groupname) for group in current_user.groups] if form.validate_on_submit(): if int(form.price.data) > current_user.accounts.balance: flash('Not enough gold to create task!') else: task = Task(taskname=form.task.data, body=form.body.data, author=current_user, gold=int(form.price.data)) current_user.accounts.balance -= int(form.price.data) db.session.add(task) print('********groups', form.groups.data) for group in form.groups.data: group = Group.query.filter_by(groupname=group).first() task.groups.append(group) track = TaskTrack(task_id=task.id) db.session.add(track) db.session.commit() flash('Your task was successfully published in {} groups!'.format( form.groups.data)) next_url = request.cookies.get('next_url') return redirect(next_url) # url for previous page resp = make_response( render_template('new_task.html', title='New Task', form=form)) if request.method == 'GET': next_url = request.referrer or '/' resp.set_cookie('next_url', next_url) return resp
def update_task(request, id): page_title = "Editar Tarefa" task = task_service.search_task_id(id) if task.user != request.user: return HttpResponse( "Opa!! parece que você está tentando alterar uma tarefa que não é sua" ) task_form = TaskForm(request.POST or None, instance=task) if task_form.is_valid(): title = task_form.cleaned_data["title"] description = task_form.cleaned_data["description"] expiration_date = task_form.cleaned_data["expiration_date"] priority = task_form.cleaned_data["priority"] updated_task = Task(title=title, description=description, expiration_date=expiration_date, priority=priority, user=request.user) task_service.update_task(task, updated_task) return redirect('index_tasks') return render(request, 'tasks/task_form.html', { 'task_form': task_form, 'page_title': page_title })
def update_task(task_id): task = Task.query.get_or_404(task_id) userStatus = current_user.is_active if task.user_id != current_user.id: abort(403) form = TaskForm() if form.validate_on_submit(): task.text = form.text.data db.session.commit() return redirect(url_for( 'task', task_id=task_id, )) elif request.method == 'GET': form.text.data = task.text return render_template('taskUpdate.html', userStatus=userStatus, task=task, name=current_user.username, form=form)
def dashboard(): form = TaskForm() userStatus = current_user.is_active if form.validate_on_submit(): newTask = Task(text=form.text.data, user_id=current_user.id) print(newTask) db.session.add(newTask) db.session.commit() print("NEW TASK CREATED -'" + str(newTask) + "'") flash(f'{current_user.username} created a task!', 'success') return redirect( url_for('dashboard', userStatus=userStatus, tasks=current_user.tasks, name=current_user.username, form=form)) #return '<h1> Hello '+form.username.data+'!</h1>' return render_template('dashboard.html', userStatus=userStatus, tasks=current_user.tasks, name=current_user.username, form=form)
def taskform_handle(): form_for_task = TaskForm() if form_for_task.validate_on_submit(): flash('Handle task {0}'.format(form_for_task.task_id.data)) return redirect(url_for('task_status', task_id=form_for_task.task_id.data)) return redirect(url_for('index'))
def index(): taskform = TaskForm() if taskform.validate_on_submit(): description = None filename = None if taskform.description.data: description = taskform.description.data if taskform.image.data: filename = secure_filename(taskform.image.data.filename) # avoid overwriting existing files while path.exists(path.join(taskattachdir, filename)): fname, fext = path.splitext(filename) filename = '%s_%s' %(fname, fext) image_path = path.join(taskattachdir, filename) taskform.image.data.save(image_path) if AUTO_ROTATE: try: angle = fix_orientation(image_path, save_over=True) logger.info('image %s rotated by %s degrees' %(filename, angle)) except ValueError as e: logger.warn('image %s has no EXIF data: %s' %(filename, e)) store(description, filename) recent = readjson(taskjson) if recent is not None: recent = sorted(recent, key=lambda r: r['timestamp'], reverse=True) return render_template('main.html', title='Today I ...', taskform=taskform, recent=recent)
def task(): form = TaskForm() if form.validate_on_submit(): task_summary = request.form['title'] due_date = request.form['due_date'] time_est = request.form['time_est'] stress = request.form['stress'] is_placed = False with open('tasks.json', 'rb') as file: task_database = json.load(file) task = {'task_summary' : task_summary, 'due_date' : due_date, 'time_est': time_est, 'stress' : stress, 'is_placed' : is_placed} index = task_summary.strip() index = task_summary.replace(" ", "") index = index + str(due_date) + str(time_est) task_database[index] = task with open('tasks.json', 'w') as f: json.dump(task_database, f) task_database[index]["is_placed"] = True break_up_tasks() return redirect(url_for('calendar')) return render_template('task.html', title= 'Tasks', form=form)
def index(): form = TaskForm() if form.validate_on_submit(): db.session.add(Task(task=form.task.data, status=False)) db.session.commit() return redirect(url_for('index')) tasks = Task.query.all() return render_template('index.html', form=form, tasks=tasks)
def search() -> 'html': """Ищет информацию о задаче""" form = TaskForm() if form.validate_on_submit(): flash(f'Поиск задачи по запросу {form.task.data}') tasks = Task.query.filter_by(name=form.task.data).all() if not tasks: tasks = ['Ничего не найдено'] return render_template('search.html', title='Search', tasks=tasks, form=form) return render_template('add.html', title='Search', name='Поиск', form=form)
def details(id): task = Task.query.get(id) form = TaskForm(request.form, obj=task) if request.method == "POST": if form.validate_on_submit(): form.populate_obj(task) print(task) task.save() return redirect(url_for('tasks.list')) return render_template('task_details.html', form=form)
def create(): form = TaskForm(request.form) if form.validate_on_submit(): Task(title=form.title.data, description=form.description.data, due_date=form.due_date.data, is_accomplished=form.is_accomplished.data, user_id=session.get('user_id')).create() return redirect(url_for('tasks.list')) return render_template('task_create.html', form=form)
def index(): form = TaskForm(request.form) if request.method == 'POST' and form.validate(): task = { 'name': form.name.data, 'deadline': form.deadline.data, 'done': False } db.tasks.insert_one(task) return redirect(url_for('done')) return render_template('index.html', form=form)
def add_task(request): if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): form.save(commit=True) return index(request) else: print form.errors else: form = TaskForm() return render(request, 'app/add_task.html', {'form': form})
def create_task(): form = TaskForm() flash('Errors="%s"' % (form.errors)) if form.validate_on_submit(): t = Task(title=form.title.data, description=form.description.data, date=form.date.data) db.session.add(t) db.session.commit() return redirect('/task') return render_template('create_task.html', title='Create Task', form=form)
def create_task(): form = TaskForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): data = Task() form.populate_obj(data) print(str(form)) data.assigneeId = current_user.id db.session.add(data) db.session.commit() return data.to_dict() return ('Invalid Info')
def edit_task(id): task = Task.query.get(id) form = TaskForm(obj=task) flash('Errors="%s"' % (form.errors)) if form.validate_on_submit(): t = task t.title = form.title.data t.description = form.description.data t.date = form.date.data db.session.commit() return redirect('/task') return render_template('edit_task.html', title='Edit Task', form=form)
def remove() -> 'html': """Удаляет задачу""" form = TaskForm() if form.validate_on_submit(): task = Task.query.filter_by(name=form.task.data) if task.first() is not None: task.delete() db.session.commit() flash(f'Задача {form.task.data} удалена') else: flash(f'Задача {form.task.data} не найдена') return redirect(url_for('remove')) return render_template('add.html', title='Remove', name='Удаление', form=form)
def add() -> 'html': """Добавляет в базу данных""" form = TaskForm() if form.validate_on_submit(): if Task.query.filter_by(name=form.task.data).first() is None: task = Task(id=uuid.uuid4(), name=form.task.data, status=Status.created) db.session.add(task) db.session.commit() flash(f'Добавлена задача {form.task.data}') app.task_queue.enqueue('app.task.do', form.task.data) else: flash(f'Задача {form.task.data} уже добавлена') return redirect(url_for('add')) return render_template('add.html', title='Add', name='Добавление', form=form)
def add_task(id): todolist = ToDoList.query.filter_by(id=id).first() form = TaskForm() if form.validate_on_submit(): task = Task(title=form.title.data, description=form.description.data, deadline=form.deadline.data, task_owner=current_user, todolist=todolist, is_completed=False) db.session.add(task) db.session.commit() return redirect(url_for('todolist', id=todolist.id)) return render_template('add_task.html', todolist=todolist, form=form)
def projectedit(projectname): project = Project.query.filter_by(title=projectname).first_or_404() task = Project.projectEdit(project).tasks form = TaskForm() if form.validate_on_submit(): task = Task(body=form.label.data, project=project, checked='unchecked') db.session.add(task) db.session.commit() flash('Your task is now live!') task = Project.projectEdit(project).tasks return render_template('project.html', project=project, form=form, task=task)
def task_create(todo_id): task_form = TaskForm() if task_form.validate_on_submit(): task_object = Task(body=task_form.body.data, todo_list_id=todo_id) db.session.add(task_object) db.session.commit() return redirect(url_for('todo.task_list', todo_id=todo_id)) todo_item = TodoList.query.filter_by(id=todo_id).first_or_404() tasks = Task.query.filter_by(todo_list_id=todo_id).order_by( Task.is_finished) return render_template('tasks_list.html', form=task_form, todo_item=todo_item, tasks=tasks)
def post(self): form = TaskForm() if form.validate_on_submit(): task = Task(title=form.title.data, body=form.body.data, status=form.status.data) user = User.query.filter_by(username=form.performer.data).first() if user: user.tasks.append(task) db.session.add(task) db.session.commit() flash('Your task is now alive!') return redirect(url_for('index')) else: flash('There is no such developer!')
def get(self): form = TaskForm() tasks = Task.query.all() return render_template('index.html', title='Home', tasks=tasks, form=form)
def signup(): form = RegisterForm() formT = TaskForm() userStatus = current_user.is_active if form.validate_on_submit(): hashPass = generate_password_hash(form.password.data, method='sha256') newUser = User(username=form.username.data, email=form.email.data, password=hashPass, security_question_1=form.security_question_1.data, security_answer_1=form.security_answer_1.data) db.session.add(newUser) db.session.commit() login_user(newUser, remember=form.remember.data) print("NEW USER -'" + str(current_user.username + "'")) flash(f'Account created for {form.username.data}!', 'success') return redirect( url_for('dashboard', userStatus=userStatus, name=current_user.username, form=formT)) #return '<h1> Hello '+form.username.data+'!</h1>' return render_template('signup.html', form=form)
def new_task(class_id): form = TaskForm() cls = Class(ObjectId(class_id)) cls.flask_validate() if form.validate_on_submit(): date = form.date.data time = form.time.data dt = datetime.combine(date, time or datetime.min.time()) if date else None created_task = Task.create(form.name.data, class_=cls, date=dt, description=form.description.data, category=form.category.data) return redirect(url_for('pages.view_class', class_id=class_id)) return render_template('new_task.html', form=form)
def task_edit(task_id): task_object = Task.query.filter_by(id=task_id).first_or_404() task_form = TaskForm(body=task_object.body, is_finished=task_object.is_finished) if task_form.validate_on_submit(): task_object.body = task_form.body.data task_object.is_finished = task_form.is_finished.data db.session.commit() return redirect( url_for('todo.task_list', todo_id=task_object.todo_list_id)) todo_item = TodoList.query.filter_by( id=task_object.todo_list_id).first_or_404() return render_template('task_item.html', form=task_form, todo_item=todo_item, task=task_object)
def edit_task(task_id): task = Task(ObjectId(task_id)) task.flask_validate(edit=True) form = TaskForm(obj=task.to_struct()) form.time.data = task.date.time() if form.validate_on_submit(): date = form.date.data time = form.time.data dt = datetime.combine(date, time or datetime.min.time()) if date else None task.name = form.name.data task.description = form.description.data task.category = form.category.data task.date = dt return redirect( url_for('pages.view_class', class_id=str(task.class_.get_id()))) return render_template('edit_task.html', form=form, task=task)
def create_task(): form = TaskForm() if form.validate_on_submit(): title = request.form.get('title') body = request.form.get('description') start = request.form.get('start_time') end = request.form.get('end_time') author_name = request.form.get('author_name') task = Task(title=title, body=body, start=datetime.strptime(start, '%H:%M %d.%m.%Y'), end=datetime.strptime(end, '%H:%M %d.%m.%Y'), author_name=author_name) db.session.add(task) db.session.commit() return redirect(f'/tasks/{author_name}') return render_template('create_task.html', form=form)
def task_list(todo_id): task_form = TaskForm() todo_object = TodoList.query.filter_by(id=todo_id).first_or_404() tasks = Task.query.filter_by(todo_list_id=todo_id).order_by( Task.is_finished) return render_template('tasks_list.html', form=task_form, todo_item=todo_object, tasks=tasks)
def index(request): if request.method == 'GET': context = { 'form': TaskForm, 'tasks': Task.objects.all(), } return render(request, 'index.html', context) else: form = TaskForm(request.POST) if form.is_valid(): form.save() return redirect('index') context = { 'tasks': Task.objects.all(), 'form': form, } return render(request, 'index.html', context)
def edit_task(task_id): task = Task.query.filter_by(user_id=current_user.get_id()) current_task = Task.query.get_or_404(task_id) if current_task.task_due: current_task.task_due = current_task.task_due.astimezone( get_localzone()) if current_task.task_remind: current_task.task_remind = current_task.task_remind.astimezone( get_localzone()) task_form = TaskForm(obj=current_task) if request.method == 'POST': if not task_form.task_name.data: flash('task name can\'t be blank') else: #convert local datetime to UTC if task_form.task_due.data: task_form.task_due.data = task_form.task_due.data.astimezone( pytz.utc) if task_form.task_remind.data: task_form.task_remind.data = task_form.task_remind.data.astimezone( pytz.utc) task_form.populate_obj(current_task) db.session.commit() flash('task is edited successfully') #check task_remind and send scheduled reminder by email if current_task.task_remind: if current_task.task_remind < datetime.utcnow().replace( tzinfo=pytz.utc): flash('...but task reminder is past') else: send_email_reminder.apply_async( args=(current_task.task_id, ), eta=current_task.task_remind) flash('task reminder is also scheduled') return redirect(url_for('index')) return render_template('edit.html', title='edit', task=task, task_form=task_form)
def index(): if current_user.is_authenticated: user = current_user task = Task.query.filter_by(user_id=current_user.get_id()) task_form = TaskForm() return render_template('index.html', title='home', task=task, task_form=task_form, current_user=current_user)