taskapp/views/task.py
author Nishanth Amuluru <nishanth@fossee.in>
Wed, 05 Jan 2011 18:50:20 +0530
changeset 216 ab7c24ab8d93
parent 215 84ec0ca5bc68
child 217 307f699e6102
permissions -rw-r--r--
Added a link to list all the textbooks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
     1
from datetime import datetime
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
     2
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
     3
from django.http import HttpResponse, Http404
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
     4
from django.shortcuts import render_to_response, redirect
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
     5
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
     6
from pytask.taskapp.models import User, Task, Comment, Request, Notification
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents: 114
diff changeset
     7
from pytask.taskapp.utilities.task import getTask
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
     8
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm, EditTaskForm, ClaimTaskForm
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
     9
from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor, deleteTask
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
    10
from pytask.taskapp.views.user import show_msg
138
c452c699a8af now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents: 136
diff changeset
    11
from pytask.taskapp.utilities.user import get_user
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    12
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    13
## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    14
## do not create su user thro syncdb
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    15
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    16
def browse_tasks(request):
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    17
    """ display all the tasks """
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    18
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
    19
    user = get_user(request.user) if request.user.is_authenticated() else request.user
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    20
    task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    21
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    22
    context = {'user':user,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    23
               'task_list':task_list,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    24
               }
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    25
    return render_to_response('task/browse.html', context)
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    26
215
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    27
def show_textbooks(request):
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    28
    """ display all the tasks """
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    29
    
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    30
    user = get_user(request.user) if request.user.is_authenticated() else request.user
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    31
    task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    32
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    33
    textbooks = task_list.filter(tags_field__icontains="textbook")
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    34
    
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    35
    context = {'user':user,
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    36
               'task_list':task_list,
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    37
               }
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    38
    return render_to_response('task/browse.html', context)
84ec0ca5bc68 Added a page for displaying all the textbooks
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    39
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    40
def publish_task(request, tid):
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    41
    """ check if user is the mentor and also if the task status is UP.
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    42
    """
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    43
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    44
    task_url = "/task/view/tid=%s"%tid
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    45
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
    46
    user = get_user(request.user) if request.user.is_authenticated() else request.user
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    47
    task = getTask(tid)
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    48
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    49
    is_guest = True if not user.is_authenticated() else False
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    50
    is_mentor = True if user in task.mentors.all() else False
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    51
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    52
    if user == task.created_by:
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    53
        context = {
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    54
            'user':user,
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    55
        }
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    56
        if task.status == "UP":
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    57
            if request.method == "POST":
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    58
                publishTask(task)
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    59
                return show_msg(user, "The task has been published", task_url, "view the task")
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    60
            else:
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    61
                return render_to_response('task/publish.html', context)
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    62
        else:
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    63
            return show_msg(user, "The task is already published", task_url, "view the task")
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    64
    else:
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    65
        return show_msg(user, "You are not authorised to do this", '/task/browse/', "browse tasks")
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    66
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    67
def view_task(request, tid):
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    68
    """ get the task depending on its tid and display accordingly if it is a get.
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    69
    check for authentication and add a comment if it is a post request.
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    70
    """
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    71
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    72
    task_url = "/task/view/tid=%s"%tid
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    73
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
    74
    user = get_user(request.user) if request.user.is_authenticated() else request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
    75
    task = getTask(tid)
110
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    76
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    77
    if task.status == "DL":
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    78
        return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
155
52958289d81f now if a task has subs, it will remain locked forever.
nishanth
parents: 154
diff changeset
    79
    comments = task.comment_set.filter(is_deleted=False).order_by('creation_datetime')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    80
    mentors = task.mentors.all()
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    81
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    82
    deps, subs = task.deps, task.subs
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    83
    
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    84
    is_guest = True if not user.is_authenticated() else False
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    85
    is_mentor = True if user in task.mentors.all() else False
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    86
    context = {'user':user,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    87
               'task':task,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    88
               'comments':comments,
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    89
               'mentors':mentors,
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    90
               'subs':subs,
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    91
               'deps':deps,
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    92
               'is_guest':is_guest,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    93
               'is_mentor':is_mentor,
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    94
              }
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    95
160
05157d35d66f imposed a constraint that edit_task url is not displayed if task is OP and has claimed_users.
nishanth
parents: 159
diff changeset
    96
    claimed_users = task.claimed_users.all()
