Exemple #1
0
def project_view(request, project_id, response_format='html'):
    "Single project view page"
    
    project = get_object_or_404(Project, pk=project_id)
    if not request.user.get_profile().has_permission(project):
        return user_denied(request, message="You don't have access to this Project") 
   
    query = Q(parent__isnull=True, project=project)
    if request.GET:
        if 'status' in request.GET and request.GET['status']:
            query = query & _get_filter_query(request.GET)
        else:
            query = query & Q(status__hidden=False) & _get_filter_query(request.GET)
    else:
        query = query & Q(status__hidden=False)

    if request.user.get_profile().has_permission(project, mode='r'):
        if request.POST:
            record = UpdateRecord()
            record.record_type = 'manual'
            form = TaskRecordForm(request.user.get_profile(), request.POST, instance=record)
            if form.is_valid():
                record = form.save()
                record.set_user_from_request(request)
                record.save()
                record.about.add(project)
                project.set_last_updated()
                return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
        else:
            form = TaskRecordForm(request.user.get_profile())
    else:
        form = None
    
    tasks = Object.filter_by_request(request, Task.objects.filter(query))

    tasks_progress = float(0)
    tasks_progress_query = Object.filter_by_request(request, Task.objects.filter(Q(parent__isnull=True, project=project)))
    if tasks_progress_query:
        for task in tasks_progress_query:
            if not task.status.active:
                tasks_progress += 1
        tasks_progress = (tasks_progress / len(tasks_progress_query)) * 100
        tasks_progress = round(tasks_progress, ndigits=1)
    
    filters = FilterForm(request.user.get_profile(), 'project', request.GET)
    
    milestones = Object.filter_by_request(request, 
                                          Milestone.objects.filter(project=project).filter(status__hidden=False))
    subprojects = Project.objects.filter(parent=project)
    
    context = _get_default_context(request)
    context.update({'project': project,
                    'milestones': milestones,
                    'tasks':tasks,
                    'tasks_progress':tasks_progress,
                    'record_form':form,
                    'subprojects':subprojects,
                    'filters': filters})
    return render_to_response('projects/project_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #2
0
def task_view(request, task_id, response_format='html'):
    "Single task view page"

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

    if request.user.get_profile().has_permission(task, mode='x'):
        if request.POST:
            if 'add-work' in request.POST:
                return HttpResponseRedirect(reverse('projects_task_time_slot_add', args=[task.id]))
            elif 'start-work' in request.POST:
                return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
            record = UpdateRecord()
            record.record_type = 'manual'
            form = TaskRecordForm(
                request.user.get_profile(), request.POST, instance=record)
            if form.is_valid():
                record = form.save()
                record.set_user_from_request(request)
                record.save()
                record.about.add(task)
                task.set_last_updated()
                return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        else:
            form = TaskRecordForm(request.user.get_profile())
    else:
        form = None

    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({'task': task,
                    'subtasks': subtasks,
                    'record_form': form,
                    'time_slots': time_slots})

    if 'massform' in context and 'project' in context['massform'].fields:
        del context['massform'].fields['project']

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