コード例 #1
0
ファイル: views.py プロジェクト: tovmeod/anaf
def task_time_slot_edit(request, time_slot_id, response_format='html'):
    """Task time slot edit page"""

    task_time_slot = get_object_or_404(TaskTimeSlot, pk=time_slot_id)
    task = task_time_slot.task

    if not request.user.profile.has_permission(task_time_slot, mode='w') \
            and not request.user.profile.has_permission(task, mode='w'):
        return user_denied(request, message="You don't have access to this Task Time Slot")

    if request.POST:
        form = TaskTimeSlotForm(
            request.user.profile, None, request.POST, instance=task_time_slot)
        if form.is_valid():
            task_time_slot = form.save()
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))

        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
    else:
        form = TaskTimeSlotForm(
            request.user.profile, None, instance=task_time_slot)

    context = _get_default_context(request)
    context.update({'form': form,
                    'task_time_slot': task_time_slot,
                    'task': task})

    return render_to_response('projects/task_time_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
コード例 #2
0
ファイル: views.py プロジェクト: tovmeod/anaf
def task_time_slot_add(request, task_id, response_format='html'):
    """Time slot add to preselected task"""

    task = get_object_or_404(Task, pk=task_id)
    if not request.user.profile.has_permission(task, mode='x'):
        return user_denied(request, message="You don't have access to this Task")

    if request.POST:
        task_time_slot = TaskTimeSlot(
            task=task, time_to=datetime.now(), user=request.user.profile)
        form = TaskTimeSlotForm(
            request.user.profile, task_id, request.POST, instance=task_time_slot)
        if 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        elif form.is_valid():
            task_time_slot = form.save()
            task_time_slot.set_user_from_request(request)
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
    else:
        form = TaskTimeSlotForm(request.user.profile, task_id)

    subtasks = Object.filter_by_request(
        request, Task.objects.filter(parent=task))
    time_slots = Object.filter_by_request(
        request, TaskTimeSlot.objects.filter(task=task))

    context = _get_default_context(request)
    context.update({'form': form,
                    'task': task,
                    'subtasks': subtasks,
                    'time_slots': time_slots})

    return render_to_response('projects/task_time_add', context,
                              context_instance=RequestContext(request), response_format=response_format)