Esempio n. 1
0
def task_create(request, project_id):

    if request.method == 'POST':

        proj = Project.objects.get(pk=project_id)

        text = request.POST.get('text', False)
        task_title = request.POST.get('task_title', False)
        now = timezone.now()
        task_duedate = timezone.now() + datetime.timedelta(weeks=1)
        if request.POST.get('task_duedate') != '':
            task_duedate = datetime.datetime.fromtimestamp(
                int(request.POST.get('task_duedate', False)))

        task = Task(text=text,
                    title=task_title,
                    start_date=now,
                    due_date=task_duedate,
                    project=proj)

        task.save()
        task.users_assigned = [request.user]

        return redirect('/taskManager/' + project_id + '/',
                        {'new_task_added': True})
    else:
        return render_to_response('taskManager/task_create.html',
                                  {'proj_id': project_id},
                                  RequestContext(request))
Esempio n. 2
0
def task_create(request, project_id):

    if request.method == 'POST':

        proj = Project.objects.get(pk=project_id)

        text = request.POST.get('text', False)
        task_title = request.POST.get('task_title', False)
        now = datetime.datetime.now()
        task_duedate = timezone.now() + datetime.timedelta(weeks=1)
        if request.POST.get('task_duedate') != '':
            task_duedate = datetime.datetime.fromtimestamp(
                int(request.POST.get('task_duedate', False)))

        task = Task(
            text=text,
            title=task_title,
            start_date=now,
            due_date=task_duedate,
            project=proj)

        task.save()
        task.users_assigned = [request.user]

        return redirect('/taskManager/' + project_id +
                        '/', {'new_task_added': True})
    else:
        return render_to_response(
            'taskManager/task_create.html', {'proj_id': project_id}, RequestContext(request))
Esempio n. 3
0
def task_create(request, project_id):

    logger.info('User %s create task for project %s' % (request.user.username,project_id))
    if request.method == 'POST' and belongs_to_project(request.user, project_id):
        proj = Project.objects.get(pk=project_id)

        text = request.POST.get('text', False)
        task_title = request.POST.get('task_title', False)
        now = timezone.now()
        task_duedate = timezone.now() + datetime.timedelta(weeks=1)
        if request.POST.get('task_duedate') != '':
            task_duedate = datetime.datetime.strptime(
                request.POST.get('task_duedate', False),'%Y-%m-%d')

        task = Task(
            text=text,
            title=task_title,
            start_date=now,
            due_date=task_duedate,
            project=proj)

        task.save()
        task.users_assigned.add(request.user)

        return redirect('/taskManager/' + project_id +
                        '/project_details/', {'new_task_added': True})
    else:
        return render(
            request, 'taskManager/task_create.html', {'proj_id': project_id})
Esempio n. 4
0
def create(request):
    if request.method == 'GET':
        form = TaskCreateForm()
        nex = request.GET.get('next')
        return render(request, 'task/task_create.html', {
            'form': form,
            'next': nex
        })
    if request.method == 'POST':
        form = TaskCreateForm(request.POST)
        repeat = int(request.POST.get('repeat'))
        num = int(request.POST.get('num'))
        deadline = datetime.datetime.strptime(request.POST.get('deadline'),
                                              '%Y-%m-%d')
        when = datetime.datetime.strptime(request.POST.get('when'), '%Y-%m-%d')
        tasks = []
        if form.is_valid():
            for i in range(num):
                task = Task(name=request.POST.get('name'),
                            deadline=deadline.strftime('%Y-%m-%d'),
                            period=request.POST.get('period'),
                            when=when.strftime('%Y-%m-%d'),
                            time=form.cleaned_data['time'],
                            fixed=form.cleaned_data['fixed'],
                            user=request.user)
                tasks.append(task)
                when += datetime.timedelta(days=repeat)
                deadline += datetime.timedelta(days=repeat)
        Task.objects.bulk_create(tasks)
        return redirect_to_origin(request)
Esempio n. 5
0
def list(request, pk):
    if request.user.pk != pk:
        return redirect('account_login')
    d = datetime.date.today()
    day = datetime.datetime.now().weekday()
    if len(AddRoutine.objects.filter(user=request.user)):
        addroutine = AddRoutine.objects.get(user=request.user)
        if addroutine.last_visited != d and addroutine.add_or_not:
            routines = Routine.objects.filter(user=request.user)
            routine_tasks = []
            for routine in routines:
                if routine.days > 0 and routine.days - 1 != day:
                    continue
                task = Task(name=routine.name,
                            deadline=d,
                            period=routine.period,
                            when=d,
                            time=routine.time,
                            fixed=routine.fixed,
                            user=request.user)
                routine_tasks.append(task)
            Task.objects.bulk_create(routine_tasks)
            addroutine.last_visited = d
            addroutine.save()
    tasks = Task.objects.filter(user=request.user, done_or_not=False)
    todays = tasks.filter(when__lte=datetime.date.today())
    for task in todays:
        task.when = date.today()
        task.save()
    for task in todays:
        task.expired = True if task.deadline < datetime.date.today() else False
        task.save()
    today_num = len(todays)
    names = ['~12時', '12~15時', '15~18時', '18~21時', '21時~']
    h = datetime.datetime.now().hour
    p = max(h // 3 - 3, 0)
    today_infos = []
    for i, name in enumerate(names):
        if i < p:
            continue
        elif i == p:
            info = Taskinfo(
                name=name,
                tasks=todays.filter(period__lte=i).order_by('order'))
        else:
            info = Taskinfo(name=name,
                            tasks=todays.filter(period=i).order_by('order'))
        if info.num > 0:
            today_infos.append(info)
    toms = tasks.filter(when=datetime.date.today() +
                        datetime.timedelta(days=1))
    for task in toms:
        task.expired = True if task.deadline < datetime.date.today() else False
        task.save()
    tom_num = len(toms)
    tom_infos = []
    for i, name in enumerate(names):
        info = Taskinfo(name=name,
                        tasks=toms.filter(period=i).order_by('order'))
        if info.num > 0:
            tom_infos.append(info)
    other = Taskinfo(
        name="明日以降",
        tasks=tasks.filter(when__gt=datetime.date.today() +
                           datetime.timedelta(days=1)).order_by('when'))
    return render(
        request, 'task/task_list.html', {
            'today_infos': today_infos,
            'today_num': today_num,
            'tom_infos': tom_infos,
            'tom_num': tom_num,
            'other': other
        })