コード例 #1
0
ファイル: time.py プロジェクト: mlouro/django-viriato
def index(request, project_id):
    t = 'projects/time/index.html'
    response_vars = { }

    project     = Project.objects.get(id=project_id)
    time_list   = Time.objects.filter(project=project)

    if request.method == 'POST':

        form = TimeForm(request.POST)

        if form.is_valid():
            time = form.save(commit=False)
            time.project_id = project_id
            time.save()

    else:
        time = Time()
        time.person = request.user
        time.date = datetime.now().date
        form = TimeForm(instance=time)




    response_vars['project'] = project
    response_vars['form'] = form
    response_vars['time_list'] = time_list

    response_vars['total_time'] = time_list.aggregate(Sum('time'))

    return render_project(request, project_id, t, response_vars)
コード例 #2
0
ファイル: time.py プロジェクト: mlouro/django-viriato
def save(request, project_id, time_id=False):
    """
    Shows latest activity and other usefull info
    """
    t = 'projects/time/form.html'
    response_vars = {}
    project = Project.objects.get(id=project_id)

    task = None

    if time_id:
        time = Time.objects.get(id=time_id)
        form = TimeForm(instance=time)
        parent = time.parent
    else:
        time = Time()
        form = TimeForm()

    if request.POST.has_key('task_id') and request.POST['task_id']:
        task = Task.objects.get(id=request.POST['task_id'])
    else:
        if request.GET.has_key('task') and request.GET['task']:
            task = Task.objects.get(id=request.GET['task'])


    if request.method == 'POST':

        form = TimeForm(request.POST)

        if form.is_valid():
            if time_id:
                form = TimeForm(request.POST, instance=Time.objects.get(id=time_id))
                time = form.save(commit=False)
            else:
                time = form.save(commit=False)
                time.project = project

            time.content_object  = task
            time.person = request.user
            time.save()

            if task:
                return HttpResponseRedirect(reverse('task_detail', args=[project.id, task.id]))

            return HttpResponseRedirect(reverse('projects.views.time.index', args=[project.id]))


    response = { }
    response_vars['request']      = request
    response_vars['project']      = project
    response_vars['form']         = form
    response_vars['time']         = time
    response_vars['task']         = task

    return render_project(request, project_id, t, response_vars)