pytask/taskapp/views.py
author Nishanth Amuluru <nishanth@fossee.in>
Tue, 11 Jan 2011 00:34:23 +0530
changeset 135 014d812e625e
parent 134 563fe356947d
child 136 cdd8026ee60e
permissions -rwxr-xr-x
edit textbook works fine
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
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
     3
from django.contrib.auth.models import User
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
     4
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     5
from django.shortcuts import render_to_response, redirect
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     6
from django.http import Http404
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     7
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     8
from django.contrib.auth.decorators import login_required
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
     9
from django.core.context_processors import csrf
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    10
from django.views.decorators.csrf import csrf_protect
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    11
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    12
from pytask.utils import make_key
101
bce480ff6ddc used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents: 95
diff changeset
    13
from pytask.views import show_msg
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    14
130
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
    15
from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
    16
from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
    17
                                 TaskCommentForm, ClaimTaskForm, \
135
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
    18
                                 ChoiceForm, EditTaskForm, CreateTextbookForm,\
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
    19
                                 EditTextbookForm
132
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
    20
from pytask.taskapp.utils import getTask, getTextBook
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    21
from pytask.profile.utils import get_notification
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    22
101
bce480ff6ddc used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents: 95
diff changeset
    23
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    24
@login_required
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    25
def create_task(request):
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    26
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    27
    user = request.user
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    28
    profile = user.get_profile()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    29
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    30
    context = {"user": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    31
               "profile": profile,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    32
              }
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    33
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    34
    context.update(csrf(request))
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    35
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    36
    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
    37
    if can_create_task:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    38
        if request.method == "POST":
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    39
            form = CreateTaskForm(request.POST)
95
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    40
            if form.is_valid():
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    41
                data = form.cleaned_data.copy()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    42
                data.update({"created_by": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    43
                             "creation_datetime": datetime.now(),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    44
                             "uniq_key": make_key(Task),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    45
                            })
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    46
                
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    47
                task = Task(**data)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    48
                task.save()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    49
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    50
                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
    51
                return redirect(task_url)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    52
            else:
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    53
                context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    54
                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
    55
        else:
102
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    56
            form = CreateTaskForm()
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    57
            context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 101
diff changeset
    58
            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
    59
    else:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 69
diff changeset
    60
        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
    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
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
    63
    """ 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
    64
    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
    65
    """
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
    66
    
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
    67
    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
    68
    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
    69
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
    user = request.user
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    71
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    72
    if not user.is_authenticated():
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    73
        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
    74
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
    75
    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
    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 = {"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
    78
               "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
    79
               "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
    80
              }
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
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
    82
    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
    83
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
    84
    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
    85
        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
    86
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    87
    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
    88
                         else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    89
    if not task_viewable:
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    90
        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
    91
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    92
    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
    93
    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
    94
    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
    95
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
    96
    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
    97
                    '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
    98
                    '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
    99
                   })
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
   100
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
    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
   102
    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
   103
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   104
    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
   105
    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
   106
127
32457bce3437 prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents: 125
diff changeset
   107
    context['selected_users'] = selected_users
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   108
    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
   109
    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
   110
                                     profile.rights in ["MG", "DC"]\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   111
                                     else False
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   112
    context['can_edit'] = True if is_creator and task.status == "UP" 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
   113
    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
   114
    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
   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
    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
   117
    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
   118
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   119
    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
   120
                                     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
   121
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
#    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
   123
#        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
   124
#    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
   125
#        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
   126
#    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
   127
#        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
   128
   
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
   129
    if request.method == 'POST':
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   130
        form = TaskCommentForm(request.POST)
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   131
        if form.is_valid():
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   132
            data = form.cleaned_data['data']
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   133
            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
   134
                                      uniq_key=make_key(TaskComment),
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   135
                                      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
   136
            new_comment.save()
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   137
            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
   138
        else:
112
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   139
            context['form'] = form
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 111
diff changeset
   140
            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
   141
    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
   142
        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
   143
        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
   144
        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
   145
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   146
@login_required
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   147
def edit_task(request, tid):
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   148
    """ only creator gets to edit the task and that too only before it gets
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   149
    approved.
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   150
    """
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   151
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   152
    user = request.user
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   153
    profile = user.get_profile()
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   154
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   155
    task_url = "/task/view/tid=%s"%tid
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   156
    task = getTask(tid)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   157
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   158
    is_creator = True if user == task.created_by else False
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   159
    can_edit = True if task.status == "UP" and is_creator else False
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   160
    if not can_edit:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   161
        raise Http404
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   162
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   163
    context = {"user": user,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   164
               "profile": profile,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   165
               "task": task,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   166
              }
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   167
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   168
    context.update(csrf(request))
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   169
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   170
    if request.method == "POST":
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   171
        form = EditTaskForm(request.POST, instance=task)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   172
        if form.is_valid():
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   173
            form.save()
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   174
            return redirect(task_url)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   175
        else:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   176
            context.update({"form": form})
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   177
            return render_to_response("task/edit.html", context)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   178
    else:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   179
        form = EditTaskForm(instance=task)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   180
        context.update({"form": form})
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   181
        return render_to_response("task/edit.html", context)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   182
