def test_creation(self): """ Test generating objects of each type.""" test_task = Task(datetime.now(), 6) test_timeperiod = TimePeriod(datetime.now(), datetime.now()) assert test_task.as_dict()['object_type'] == 'Task' assert test_timeperiod.as_dict()['object_type'] == 'TimePeriod'
def test_tasks(self, tasks): """ Test task functions.""" tasks = Task.get_all() assert len(tasks) == 2 tasks[0].delete() tasks = Task.get_all() assert len(tasks) == 1 assert not tasks[0].assigned
def get_tasks_from_sheet(sheet_id=SHEET_ID): """ Get a list of tasks from Google Sheet. """ credentials = get_credentials(SHEET_CREDS_FILENAME, SHEET_SCOPES) http = credentials.authorize(httplib2.Http()) discovery_url = ('https://sheets.googleapis.com/$discovery/rest?' 'version=v4') service = discovery.build('sheets', 'v4', http=http, discoveryServiceUrl=discovery_url) range_name = 'Todo!A1:F' result = service.spreadsheets().values().get(spreadsheetId=sheet_id, range=range_name).execute() values = result.get('values', []) tasks = [] for value in values[1:]: try: tasks.append( Task(value[4], value[3], taskref=value[0], tasktype=value[1], description=value[2], timetype="hours")) except: continue return tasks
def test_schedule_tasks(self, tasks, timeperiods): """ Test scheduling a task.""" tps = TimePeriod.get_all() tasks = Task.get_all() assert tps[0] not in tasks[0].timeperiods rt = schedule_task(tasks[0], datetime(2010, 10, 9, 12, 00)) assert rt == 0 assert tps[0] in tasks[0].timeperiods
def new_task(): form = TaskForm() if form.validate_on_submit(): task = Task(title = form.title.data, content = form.content.data, author = current_user) db.session.add(task) db.session.commit() flash('Your task has been assigned', 'success') return redirect(url_for('main')) return render_template('new_task.html', title='New task', form = form)
def schedule_all(): """ Schedule all tasks.""" # Get all unassigned tasks tasks = Task.get_all() errors = list() for task in tasks: timeleft = schedule_task(task) if timeleft > 0: errors.append({'task': task, 'timeleft': timeleft}) return errors
def test_assignments(self, tasks, timeperiods): """ Check manual assignments.""" tps = TimePeriod.get_all() tasks = Task.get_all() assert tps[0].available and tps[1].available tps[0].task = tasks[0] tps[1].task = tasks[1] tps[0].save() tps[1].save() assert not tps[0].available and not tps[1].available assert len(TimePeriod.get_assigned()) == 2 assert "test1" in tps[0].as_event()['description'] tasks[0].reset_assignments() assert tps[0].available and not tps[1].available
def run(): """ Run program.""" # Clear initial data Task.delete_all() TimePeriod.delete_all() # Clear output calendar clear_events() # Get tasks from Google spreadsheet tasks = get_tasks_from_sheet() # Get working blocks from Input Google calendar wb = get_work_blocks() # Save data for t in tasks: t.save() for w in wb: w.save() # Schedule tasks errors = schedule_all() # Upload scheduled time periods to Output Google calendar assigned_tps = TimePeriod.get_assigned() events = [a_tp.as_event() for a_tp in assigned_tps] posted_events = post_assigned_time(events) # Return errors and posted events return (errors, posted_events)
def new_task(): form = TaskForm() users = [(user.id, user.username) for user in User.query.all()] users.sort(key=lambda x: x[1]) form.assignee1.choices = users users_null = [(user.id, user.username) for user in User.query.all()] users_null.sort(key=lambda x: x[1]) users_null.insert(0, (-1, '')) for assignee in [ form.assignee2, form.assignee3, form.assignee4, form.assignee5 ]: assignee.choices = users_null # form.audience.choices = audience_groups if form.validate_on_submit(): task = Task(title=form.title.data, content=form.content.data, author=current_user) db.session.add(task) db.session.commit() task_id = db.session.query(Task).order_by(Task.id.desc()).first().id task_rec = Task_recipient(task_id=task_id, recipient=current_user.id) db.session.add(task_rec) db.session.commit() assignees = [] for assignee in [ form.assignee1, form.assignee2, form.assignee3, form.assignee4, form.assignee5 ]: if assignee.data != -1 and assignee.data not in assignees: assignees.append(assignee.data) # users = User.query.filter(User.username in assignees) for userid in assignees: task_rec = Task_recipient(task_id=task_id, recipient=userid) try: db.session.add(task_rec) db.session.commit() except exc.IntegrityError as e: db.session.rollback() flash('Your task has been assigned', 'success') return redirect(url_for('main')) return render_template('new_task.html', title='New task', form=form)
def schedule(): """HTTP endpoint for scheduling tasks If a task with the same code already exists, the one with the shorter interval will be made active. """ code = request.form['code'] interval = int(request.form['interval']) task_id = binascii.b2a_hex(os.urandom(5)) new_task = Task(id=task_id) new_task.active = True new_task.code = code new_task.interval = interval # TODO(derek): Assert there is only one other_task other_task = Task.query.filter_by(code=code, active=True).first() if other_task: if other_task.interval <= new_task.interval: new_task.active = False else: other_task.active = False other_task.save() current_app.scheduler.cancel(other_task.id) if new_task.active: print current_app.scheduler.schedule current_app.scheduler.schedule({ 'id': task_id, 'code': new_task.code, 'interval': new_task.interval }) new_task.save() return json.dumps({ 'status': 'success', 'id': task_id, })
def tasks(session): Task.delete_all() Task(datetime(2010, 10, 20, 12, 00), 30, description="test1").save() Task("20 October 2010", 1, timetype="hours", description="test2").save() return session
def other(request): q = Task(task='Mow', area='Green', hole=19) q.save() context = Task.objects.all() return render(request, 'view_edit_tasks.html', context=context)
task_title.append(fake.sentence()) task_date = [] for _ in range(num): task_date.append(datetime.utcnow) task_content = [] for i in range(num): task_content.append(fake.text()) task_user_id = [] for i in range(num): task_user_id.append(random.randint(10001, 10001 + num)) task_audience = [] for i in range(num): task_audience.append(fake.sentence()) for i in range(num): new_task = Task(id=tid[i], title=task_title[i], content=task_content[i], user_id=task_user_id[i]) db.session.add(new_task) task_recipient = [] for i in range(num): task_recipient.append(random.randint(10001, 10001 + num)) task_completed = [] for i in range(num): task_completed.append(random.randint(0, 1)) for i in range(num): try: task_rec = Task_recipient(task_id=tid[i], recipient=1, completed=task_completed[i]) db.session.add(task_rec) db.session.commit()