taskapp/views/task.py
author nishanth
Fri, 26 Feb 2010 22:45:19 +0530
changeset 124 6d92b7cd2a37
parent 120 aad4e6065d85
child 126 e5377fdaf110
permissions -rw-r--r--
taking care if publish task post request is made again. added published_date field to task.
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
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
     3
from django.http import HttpResponse
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
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
     6
from pytask.taskapp.models import User, Task, Comment, Claim, Credit
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents: 114
diff changeset
     7
from pytask.taskapp.utilities.task import getTask
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
     8
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents: 114
diff changeset
     9
from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask
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
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    11
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    12
## 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
    13
## do not create su user thro syncdb
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    14
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    15
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
    16
    """ 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
    17
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    18
    user = 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
    19
    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
    20
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    21
    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
    22
               '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
    23
               }
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    24
    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
    25
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    26
def publish_task(request, tid):
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    27
    """ 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
    28
    """
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    29
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    30
    task_url = "/task/view/tid=%s"%tid
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    31
    
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    32
    user = request.user
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    33
    task = getTask(tid)
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    34
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    35
    is_guest = True if not user.is_authenticated() else False
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    36
    is_mentor = True if user in task.mentors.all() else False
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    37
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    38
    if user == task.created_by:
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    39
        context = {
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    40
            'user':user,
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    41
        }
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    42
        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
    43
            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
    44
                publishTask(task)
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    45
                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
    46
            else:
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    47
                return render_to_response('task/publish.html', context)
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    48
        else:
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    49
            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
    50
    else:
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    51
        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
    52
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    53
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
    54
    """ 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
    55
    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
    56
    """
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    57
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    58
    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
    59
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    60
    user = request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
    61
    task = getTask(tid)
110
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    62
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    63
    if task.status == "DL":
3685c2333448 now deleted tasks cannot be viewed by anyone
nishanth
parents: 109
diff changeset
    64
        return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
112
eadff01e395e now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents: 111
diff changeset
    65
    comments = task.comment_set.filter(is_deleted=False)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    66
    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
    67
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
    68
    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
    69
    
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    70
    errors = []
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
    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
    73
    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
    74
    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
    75
               '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
    76
               'comments':comments,
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    77
               'mentors':mentors,
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    78
               'subs':subs,
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    79
               '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
    80
               '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
    81
               'is_mentor':is_mentor,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    82
               'errors':errors,
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    83
              }
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    84
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 110
diff changeset
    85
    context['can_publish'] = 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
    86
    context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    87
    context['task_claimable'] = True if task.status in ["OP", "WR"] else False
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    88
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    89
    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
    90
    context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    91
    context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    92
    
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
    93
    context['assigned_users'] = task.assigned_users.all()
64
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    94
   
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    95
    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
    96
        if not 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
    97
            data = request.POST["data"]
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    98
            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
    99
            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
   100
            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
   101
        else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   102
            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
   103
            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
   104
    else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
   105
        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
   106
        
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
   107
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
   108
    """ 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
   109
    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
   110
    """
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
   111
    
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
   112
    user = request.user
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
   113
    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
   114
    
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
   115
    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
   116
        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
   117
        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
   118
        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
   119
            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
   120
                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
   121
                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
   122
                    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
   123
                    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
   124
                    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
   125
                    credits = data['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
   126
                    publish = data['publish']
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
   127
                    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
   128
                    
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
   129
                    if not 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
   130
                        error_msg = "Another task with the same title exists"
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
   131
                        return render_to_response('task/create.html',{'form':form, 'error_msg':error_msg})
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
   132
                    
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
   133
                    addMentor(task, user)
66
f670de53402b modified view task template and view to suit new design.
nishanth
parents: 64
diff changeset
   134
                    updateTask(task,tags_field=data['tags_field'])
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
   135
                    if publish: publishTask(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
   136
                    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
   137
                    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
   138
                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
   139
                    return render_to_response('task/create.html',{'form':form})
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
            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
   141
                form = TaskCreateForm()
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
                return render_to_response('task/create.html',{'form':form})
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
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   144
            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
   145
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   146
        return show_msg(user, 'You are not authorised to create a task.')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   147
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   148
def add_mentor(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   149
    """ 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
   150
    if user is not authenticated, redirect him to concerned page. """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   151
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   152
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   153
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   154
    user = request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   155
    task = getTask(tid)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   156
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   157
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   158
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   159
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   160
    if (not is_guest) and user in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   161
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   162
        ## 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
   163
        user_list = list(User.objects.filter(is_active=True))
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   164
        for mentor in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   165
            user_list.remove(mentor)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   166
            
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   167
        for a_user in task.claimed_users.all():
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   168
            user_list.remove(a_user)
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   169
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   170
        for a_user in task.assigned_users.all():
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   171
            user_list.remove(a_user)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   172
            
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   173
        non_mentors = ((_.id,_.username) for _ in user_list)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   174
        ## code till must be made elegant and not brute force like above
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
        form = AddMentorForm(non_mentors)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   177
        if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   178
            uid = request.POST['mentor']
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   179
            new_mentor = User.objects.get(id=uid)
105
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 96
diff changeset
   180
            reqMentor(task, new_mentor, user)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   181
            return redirect(task_url)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   182
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   183
            return render_to_response('task/addmentor.html', {'form':form, 'errors':errors})
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   184
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   185
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   186
        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
   187
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   188
def add_tasks(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   189
    """ 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
   190
    """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   191
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   192
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   193
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   194
    user = request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   195
    task = getTask(tid)
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   196
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
   197
    deps, subs = task.deps, task.subs
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   198
    is_plain = False if deps or subs else True
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   199
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   200
    ## again a brute force method
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   201
    valid_tasks = []
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   202
    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
   203
        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
   204
            valid_tasks.append(a_task)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   205
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   206
    task_choices = [ (_.id,_.title) for _ in valid_tasks ]
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   207
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   208
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   209
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   210
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   211
    if (not is_guest) and user in task.mentors.all():
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   212
        if task.status in ["UP", "OP", "LO"]:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   213
            form = AddTaskForm(task_choices, is_plain)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   214
            if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   215
                ## 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
   216
                ## only exclude tasks with status deleted
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   217
                data = request.POST
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   218
                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
   219
                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
   220
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   221
                if not errors:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   222
                    if is_plain:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   223
                        update_method = addDep if data['type'] == "D" else addSubTask
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   224
                    elif deps:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   225
                        update_method = addDep
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   226
                    elif subs:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   227
                        update_method = addSubTask
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   228
                    else:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   229
                        print "Screw you"
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   230
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   231
                    ## we might iterate over a task list later on
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   232
                    task_id = data['task']
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   233
                    sub_or_dep = getTask(task_id)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   234
                    update_method(task, sub_or_dep)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   235
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   236
                    return redirect(task_url)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   237
                else:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   238
                    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
   239
            else:
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   240
                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
   241
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   242
            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
   243
#            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
   244
            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
   245
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   246
        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
   247
    
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   248
def remove_task(request, tid):
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   249
    """ display a list of tasks and remove the selectes ones.
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   250
    """
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 76
diff changeset
   251
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   252
    task_url = "/task/view/tid=%s"%tid
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   253
    
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   254
    user = request.user
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   255
    task = getTask(tid)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   256
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   257
    is_guest = True if not user.is_authenticated() else False
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   258
    if (not is_guest) and user in task.mentors.all():
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   259
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   260
        deps, subs = task.deps, task.subs
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   261
        task_list = deps if task.sub_type == "D" else subs
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   262
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   263
        if task_list:
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   264
            choices = [(_.id,_.title) for _ in task_list ]
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   265
            form = ChoiceForm(choices)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   266
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   267
            errors = []
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   268
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   269
            if request.method == "POST":
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   270
                data = request.POST
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   271
                if not data.get('choice', None): errors.append("Please choose a task to remove.")
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   272
                if not errors:
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   273
                    tid = data['choice']
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   274
                    sub_task = getTask(tid)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   275
                    removeTask(task, sub_task)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   276
                    return redirect(task_url)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   277
                else:
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   278
                    return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   279
            else:
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   280
                return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   281
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   282
            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
   283
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   284
        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
   285
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   286
def claim_task(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   287
    """ 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
   288
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   289
    ## 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
   290
    ## 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
   291
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   292
    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
   293
    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
   294
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   295
    errors = []
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   296
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   297
    user = request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   298
    task = getTask(tid)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   299
    claims = Claim.objects.filter(task=task)
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   300
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   301
    mentors = task.mentors.all()
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   302
    claimed_users = task.claimed_users.all()
