Exemplo n.º 1
0
def edit_subtask(request, subtask_id, owner_name=None):
    """
    Display full details of a SubTask.

    Note :
    Only owners of a subtask can (fully) edit the subtask (and that too only
    in their own page, ie. not while visiting some other user's page)

    Coords who have been assigned the SubTask can change only the Status.

    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner(request, owner_name)

    user = request.user
    curr_subtask = SubTask.objects.get(id=subtask_id)
    curr_subtask_form = SubTaskForm(instance=curr_subtask)

    if curr_subtask.is_owner(user):
        is_owner = True
    else:
        # User is a Coord
        is_owner = False

    has_updated = False
    other_errors = False
    if request.method == 'POST':
        if is_owner:
            # Let the Core save the SubTask
            curr_subtask_form = SubTaskForm(request.POST,
                                            instance=curr_subtask)
            if curr_subtask_form.is_valid():
                curr_subtask_form.save()
                has_updated = True
            else:
                other_errors = True
        elif 'status' in request.POST:
            # Coord - allowed to change only the status
            curr_subtask.status = request.POST.get('status', 'O')
            curr_subtask.save()
            has_updated = True
            # Reinstantiate the form
            curr_subtask_form = SubTaskForm(instance=curr_subtask)
            print 'SubTask updated'
    comments, comment_form, comment_status = handle_comment(
        request=request,
        is_task_comment=False,
        object_id=subtask_id,
        other_errors=other_errors)
    if has_updated:
        # Redirect to the same page, at Vivek's request
        return redirect('tasks.views.edit_subtask',
                        owner_name=owner_name,
                        subtask_id=subtask_id)
    else:
        return render_to_response('tasks/edit_subtask.html',
                                  locals(),
                                  context_instance=global_context(request))
Exemplo n.º 2
0
def edit_subtask(task_id,subtask_id):
    form=SubTaskForm(request.form)
    task=Task.objects(id=ObjectId(task_id)).first()
    subtask=task.subtasks[subtask_id]
    if request.method == 'POST' and form.validate():
        form=SubTaskForm(request.form)    
        task.subtasks[subtask_id].content=form.content.data
        task.subtasks[subtask_id].deadline=form.deadline.data
        task.save()
        return redirect('/task/pending')
    return render_template('edit_sub.html', form=form, subtask=subtask,task_id=task_id,subtask_id=subtask_id)
Exemplo n.º 3
0
def add_subtask(task_id):
    nowdate=datetime.now()
    form=SubTaskForm(request.form)    
    task=Task.objects(id=ObjectId(task_id)).first()
    if request.method == 'POST' and form.validate():
        subtask = SubTask()
        form.populate_obj(subtask)
        subtask.id = ObjectId()
        task.subtasks.append(subtask)        
        task.save()
        return redirect('/task/pending')
    return render_template('add_sub.html', form=form , task_id=task_id, nowdate=nowdate)
Exemplo n.º 4
0
def edit_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.

    Note :
    Only owners of a subtask can (fully) edit the subtask (and that too only
    in their own page, ie. not while visiting some other user's page)

    Coords who have been assigned the SubTask can change only the Status.

    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)

    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    curr_subtask_form = SubTaskForm (instance = curr_subtask)

    if curr_subtask.is_owner (user):
        is_owner = True
    else:
        # User is a Coord
        is_owner = False

    has_updated = False
    other_errors = False
    if request.method == 'POST':
        if is_owner:
            # Let the Core save the SubTask
            curr_subtask_form = SubTaskForm (request.POST, instance = curr_subtask)
            if curr_subtask_form.is_valid ():
                curr_subtask_form.save ()
                has_updated = True
            else:
                other_errors = True
        elif 'status' in request.POST:
            # Coord - allowed to change only the status
            curr_subtask.status = request.POST.get ('status', 'O') 
            curr_subtask.save ()
            has_updated = True
            # Reinstantiate the form
            curr_subtask_form = SubTaskForm (instance = curr_subtask)
            print 'SubTask updated'
    comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = False,
        object_id = subtask_id,
        other_errors = other_errors)
    if has_updated:
        # Redirect to the same page, at Vivek's request
        return redirect ('tasks.views.edit_subtask',
                         owner_name = owner_name, subtask_id = subtask_id)
    else:
        return render_to_response('tasks/edit_subtask.html',
                              locals(),
                              context_instance = global_context (request))
Exemplo n.º 5
0
def edit_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.

    Note :
    Only owners of a subtask can (fully) edit the subtask (and that too only
    in their own page, ie. not while visiting some other user's page)

    Coords who have been assigned the SubTask can change only the Status.

    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)
    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    curr_subtask_form = SubTaskForm (instance = curr_subtask,editor=request.user)

    if curr_subtask.is_owner (user):
        is_owner = True
    else:
        # User is a Coord
        is_owner = False

    if(curr_subtask.status=='C'):
        closed_task=1                     # The SubTask Was closed prior to editing
    else:
        closed_task=0                     # The SubTask is not closed prior to editing
    has_updated = False
    other_errors = False

    #Get Department Members' image thumbnails
    department = page_owner.get_profile ().department          
    dept_cores_list = User.objects.filter (
        groups__name = 'Cores',
        userprofile__department = department)
    dept_supercoords_list = User.objects.filter (
        groups__name = 'Supercoords',
        userprofile__department = department)
    dept_coords_list = User.objects.filter (
        groups__name = 'Coords',
        userprofile__department = department)

    if request.method == 'POST':
        if is_owner:
            # Let the Core save the SubTask
            curr_subtask_form = SubTaskForm (request.POST, instance = curr_subtask)
            if curr_subtask_form.is_valid ():
                if 'status' in request.POST:                
                    if(curr_subtask_form.cleaned_data['status']=='C')and(closed_task == 0):
                        curr_subtask_form.completion_date=datetime.date.today()                    
                    elif(closed_task == 1):
                        curr_subtask_form.completion_date=None
                curr_subtask_form.save ()
                has_updated = True
            else:
                other_errors = True
        elif 'status' in request.POST:
            # Coord - allowed to change only the status
            curr_subtask.status = request.POST.get ('status', 'O') 
            if(curr_subtask.status=='C')and(closed_task == 0):
                curr_subtask.completion_date=datetime.date.today()                    
            elif(closed_task == 1):
                curr_subtask.completion_date=None
            curr_subtask.save ()
            has_updated = True
            # Reinstantiate the form
            curr_subtask_form = SubTaskForm (instance = curr_subtask)
            print 'SubTask updated'
    comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = False,
        object_id = subtask_id,
        other_errors = other_errors)
    
   

    if has_updated:
        return redirect ('erp.tasks.views.display_portal',
                         owner_name = owner_name)
    else:
        return render_to_response('tasks/edit_subtask.html',
                              locals(),
                              context_instance = global_context (request))