pytask/taskapp/views.py
author Nishanth Amuluru <nishanth@fossee.in>
Sun, 09 Jan 2011 11:13:51 +0530
changeset 115 181d4eb9f419
parent 112 4cc40503bf3c
child 117 c693def6510f
permissions -rwxr-xr-x
created a view for making claim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     1
from datetime import datetime
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     2
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     3
from django.shortcuts import render_to_response, redirect
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     4
from django.http import Http404
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     5
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     6
from django.contrib.auth.decorators import login_required
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     7
from django.core.context_processors import csrf
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     8
from django.views.decorators.csrf import csrf_protect
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     9
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    10
from pytask.utils import make_key
101
bce480ff6ddc used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents: 95
diff changeset
    11
from pytask.views import show_msg
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    12
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    13
from pytask.taskapp.models import Task, TaskComment
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    14
from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, TaskCommentForm
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    15
from pytask.taskapp.utils import getTask
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    16
from pytask.profile.utils import get_notification
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    17
101
bce480ff6ddc used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents: 95
diff changeset
    18
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    19
@login_required
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    20
def create_task(request):
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    21
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    22
    user = request.user
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    23
    profile = user.get_profile()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    24
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    25
    context = {"user": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    26
               "profile": profile,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    27
              }
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    28
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    29
    context.update(csrf(request))
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    30
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    31
    can_create_task = False if profile.rights == "CT" else True
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    32
    if can_create_task:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    33
        if request.method == "POST":
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    34
            form = CreateTaskForm(request.POST)
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    35
            if form.is_valid():
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    36
                data = form.cleaned_data.copy()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    37
                data.update({"created_by": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    38
                             "creation_datetime": datetime.now(),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    39
                             "uniq_key": make_key(Task),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    40
                            })
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    41
                
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    42
                task = Task(**data)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    43
                task.save()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    44
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    45
                task_url = '/task/view/tid=%s'%task.uniq_key
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    46
                return redirect(task_url)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    47
            else:
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    48
                context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    49
                return render_to_response('task/create.html', context)
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    50
        else:
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    51
            form = CreateTaskForm()
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    52
            context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    53
            return render_to_response('task/create.html', context)
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    54
    else:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    55
        return show_msg(user, 'You are not authorised to create a task.')
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    56
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    57
def view_task(request, tid):
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    58
    """ get the task depending on its tid and display accordingly if it is a get.
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    59
    check for authentication and add a comment if it is a post request.
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    60
    """
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    61
    
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    62
    task_url = "/task/view/tid=%s"%tid
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    63
    task = getTask(tid)
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    64
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    65
    user = request.user
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    66
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    67
    if not user.is_authenticated():
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    68
        return render_to_response("/task/view.html", {"task": task})
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    69
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    70
    profile = user.get_profile()
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    71
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    72
    context = {"user": user,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    73
               "profile": profile,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    74
               "task": task,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    75
              }
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    76
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    77
    context.update(csrf(request))
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    78
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    79
    if task.status == "DL":
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    80
        return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    81
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    82
    task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    83
                         else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    84
    if not task_viewable:
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    85
        return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks")
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    86
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    87
    reviewers = task.reviewers.all()
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    88
    is_reviewer = True if user in task.reviewers.all() else False
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    89
    comments = task.comments.filter(is_deleted=False).order_by('comment_datetime')
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    90
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    91
    context.update({'is_reviewer':is_reviewer,
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    92
                    'comments':comments,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    93
                    'reviewers':reviewers,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    94
                   })
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    95
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    96
    claimed_users = task.claimed_users.all()
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    97
    selected_users = task.selected_users.all()
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
    98
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    99
    is_creator = True if user == task.created_by else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   100
    has_claimed = True if user in claimed_users else False
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   101
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   102
    context['is_selected'] = True if user in selected_users else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   103
    context['can_approve'] = True if task.status == "UP" and\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   104
                                     profile.rights in ["MG", "DC"]\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   105
                                     else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   106
    context['can_edit'] = True if is_creator else False
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   107
    context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   108
    context['can_delete'] = True if task.status == "UP" and is_creator else False
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   109
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   110
    context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   111
    context['task_claimable'] = True if task.status in ["OP", "WR"] else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   113
    context['can_comment'] = True if task.status != "UP" or\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   114
                                     profile.rights!="CT" else False
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   115
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   116
#    if task.status == "CD":
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   117
#        context['closing_notification'] =  Notification.objects.filter(task=task,role="CD")[0]
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   118
#    elif task.status == "CM":
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   119
#        context['completed_notification'] =  Notifications.objects.filter(task=task,role="CM")[0]
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   120
#    elif task.status == "WR":
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   121
#        context['assigned_users'] = task.assigned_users.all()
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   122
   
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   123
    if request.method == 'POST':
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   124
        form = TaskCommentForm(request.POST)
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   125
        if form.is_valid():
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   126
            data = form.cleaned_data['data']
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   127
            new_comment = TaskComment(task=task, data=data,
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   128
                                      uniq_key=make_key(TaskComment),
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   129
                                      commented_by=user, comment_datetime=datetime.now())
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   130
            new_comment.save()
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   131
            return redirect(task_url)
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   132
        else:
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   133
            context['form'] = form
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   134
            return render_to_response('task/view.html', context)
111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   135
    else:
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   136
        form = TaskCommentForm()
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   137
        context['form'] = form
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   138
        return render_to_response('task/view.html', context)
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 102
diff changeset
   139
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   140
@login_required
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   141
def claim_task(response, tid):
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   142
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   143
    task_url = "/task/view/tid=%s"%tid
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   144
    claim_url = "/task/claim/tid=%s"%tid
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   145
    task = getTask(tid)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   146
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   147
    if task.status == "UP":
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   148
        raise Http404
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   149
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   150
    user = request.user
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   151
    profile = user.get_profile()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   152
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   153
    context = {"user": user,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   154
               "profile": profile,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   155
               "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   156
              }
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   157
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   158
    context.update(csrf(request))
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   159
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   160
    reviewers = task.reviewers.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   161
    claimed_users = task.claimed_users.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   162
    assigned_users = task.assigned_users.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   163
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   164
    is_creator = True if user == task.created_by else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   165
    is_reviewer = True if user in reviewers else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   166
    has_claimed = True if user in claimed_users else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   167
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   168
    task_claimable = True if task.status in ["OP", "WR"] else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   169
    can_claim = True if task_claimable and ( not has_claimed )\
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   170
                        and ( not is_reviewer ) else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   171
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   172
    old_claims = task.claims.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   173
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   174
    context.update({"is_creator": is_creator,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   175
                    "task_claimable": task_claimable,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   176
                    "can_claim": can_claim,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   177
                    "old_claims": old_claims})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   178
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   179
    if request.method == "POST" and can_claim:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   180
        form = ClaimTaskForm(request.POST)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   181
        if form.is_valid():
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   182
            data = form.cleaned_data.copy()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   183
            data.update({"uniq_key": make_key(TaskClaim),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   184
                         "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   185
                         "claim_datetime": datetime.now(),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   186
                         "claimed_by": user,})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   187
            new_claim = TaskClaim(**data)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   188
            new_claim.save()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   189
            return redirect(claim_url)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   190
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   191
        else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   192
            context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   193
            return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   194
    else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   195
        form = ClaimTaskForm()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   196
        context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   197
        return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   198
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   199