05157d35d66f imposed a constraint that edit_task url is not displayed if task is OP and has claimed_users.
nishanth
parents: 159
diff changeset
    97
192
8c982f517786 fixed a small syntax error .
nishanth
parents: 191
diff changeset
    98
193
505bbe421be4 fixed a bug in view task.
nishanth
parents: 192
diff changeset
    99
    is_requested_mentor = True if user.is_authenticated() and user.request_sent_to.filter(is_valid=True,is_replied=False,role="MT",task=task) else False
192
8c982f517786 fixed a small syntax error .
nishanth
parents: 191
diff changeset
   100
    task_viewable = True if ( task.status != "UP" ) or is_mentor or is_requested_mentor else False
191
3bfe70742aa8 now requested mentors can see unpublished task but not comment on it.
nishanth
parents: 181
diff changeset
   101
    if not task_viewable:
3bfe70742aa8 now requested mentors can see unpublished task but not comment on it.
nishanth
parents: 181
diff changeset
   102
        return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks")
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   103
192
8c982f517786 fixed a small syntax error .
nishanth
parents: 191
diff changeset
   104
    context['is_requested_mentor'] = is_requested_mentor
8c982f517786 fixed a small syntax error .
nishanth
parents: 191
diff changeset
   105
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
   106
    context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   107
    context['can_edit'] = True if task.status == "UP" and is_mentor else False
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   108
    context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_mentor else False
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   109
    context['can_delete'] = True if task.status == "UP" and user == task.created_by else False
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   110
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   111
    context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   112
    context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   113
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   114
    context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   115
    context['task_claimable'] = True if task.status in ["OP", "WR"] and not is_guest else False
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   116
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   117
    if task.status == "CD":
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   118
        context['closing_notification'] =  Notification.objects.filter(task=task,role="CD")[0]
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   119
    elif task.status == "CM":
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   120
        context['completed_notification'] =  Notifications.objects.filter(task=task,role="CM")[0]
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   121
    elif task.status == "WR":
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   122
        context['assigned_users'] = task.assigned_users.all()
64
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
   123
   
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   124
    if request.method == 'POST':
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   125
        if not is_guest:
176
13ceb76fd0a3 now empty comments will not be accepted.
nishanth
parents: 167
diff changeset
   126
            data = request.POST.get("data", "").strip()
13ceb76fd0a3 now empty comments will not be accepted.
nishanth
parents: 167
diff changeset
   127
            if not data:
13ceb76fd0a3 now empty comments will not be accepted.
nishanth
parents: 167
diff changeset
   128
                context['error_msg'] = "Enter some message to comment"
13ceb76fd0a3 now empty comments will not be accepted.
nishanth
parents: 167
diff changeset
   129
                return render_to_response('task/view.html', context)
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   130
            new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now())
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   131
            new_comment.save()
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   132
            return redirect(task_url)
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   133
        else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   134
            errors.append("You must be logged in to post a comment")
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   135
            return render_to_response('task/view.html', context)
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   136
    else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   137
        return render_to_response('task/view.html', context)
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   138
        
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   139
def create_task(request):
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   140
    """ check for rights and create a task if applicable.
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   141
    if user cannot create a task, redirect to homepage.
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   142
    """
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   143
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   144
    user = get_user(request.user) if request.user.is_authenticated() else request.user
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   145
    is_guest = True if not user.is_authenticated() else False
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   146
    
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   147
    if not is_guest:
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   148
        user_profile = user.get_profile()
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   149
        can_create_task = False if user_profile.rights == "CT" else True
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   150
        if can_create_task:
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   151
            if request.method == "POST":
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   152
                form = TaskCreateForm(request.POST)
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   153
                if form.is_valid():
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   154
                    data = form.cleaned_data
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   155
                    title = data['title']
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   156
                    desc = data['desc']
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   157
                    credits = data['credits']