130
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   183
@login_required
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   184
def create_textbook(request):
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   185
130
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   186
    user = request.user
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   187
    profile = user.get_profile()
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   188
130
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   189
    can_create = True if profile.rights != "CT" else False
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   190
    if not can_create:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   191
        raise Http404
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   192
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   193
    context = {"user": user,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   194
               "profile": profile,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   195
              }
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   196
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   197
    context.update(csrf(request))
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   198
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   199
    if request.method == "POST":
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   200
        form = CreateTextbookForm(request.POST)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   201
        if form.is_valid():
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   202
            data = form.cleaned_data.copy()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   203
            data.update({"uniq_key": make_key(TextBook),
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   204
                         "created_by": user,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   205
                         "creation_datetime": datetime.now()})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   206
            del data['chapters']
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   207
            new_textbook = TextBook(**data)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   208
            new_textbook.save()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   209
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   210
            new_textbook.chapters = form.cleaned_data['chapters']
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   211
132
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   212
            textbook_url = "/task/textbook/view/tid=%s"%new_textbook.uniq_key
130
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   213
            return redirect(textbook_url)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   214
        else:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   215
            context.update({"form": form})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   216
            return render_to_response("task/create_textbook.html", context)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   217
    else:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   218
        form = CreateTextbookForm()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   219
        context.update({"form": form})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 128
diff changeset
   220
        return render_to_response("task/create_textbook.html", context)
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   221
132
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   222
def view_textbook(request, tid):
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   223
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   224
    textbook = getTextBook(tid)
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   225
    textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   226
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   227
    user = request.user
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   228
    if not user.is_authenticated():
134
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   229
        return render_to_response("task/view_textbook.html", {"user": user})
132
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   230
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   231
    profile = user.get_profile()
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   232
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   233
    context = {"user": user,
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   234
               "profile": profile,
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   235
               "textbook": textbook,
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   236
              }
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   237
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   238
    context.update(csrf(request))
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   239
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   240
    chapters = Task.objects.filter(status="UP")
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   241
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   242
    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   243
                       else False
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   244
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   245
    can_approve = True if profile.rights in ["MG", "DC"] and \
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   246
                          textbook.status == "UP" else False
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   247
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   248
    context.update({"chapters": chapters,
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   249
                    "can_edit": can_edit,
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   250
                    "can_approve": can_approve})
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   251
    return render_to_response("task/view_textbook.html", context)
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 130
diff changeset
   252
134
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   253
def browse_textbooks(request):
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   254
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   255
    user = request.user
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   256
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   257
    open_textbooks = TextBook.objects.filter(status="OP").\
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   258
                                      order_by("creation_datetime")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   259
    comp_textbooks = TextBook.objects.filter(status="CM").\
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   260
                                      order_by("creation_datetime")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   261
    context = {"user": user,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   262
               "open_textbooks": open_textbooks,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   263
               "comp_textbooks": comp_textbooks,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   264
              }
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   265
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   266
    if user.is_authenticated() and user.get_profile().rights != "CT":
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   267
        unpub_textbooks = TextBook.objects.filter(status="UP")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   268
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   269
        context.update({"unpub_textbooks": unpub_textbooks})
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   270
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   271
    return render_to_response("task/browse_textbooks.html", context)
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 132
diff changeset
   272
128
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 127
diff changeset
   273
@login_required
135
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   274
def edit_textbook(request, tid):
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   275
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   276
    user = request.user
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   277
    profile = user.get_profile()
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   278
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   279
    textbook = getTextBook(tid)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   280
    textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   281
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   282
    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   283
                       else False
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   284
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   285
    if not can_edit:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   286
        raise Http404
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   287
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   288
    context = {"user": user,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   289
               "profile": profile,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   290
               "textbook": textbook,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   291
              }
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   292
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   293
    context.update(csrf(request))
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   294
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   295
    if request.method == "POST":
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   296
        form = EditTextbookForm(request.POST, instance=textbook)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   297
        if form.is_valid():
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   298
            form.save()
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   299
            return redirect(textbook_url)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   300
        else:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   301
            context.update({"form": form})
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   302
            return render_to_response("task/edit_textbook.html", context)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   303
    else:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   304
        form = EditTextbookForm(instance=textbook)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   305
        context.update({"form": form})
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   306
        return render_to_response("task/edit_textbook.html", context)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   307
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 134
diff changeset
   308
