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 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)