166
ac72d641046e now task can have a title of a deleted task.
nishanth
parents: 165
diff changeset
   158
                    #publish = data['publish'] # just in case if we have to show the option
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   159
                    task = createTask(title,desc,user,credits)
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   160
                    
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   161
                    addMentor(task, user)
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   162
                    updateTask(task,tags_field=data['tags_field'])
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   163
                    # if publish: publishTask(task)    
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   164
                    task_url = '/task/view/tid=%s'%task.id
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   165
                    return redirect(task_url)
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   166
                else:
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   167
                    return render_to_response('task/create.html',{'user':user, 'form':form})
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   168
            else:
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   169
                form = TaskCreateForm()
177
4a7206176345 create task page now shows a proper side bar.
nishanth
parents: 176
diff changeset
   170
                return render_to_response('task/create.html',{'user':user, 'form':form})
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   171
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   172
            return show_msg(user, 'You are not authorised to create a task.')
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   173
    else:
180
972745147e3f fixed a bug in edit_task view.
nishanth
parents: 179
diff changeset
   174
        return show_msg(user, 'You are not authorised to create a task.', "/", "home page")
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   175
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   176
def add_mentor(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   177
    """ check if the current user has the rights to edit the task and add him.
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   178
    if user is not authenticated, redirect him to concerned page. """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   179
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   180
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   181
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   182
    user = get_user(request.user) if request.user.is_authenticated() else request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   183
    task = getTask(tid)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   184
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   185
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   186
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   187
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   188
    if (not is_guest) and user in task.mentors.all():
149
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   189
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   190
        pending_requests = Request.objects.filter(is_replied=False,is_valid=True,role="MT",task=task).order_by('creation_date').reverse()
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   191
        user_pending_requests = pending_requests.filter(sent_by=user)
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   192
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   193
        ## now iam going for a brute force method
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   194
        user_list = list(User.objects.filter(is_active=True))
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   195
        for mentor in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   196
            user_list.remove(mentor)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   197
            
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   198
        for a_user in task.claimed_users.all():
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   199
            user_list.remove(a_user)
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   200
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   201
        for a_user in task.assigned_users.all():
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   202
            user_list.remove(a_user)
149
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   203
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   204
        for req in user_pending_requests:
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   205
            user_list.remove(req.sent_to.all()[0])
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   206
            
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   207
        non_mentors = ((_.id, _.username) for _ in user_list)
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   208
        non_mentor_ids = [ str(a_user.id) for a_user in user_list ]
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   209
        ## code till must be made elegant and not brute force like above
149
3395960549e8 now a user cannot make two requests to another user for mentoring a task.
nishanth
parents: 141
diff changeset
   210
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   211
        form = AddMentorForm(non_mentors)
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   212
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   213
        context = {
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   214
            'user':user,
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 155
diff changeset
   215
            'task':task,
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   216
            'pending_requests':pending_requests,
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   217
            'form':form,
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   218
        }
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   219
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   220
        if request.method == "POST":
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   221
            data = request.POST
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   222
            uid = data.get('mentor', None)
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   223
            if uid in non_mentor_ids:
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   224
                new_mentor = User.objects.get(id=int(uid))
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   225
                reqMentor(task, new_mentor, user)
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   226
                return redirect('/task/addmentor/tid=%s'%task.id)
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   227
            else:
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   228
                ## bogus post request
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   229
                raise Http404
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   230
        else:
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 149
diff changeset
   231
            return render_to_response('task/addmentor.html', context)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   232
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   233
        return show_msg(user, 'You are not authorised to add mentors for this task', task_url, 'view the task')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   234
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   235
def add_tasks(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   236
    """ first display tasks which can be subtasks for the task and do the rest.
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   237
    """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   238
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   239
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   240
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   241
    user = get_user(request.user) if request.user.is_authenticated() else request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   242
    task = getTask(tid)
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   243
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
   244
    deps, subs = task.deps, task.subs
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   245
    is_plain = False if deps or subs else True
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   246
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   247
    ## again a brute force method
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   248
    valid_tasks = []
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   249
    for a_task in Task.objects.all():
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
   250
        if not ( a_task in deps or a_task in subs or a_task.status=="CD" or a_task==task ):
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   251
            valid_tasks.append(a_task)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   252
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   253
    task_choices = [ (_.id,_.title) for _ in valid_tasks ]
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   254
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   255
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   256
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   257
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   258
    if (not is_guest) and user in task.mentors.all():
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   259
        if task.status in ["UP", "OP", "LO"]:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   260
            form = AddTaskForm(task_choices, is_plain)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   261
            if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   262
                ## first decide if adding subs and deps can be in same page
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   263
                ## only exclude tasks with status deleted
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   264
                data = request.POST
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   265
                if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.')
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   266
                if not data.get('task', None): errors.append('Please choose a one task')
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   267
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   268
                if not errors:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   269
                    if is_plain:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   270
                        update_method = addDep if data['type'] == "D" else addSubTask
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   271
                    elif deps:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   272
                        update_method = addDep
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   273
                    elif subs:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   274
                        update_method = addSubTask
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   275
                    else:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   276
                        print "Screw you"
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   277
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   278
                    ## we might iterate over a task list later on
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   279
                    task_id = data['task']
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   280
                    sub_or_dep = getTask(task_id)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   281
                    update_method(task, sub_or_dep)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   282
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   283
                    return redirect(task_url)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   284
                else:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   285
                    return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   286
            else:
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   287
                return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   288
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   289
            errors = ["The task cannot be added subtasks or dependencies in this state"]
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   290
#            return render_to_response('task/add.html', {'form':form, 'errors':errors})
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   291
            return show_msg(user, 'The task cannot be added subtasks or dependencies now', task_url, 'view the task')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   292
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   293
        return show_msg(user, 'You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   294
    
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   295
def remove_task(request, tid):
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   296
    """ display a list of tasks and remove the selectes ones.
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   297
    """
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   298
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   299
    task_url = "/task/view/tid=%s"%tid
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   300
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   301
    user = get_user(request.user) if request.user.is_authenticated() else request.user
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   302
    task = getTask(tid)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   303
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   304
    is_guest = True if not user.is_authenticated() else False
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   305
    if (not is_guest) and user in task.mentors.all():
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   306
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   307
        if task.status in ["UP", "LO", "OP"]:
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   308
            
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   309
            deps, subs = task.deps, task.subs
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   310
            task_list = deps if task.sub_type == "D" else subs
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   311
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   312
            if task_list:
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   313
                choices = [(_.id,_.title) for _ in task_list ]
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   314
                form = ChoiceForm(choices)
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   315
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   316
                errors = []
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   317
                
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   318
                context = {
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   319
                    'user':user,
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   320
                    'task':task,
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   321
                    'form':form,
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   322
                }
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   323
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   324
                if request.method == "POST":
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   325
                    data = request.POST
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   326
                    if not data.get('choice', None):
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   327
                        errors.append("Please choose a task to remove.")
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   328
                        context['errors'] = errors
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   329
                    if not errors:
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   330
                        tid = data['choice']
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   331
                        sub_task = getTask(tid)
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   332
                        removeTask(task, sub_task)
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   333
                        return redirect(task_url)
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   334
                    else:
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   335
                        return render_to_response('task/removetask.html', context)
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   336
                else:
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   337
                    return render_to_response('task/removetask.html', context)
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   338
            else:
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   339
                return show_msg(user, "The task has no subtasks/dependencies to be removed", task_url, "view the task")
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   340
        else:
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   341
            return show_msg(user, "subtasks/dependencies cannot be removed at this stage", task_url, "view the task")
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   342
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   343
        return show_msg(user, "You are not authorised to do this", task_url, "view the task")
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   344
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   345
def claim_task(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   346
    """ display a list of claims for get and display submit only if claimable """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   347
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   348
    ## create claims model and create a new database with required tables for it
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   349
    ## see if that "one to n" or "n to one" relationship has a special field
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   350
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   351
    task_url = "/task/view/tid=%s"%tid
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   352
    claim_url = "/task/claim/tid=%s"%tid
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   353
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   354
    errors = []
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   355
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   356
    user = get_user(request.user) if request.user.is_authenticated() else request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   357
    task = getTask(tid)
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   358
    
204
fa1da06d25c9 now claims are read from notifications. we can ditchax claims model now.
nishanth
parents: 193
diff changeset
   359
    #claims = task.notifications_task.filter(role="CL",sent_to=task.created_by) 
fa1da06d25c9 now claims are read from notifications. we can ditchax claims model now.
nishanth
parents: 193
diff changeset
   360
    # this is what the next line should be when i re sync the db
fa1da06d25c9 now claims are read from notifications. we can ditchax claims model now.
nishanth
parents: 193
diff changeset
   361
    claims = Notification.objects.filter(task=task, sent_to=task.created_by, role="CL")
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   362
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   363
    mentors = task.mentors.all()
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   364
    claimed_users = task.claimed_users.all()
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   365
    assigned_users = task.assigned_users.all()
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   366
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   367
    is_guest = True if not user.is_authenticated() else False
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   368
    is_mentor = True if user in mentors else False
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   369
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   370
    task_claimable = True if task.status in ["OP", "WR"] else False
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   371
    user_can_claim = True if  task_claimable and not ( is_guest or is_mentor ) and ( user not in claimed_users ) and ( user not in assigned_users )  else False
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   372
    task_claimed = True if claimed_users else False
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   373
    
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   374
    context = {'user':user,
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   375
               'is_mentor':is_mentor,
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   376
               'task':task,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   377
               'claims':claims,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   378
               'user_can_claim':user_can_claim,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   379
               'task_claimable':task_claimable,
33
0d0ea7b188d5 fixed a bug in templates/task/claim.html which required modification of views/task.py; also changed the no.of char limit on task title .
nishanth
parents: 25
diff changeset
   380
               'task_claimed':task_claimed,
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   381
               'errors':errors}
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   382
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   383
    if not is_guest:
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   384
        form = ClaimTaskForm()
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   385
        context['form'] = form
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   386
        if request.method == "POST":
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   387
            form = ClaimTaskForm(request.POST)
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   388
            context['form'] = form
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   389
            if form.is_valid():
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 204
diff changeset
   390
                claim_proposal = form.cleaned_data['message']
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   391
                addClaim(task, claim_proposal, user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   392
                return redirect(claim_url)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   393
            else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   394
                return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   395
        else:
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   396
            return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   397
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   398
        return show_msg(user, 'You are not logged in to view claims for this task', task_url, 'view the task')
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   399
    
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   400
def rem_user(request, tid):
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   401
    """ show a list of working users and ask for a message/reason for removing user.
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   402
    """
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   403
    
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   404
    task_url = "/task/view/tid=%s"%tid
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   405
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   406
    user = get_user(request.user) if request.user.is_authenticated() else request.user
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   407
    task = getTask(tid)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   408
    
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   409
    is_guest = True if not user.is_authenticated() else False
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   410
    is_mentor = True if user in task.mentors.all() else False
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   411
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   412
    if (not is_guest) and is_mentor:
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   413
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   414
        assigned_users = task.assigned_users.all()
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   415
        choices = [ (_.id,_.username) for _ in assigned_users ]
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   416
        context = {
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   417
            'user':user,
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   418
            'task':task,
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   419
        }
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   420
        
162
d378eff02f2e added au ru notifications.
nishanth
parents: 160
diff changeset
   421
        if task.status in ["WR"]:
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   422
            if assigned_users:
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   423
                form = RemoveUserForm(choices)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   424
                context['form'] = form
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   425
                if request.method == "POST":
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   426
                    data = request.POST
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   427
                    form = RemoveUserForm(choices, data)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   428
                    if form.is_valid():
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   429
                        data = form.cleaned_data
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   430
                        uid = data['user']
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   431
                        reason = data['reason']
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   432
                        rem_user = User.objects.get(id=uid)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   433
                        removeUser(task, rem_user, user, reason)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   434
                        return redirect(task_url)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   435
                    else:
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   436
                        context['form'] = form
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   437
                        return render_to_response('task/remove_user.html', context)
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   438
                else:
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   439
                    return render_to_response('task/remove_user.html',context)
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   440
            else:
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   441
                return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   442
        else:
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   443
            return show_msg(user, "This is not the stage to remove users", task_url, "view the task")
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   444
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   445
        return show_msg(user, "You are not authorised to do this", task_url, "view the task")
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   446
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   447
def assign_task(request, tid):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   448
    """ first get the status of the task and then assign it to one of claimed users
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   449
    generate list of claimed users by passing it as an argument to a function.
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   450
    """
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   451
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   452
    task_url = "/task/view/tid=%s"%tid
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   453
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   454
    user = get_user(request.user) if request.user.is_authenticated() else request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   455
    task = getTask(tid)
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   456
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   457
    is_guest = True if not user.is_authenticated() else False
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   458
    is_mentor = True if user in task.mentors.all() else False
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   459
75
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   460
    claimed_users = task.claimed_users.all()
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   461
    assigned_users = task.assigned_users.all()
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   462
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   463
    task_claimed = True if claimed_users else False
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 17
diff changeset
   464
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   465
    if (not is_guest) and is_mentor:
157
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   466
        if task.status in ["OP", "WR"]:
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   467
            if task_claimed:
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   468
                user_list = ((user.id,user.username) for user in claimed_users)
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   469
                form = ChoiceForm(user_list)
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   470
        
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   471
                if request.method == "POST":
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   472
                    uid = request.POST['choice']
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   473
                    assigned_user = User.objects.get(id=uid)
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   474
                    assignTask(task, assigned_user, user)
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   475
                    return redirect(task_url)
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   476
                else:
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   477
                    return render_to_response('task/assign.html',{'user':user, 'task':task,'form':form})
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   478
            elif assigned_users:
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   479
                return show_msg(user, 'When the no of users you need for the task is more than the no of users willing to do the task, I\'d say please re consider the task :P',task_url, 'view the task')
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   480
            else:
157
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   481
                return show_msg(user, 'Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task')
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   482
        else: 
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   483
            return show_msg(user, "The task cannot be assigned to users at this stage", task_url, 'view the task')
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   484
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   485
        return show_msg(user, 'You are not authorised to perform this action', task_url, 'view the task')
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   486
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   487
def assign_credits(request, tid):
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   488
    """ Check if the user is a mentor and credits can be assigned.
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   489
    Then display all the approved credits.
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   490
    Then see if mentor can assign credits to users also or only mentors.
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   491
    Then put up a form for mentor to assign credits accordingly.
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   492
    """
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   493
    
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   494
    task_url = "/task/view/tid=%s"%tid
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   495
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   496
    user = get_user(request.user) if request.user.is_authenticated() else request.user
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   497
    task = getTask(tid)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   498
157
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   499
    ## the moment we see that user had requested credits, it means he had worked and hence we change the status to WR
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 157
diff changeset
   500
    ## we have to discuss on this since, credits may also be given to mentor
157
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   501
    task.status = "WR"
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   502
    task.save()
65d5e9737d1c fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents: 156
diff changeset
   503
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   504
    is_guest = True if not user.is_authenticated() else False
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   505
    is_mentor = True if (not is_guest) and user in task.mentors.all() else False
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   506
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   507
    if is_mentor:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   508
        if task.status in ["OP", "WR"]:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   509
            choices = [(_.id,_.username) for _ in task.mentors.all()]
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   510
            if task.status == "WR":
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   511
                choices.extend([(_.id, _.username) for _  in task.assigned_users.all() ])
136
8632a44b743d deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents: 135
diff changeset
   512
            prev_credits = task.request_task.filter(role="PY",is_valid=True,is_replied=True,reply=True).count()
135
0ede6b2c5cd1 now view credits page shows all the credits.. including the pending and rejected ones.
nishanth
parents: 131
diff changeset
   513
            credit_requests = task.request_task.filter(role="PY",is_valid=True).order_by('creation_date').reverse()
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   514
            form = AssignCreditForm(choices)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   515
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   516
            context = {
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   517
                'user':user,
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 94
diff changeset
   518
                'task':task,
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   519
                'prev_credits':prev_credits,
135
0ede6b2c5cd1 now view credits page shows all the credits.. including the pending and rejected ones.
nishanth
parents: 131
diff changeset
   520
                'credit_requests':credit_requests,
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   521
                'form':form,
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   522
            }
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   523
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   524
            if request.method == "POST":
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   525
                data = request.POST
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   526
                form = AssignCreditForm(choices, data)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   527
                if form.is_valid():
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   528
                    data = form.cleaned_data
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   529
                    uid = data['user']
136
8632a44b743d deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents: 135
diff changeset
   530
                    points = data['pynts']
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   531
                    given_to = User.objects.get(id=uid)
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 94
diff changeset
   532
                    assignCredits(task=task, given_by=user, given_to=given_to, points=points)
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   533
                    return redirect('/task/assigncredits/tid=%s'%task.id)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   534
                else:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   535
                    context['form'] = form
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   536
                    return render_to_response('task/assigncredits.html', context)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   537
            else:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   538
                return render_to_response('task/assigncredits.html', context)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   539
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   540
            return show_msg(user, "Credits cannot be assigned at this stage", task_url, "view the task")
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   541
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   542
        return show_msg(user, "You are not authorised to perform this action", task_url, "view the task")
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   543
36
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   544
def edit_task(request, tid):
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   545
    """ see what are the attributes that can be edited depending on the current status
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   546
    and then give the user fields accordingly.
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   547
    """
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   548
    
180
972745147e3f fixed a bug in edit_task view.
nishanth
parents: 179
diff changeset
   549
    task = getTask(tid)
972745147e3f fixed a bug in edit_task view.
nishanth
parents: 179
diff changeset
   550
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   551
    task_url = "/task/view/tid=%s"%tid
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   552
    user = get_user(request.user) if request.user.is_authenticated() else request.user
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   553
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   554
    is_mentor = True if user in task.mentors.all() else False
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   555
    can_edit = True if is_mentor and task.status == "UP" else False
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   556
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   557
    if can_edit:
181
be8ad7e26176 now editing of tasks is done in elegant way.
nishanth
parents: 180
diff changeset
   558
        form = EditTaskForm(instance=task)
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   559
        if request.method=="POST":
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   560
            data = request.POST
181
be8ad7e26176 now editing of tasks is done in elegant way.
nishanth
parents: 180
diff changeset
   561
            form = EditTaskForm(data, instance=task)
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   562
            if form.is_valid():
181
be8ad7e26176 now editing of tasks is done in elegant way.
nishanth
parents: 180
diff changeset
   563
                form.save()
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   564
                return redirect(task_url)
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   565
            else:
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   566
                return render_to_response('task/edittask.html',{'user':user, 'form':form})
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   567
        else:
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   568
            return render_to_response('task/edittask.html',{'user':user, 'form':form})
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   569
    else:
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   570
        return show_msg(user, "You cannot edit the task at this stage", task_url, "view the task")
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 164
diff changeset
   571
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   572
def complete_task(request, tid):
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   573
    """ call the event called complete task.
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   574
    and also pass it the current user to know who marked it as complete. 
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   575
    """
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   576
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   577
    task_url = "/task/view/tid=%s"%tid
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   578
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   579
    user = get_user(request.user) if request.user.is_authenticated() else request.user
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   580
    task = getTask(tid)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   581
    
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   582
    is_guest = True if not user.is_authenticated() else False
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   583
    is_mentor = True if user in task.mentors.all() else False
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   584
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   585
    claimed_users = task.claimed_users.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   586
    assigned_users = task.assigned_users.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   587
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   588
    assign_credits_url = '/task/assigncredits/tid=%s'%task.id
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   589
    task_assigned_credits = task.credit_set.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   590
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   591
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   592
    if is_mentor:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   593
        if task.status in ["OP", "WR"]:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   594
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   595
            context = {
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   596
                'user':user,
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   597
                'task':task,
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   598
            }
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   599
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   600
            if task_assigned_credits:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   601
                if request.method=="POST":
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   602
                    completeTask(task, user)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   603
                    return redirect(task_url)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   604
                else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   605
                    return render_to_response('task/complete.html', context)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   606
            else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   607
                return show_msg(user, "Nobody has been credited for doing this task.", assign_credits_url, "assign credits")
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   608
        else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   609
            return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task")
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   610
    else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   611
        return show_msg(user, "You are not authorised to do this", task_url, "view the task")
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   612
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   613
def close_task(request, tid):
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   614
    """ task can be closed only if task is published.
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   615
    call the event close task if everything is fine.
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   616
    """
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   617
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   618
    task_url = "/task/view/tid=%s"%tid
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   619
    
141
2489392ffb56 added the functionality to request a user to be AD MG DV.
nishanth
parents: 138
diff changeset
   620
    user = get_user(request.user) if request.user.is_authenticated() else request.user
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   621
    task = getTask(tid)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   622
    
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   623
    is_guest = True if not user.is_authenticated() else False
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   624
    is_mentor = True if user in task.mentors.all() else False
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   625
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   626
    if is_mentor:
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   627
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   628
        context = {
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   629
            'user':user,
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   630
            'task':task,
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   631
        }
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   632
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   633
        if not task.status in ["UP", "CD", "DL", "CM"]:
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   634
            if request.method == "POST":
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   635
                data = request.POST
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   636
                if not data.get("reason", None):
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   637
                    context["error"] = "Please enter a reason for closing the task"
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   638
                    return render_to_response('task/close.html', context)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   639
                else:
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 151
diff changeset
   640
                    closeTask(task, user, data['reason'])
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   641
                    return show_msg(user, "The task has been closed.", task_url, "view the task.")
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   642
            else:
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   643
                return render_to_response('task/close.html', context)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   644
        else:
159
a74a32a5a3e1 finalised the look of all existing task views .
nishanth
parents: 158
diff changeset
   645
            return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task")
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   646
    else:
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 124
diff changeset
   647
        return show_msg(user, "You are not authorised to do this", task_url, "view the task")
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   648
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   649
def delete_task(request, tid):
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   650
    """ mark the task status as DL.
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   651
    take a reason from the user and pass on to all the other mentors.
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   652
    """
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   653
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   654
    task_url = "/task/view/tid=%s"%tid
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   655
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   656
    task = getTask(tid)
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   657
    user = get_user(request.user) if request.user.is_authenticated() else request.user
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   658
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   659
    if task.status == "DL":
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   660
        return show_msg(user, "This task no longer exists", '/task/browse/', "to browse other tasks")
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   661
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   662
    can_delete = True if task.status == "UP" and task.created_by == user else False
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   663
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   664
    if can_delete:
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   665
        if request.method == "POST":
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   666
            data = request.POST
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   667
            reason = data.get('reason', None)
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   668
            deleteTask(task, user, reason)
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   669
            return show_msg(user, "The task is deleted", '/', "to return to home page")
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   670
        else:
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   671
            return render_to_response('task/delete.html',{'user':user,})
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   672
    else:
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   673
        return show_msg(user, "You are not authorised to do this at this stage", task_url, "view the task")