@login_required
118
f88135529c74 claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 117
diff changeset
   309
def claim_task(request, tid):
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   310
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   311
    task_url = "/task/view/tid=%s"%tid
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   312
    claim_url = "/task/claim/tid=%s"%tid
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   313
    task = getTask(tid)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   314
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   315
    if task.status == "UP":
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   316
        raise Http404
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   317
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   318
    user = request.user
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   319
    profile = user.get_profile()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   320
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   321
    context = {"user": user,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   322
               "profile": profile,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   323
               "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   324
              }
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   325
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   326
    context.update(csrf(request))
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   327
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   328
    reviewers = task.reviewers.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   329
    claimed_users = task.claimed_users.all()
118
f88135529c74 claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 117
diff changeset
   330
    selected_users = task.selected_users.all()
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   331
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   332
    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
   333
    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
   334
    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
   335
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   336
    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
   337
    can_claim = True if task_claimable and ( not has_claimed )\
119
ec7f2f4256f5 now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents: 118
diff changeset
   338
                        and ( not is_reviewer ) and (not is_creator ) \
ec7f2f4256f5 now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents: 118
diff changeset
   339
                        else False
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   340
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   341
    old_claims = task.claims.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   342
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   343
    context.update({"is_creator": is_creator,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   344
                    "task_claimable": task_claimable,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   345
                    "can_claim": can_claim,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   346
                    "old_claims": old_claims})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   347
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   348
    if request.method == "POST" and can_claim:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   349
        form = ClaimTaskForm(request.POST)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   350
        if form.is_valid():
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   351
            data = form.cleaned_data.copy()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   352
            data.update({"uniq_key": make_key(TaskClaim),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   353
                         "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   354
                         "claim_datetime": datetime.now(),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   355
                         "claimed_by": user,})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   356
            new_claim = TaskClaim(**data)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   357
            new_claim.save()
117
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 115
diff changeset
   358
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 115
diff changeset
   359
            task.claimed_users.add(user)
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 115
diff changeset
   360
            task.save()
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 115
diff changeset
   361
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   362
            return redirect(claim_url)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   363
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   364
        else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   365
            context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   366
            return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   367
    else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   368
        form = ClaimTaskForm()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   369
        context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   370
        return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   371
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   372
@login_required
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   373
def select_user(request, tid):
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   374
    """ first get the status of the task and then select one of claimed users
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   375
    generate list of claimed users by passing it as an argument to a function.
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   376
    """
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   377
    
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   378
    task_url = "/task/view/tid=%s"%tid
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   379
    
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   380
    user = request.user
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   381
    profile = user.get_profile()
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   382
    task = getTask(tid)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   383
    
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   384
    context = {"user": user,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   385
               "profile": profile,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   386
               "task": task,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   387
              }
115
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 112
diff changeset
   388
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   389
    context.update(csrf(request))
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   390
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   391
    claimed_users = task.claimed_users.all()
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   392
    selected_users = task.selected_users.all()
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
   393
    task_claimed = True if claimed_users else False
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   394
    
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   395
    is_creator = True if user == task.created_by else False
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   396
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   397
    if ( is_creator or profile.rights in ["CR", "DC"] ) and \
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
   398
       task.status in ["OP", "WR"]:
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   399
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
   400
        if task_claimed:
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   401
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   402
            user_list = ((user.id,user.username) for user in claimed_users)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   403
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   404
            if request.method == "POST":
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   405
                form = ChoiceForm(user_list, request.POST)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   406
                if form.is_valid():
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   407
                    uid = form.cleaned_data['choice']
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   408
                    selected_user = User.objects.get(id=uid)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   409
124
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
   410
                    task.selected_users.add(selected_user)
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 122
diff changeset
   411
                    task.claimed_users.remove(selected_user)
125
9b0812962133 created the home page
Nishanth Amuluru <nishanth@fossee.in>
parents: 124
diff changeset
   412
                    task.status = "WR"
122
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   413
                    task.save()
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   414
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   415
                    return redirect(task_url)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   416
                else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   417
                    context.update({"form": form})
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   418
                    return render_to_response('task/select_user.html', context)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   419
            else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   420
                form = ChoiceForm(user_list)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   421
                context.update({"form": form})
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   422
                return render_to_response('task/select_user.html', context)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   423
        else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   424
            return show_msg(user, 'There are no pending claims for this task',
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   425
                            task_url, 'view the task')
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   426
    else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   427
        raise Http404
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 119
diff changeset
   428