76
00a41fbf4958 fixed a bug in add_claim view in views/task .
nishanth
parents: 75
diff changeset
   303
    assigned_users = task.assigned_users.all()
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   304
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   305
    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
   306
    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
   307
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   308
    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
   309
    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
   310
    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
   311
    
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   312
    context = {'user':user,
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   313
               'is_mentor':is_mentor,
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   314
               'task':task,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   315
               'claims':claims,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   316
               '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
   317
               '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
   318
               'task_claimed':task_claimed,
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   319
               'errors':errors}
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   320
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   321
    if not is_guest:
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   322
        if request.method == "POST":
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   323
            claim_proposal = request.POST['message']
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   324
            if claim_proposal:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   325
                addClaim(task, claim_proposal, user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   326
                return redirect(claim_url)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   327
            else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   328
                errors.append('Please fill up proposal in the field below')
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   329
                return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   330
        else:
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   331
            return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   332
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   333
        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
   334
    
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   335
def rem_user(request, tid):
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   336
    """ 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
   337
    """
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
   338
    
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   339
    task_url = "/task/view/tid=%s"%tid
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   340
    
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   341
    user = request.user
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   342
    task = getTask(tid)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   343
    
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   344
    is_guest = True if not user.is_authenticated() else False
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   345
    is_mentor = True if user in task.mentors.all() else False
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   346
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   347
    if (not is_guest) and is_mentor:
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   348
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   349
        assigned_users = task.assigned_users.all()
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   350
        choices = [ (_.id,_.username) for _ in assigned_users ]
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   351
        context = {
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   352
            'user':user,
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   353
            'task':task,
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   354
        }
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   355
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   356
        if assigned_users:
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   357
            form = RemoveUserForm(choices)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   358
            context['form'] = form
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   359
            if request.method == "POST":
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   360
                data = request.POST
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   361
                form = RemoveUserForm(choices, data)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   362
                if form.is_valid():
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   363
                    data = form.cleaned_data
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   364
                    uid = data['user']
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   365
                    rem_user = User.objects.get(id=uid)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   366
                    removeUser(task, rem_user)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   367
                    print data['reason']
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   368
                    return redirect(task_url)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   369
                else:
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   370
                    context['form'] = form
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   371
                    return render_to_response('task/remove_user.html', context)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   372
            else:
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   373
                return render_to_response('task/remove_user.html',context)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
   374
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   375
            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
   376
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   377
        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
   378
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   379
def assign_task(request, tid):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   380
    """ 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
   381
    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
   382
    """
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
   383
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   384
    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
   385
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   386
    user = request.user
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
   387
    task = getTask(tid)
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   388
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   389
    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
   390
    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
   391
75
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   392
    claimed_users = task.claimed_users.all()
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   393
    assigned_users = task.assigned_users.all()
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   394
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   395
    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
   396
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   397
    if (not is_guest) and is_mentor:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   398
        if task_claimed:
75
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   399
            user_list = ((user.id,user.username) for user in claimed_users)
91
1b5ad4b7c40e modified the name of assign_task_form to choice form since all it does is return a form with choices and made change accordingly.
nishanth
parents: 90
diff changeset
   400
            form = ChoiceForm(user_list)
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
   401
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   402
            if request.method == "POST":
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
   403
                uid = request.POST['choice']
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   404
                assigned_user = User.objects.get(id=uid)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   405
                assignTask(task, assigned_user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   406
                return redirect(task_url)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   407
            else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   408
                return render_to_response('task/assign.html',{'form':form})
75
fa59955a340b modified the assign task view to suit the new design
nishanth
parents: 72
diff changeset
   409
        elif assigned_users:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   410
            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
   411
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   412
            return show_msg(user, 'Wait for ppl to claim dude... slow and steady wins the race :)', 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
   413
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   414
        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
   415
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   416
def assign_credits(request, tid):
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   417
    """ 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
   418
    Then display all the approved credits.
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   419
    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
   420
    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
   421
    """
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   422
    
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   423
    task_url = "/task/view/tid=%s"%tid
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   424
    
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   425
    user = request.user
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   426
    task = getTask(tid)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   427
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   428
    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
   429
    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
   430
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   431
    if is_mentor:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   432
        if task.status in ["OP", "WR"]:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   433
            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
   434
            if task.status == "WR":
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   435
                choices.extend([(_.id, _.username) for _  in task.assigned_users.all() ])
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   436
            prev_credits = task.credit_set.all()
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   437
            ## here we can ditchax credits model and use the request model
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   438
            form = AssignCreditForm(choices)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   439
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   440
            context = {
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   441
                'user':user,
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 94
diff changeset
   442
                'task':task,
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   443
                'prev_credits':prev_credits,
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   444
                'form':form,
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   445
            }
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   446
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   447
            if request.method == "POST":
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   448
                data = request.POST
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   449
                form = AssignCreditForm(choices, data)
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   450
                if form.is_valid():
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   451
                    data = form.cleaned_data
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   452
                    uid = data['user']
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   453
                    points = data['points']
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   454
                    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
   455
                    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
   456
                    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
   457
                else:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   458
                    context['form'] = form
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   459
                    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
   460
            else:
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
   461
                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
   462
        else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   463
            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
   464
    else:
108
131554cc3434 updated show_msg method to also use the user variable in the context.
nishanth
parents: 105
diff changeset
   465
        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
   466
36
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   467
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
   468
    """ 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
   469
    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
   470
    """
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   471
    
72
9fc60a221016 modified claim_task view to suit the new design
nishanth
parents: 66
diff changeset
   472
    task = Task.objects.get(id=tid) 
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   473
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   474
def complete_task(request, tid):
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   475
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   476
    """ call the event called complete task.
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   477
    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
   478
    """
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   479
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   480
    task_url = "/task/view/tid=%s"%tid
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   481
    
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   482
    user = request.user
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   483
    task = getTask(tid)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   484
    
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   485
    is_guest = True if not user.is_authenticated() else False
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   486
    is_mentor = True if user in task.mentors.all() else False
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   487
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   488
    claimed_users = task.claimed_users.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   489
    assigned_users = task.assigned_users.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   490
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   491
    assign_credits_url = '/task/assigncredits/tid=%s'%task.id
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   492
    task_assigned_credits = task.credit_set.all()
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   493
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   494
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   495
    if is_mentor:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   496
        if task.status in ["OP", "WR"]:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   497
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   498
            context = {
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   499
                'user':user,
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   500
                'task':task,
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   501
            }
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   502
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   503
            if task_assigned_credits:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   504
                if request.method=="POST":
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   505
                    completeTask(task, user)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   506
                    return redirect(task_url)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   507
                else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   508
                    return render_to_response('task/complete.html', context)
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   509
            else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   510
                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
   511
        else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   512
            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
   513
    else:
38793914921b mark task as complete functionality is added.
nishanth
parents: 112
diff changeset
   514
        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
   515