Beispiel #1
0
 def test_parse_relative_now_minus_2_time(self):
     arg = 'now-2'
     today_with_time = datetime.datetime.combine(utils.today(), utils.now().time())
     correct_result = (today_with_time - datetime.timedelta(hours=int(2))).time()
     result_of_parse = utils.parse_time(arg)
     self.assertEqual(result_of_parse, correct_result)
Beispiel #2
0
 def test_parse_relative_today_date(self):
     arg = 'today'
     correct_result = utils.today()
     result_of_parse = utils.parse_date(arg)
     self.assertEqual(result_of_parse, correct_result)
Beispiel #3
0
 def test_parse_relative_today_minus_2_date(self):
     arg = 'today-2'
     correct_result = utils.today() - datetime.timedelta(days=2)
     result_of_parse = utils.parse_date(arg)
     self.assertEqual(result_of_parse, correct_result)
Beispiel #4
0
def home(controller, request):
    if request.session.get('parent_task') is not None:
        request.session.pop('parent_task')

    now = lib_utils.datetime_to_milliseconds(lib_utils.now())

    TaskController(controller).find_overdue_tasks(now)

    if request.method == "POST":
        up_status = request.POST.get('status_up')
        if up_status is not None:
            status, tid = tuple(up_status.split(','))
            status = Status.to_str(Status.raise_status(
                Status.from_str(status)))
            parts = tid.split('_')
            repeat = None
            plan_id = None
            if len(parts) == 1:
                tid = int(tid)
            if len(parts) == 3:
                tid = int(parts[0])
                plan_id = int(parts[1])
                repeat = int(parts[2])
            if repeat is None:
                TaskController(controller).edit_task(tid, status=status)
            else:
                PlanController(controller).edit_repeat_by_number(plan_id,
                                                                 repeat,
                                                                 status=status)
        down_status = request.POST.get('status_down')
        if down_status is not None:
            status, tid = tuple(down_status.split(','))
            status = Status.to_str(
                Status.downgrade_status(Status.from_str(status)))
            parts = tid.split('_')
            repeat = None
            plan_id = None
            if len(parts) == 1:
                tid = int(tid)
            if len(parts) == 3:
                tid = int(parts[0])
                plan_id = int(parts[1])
                repeat = int(parts[2])
            if repeat is None:
                TaskController(controller).edit_task(tid, status=status)
            else:
                PlanController(controller).edit_repeat_by_number(plan_id,
                                                                 repeat,
                                                                 status=status)
        add_subtask = request.POST.get('add_subtask')
        if add_subtask is not None:
            request.session['parent_task'] = add_subtask
            return HttpResponseRedirect(reverse('core:add_task'))

    time_range = (lib_utils.datetime_to_milliseconds(lib_utils.today()),
                  lib_utils.shift_datetime_in_millis(
                      lib_utils.today(), datetime.timedelta(days=1)))
    tasks = []
    tasks += TaskController(controller).get_overdue_tasks(now)
    tasks += TaskController(controller).fetch_tasks(time_range=time_range)
    tasks += TaskController(controller).fetch_tasks(timeless=True)
    for i, task in enumerate(tasks):
        for j in range(len(tasks) - 1, i, -1):
            if task.tid == tasks[j].tid and task.status == Status.OVERDUE:
                del tasks[j]

    tasks = filter_status(tasks)

    visual_tasks = [
        VisualTaskData.from_lib_task(controller, task) for task in tasks
    ]

    return render(request, 'core/home.html', {'tasks': visual_tasks})