taskapp/views/task.py
author nishanth
Wed, 24 Feb 2010 11:04:11 +0530
changeset 64 e743fe1f0f99
parent 55 ca2486e29178
child 66 f670de53402b
permissions -rw-r--r--
updated view task in views to suit the new design .
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
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
     6
from pytask.taskapp.models import User, Task, Comment, Claim
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
     7
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
     8
from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addClaim, assignTask, getTask
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
     9
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
    10
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    11
## 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
    12
## do not create su user thro syncdb
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    13
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    14
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
    15
    """ 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
    16
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    17
    user = request.user
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    18
    task_list = Task.objects.order_by('id').reverse()
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    19
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    20
    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
    21
               '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
    22
               }
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    23
    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
    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
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
    26
    """ 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
    27
    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
    28
    """
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    29
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    30
    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
    31
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    32
    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
    33
    task = getTask(tid)
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    34
    comments = Comment.objects.filter(task=task)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    35
    mentors = task.mentors.all()
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    36
    errors = []
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    37
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    38
    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
    39
    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
    40
    
64
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    41
    task_claimable = True if task.status in ["OP", "WR"] else False
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    42
    
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    43
    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
    44
               '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
    45
               'comments':comments,
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    46
               'mentors':mentors,
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    47
               '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
    48
               '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
    49
               'errors':errors,
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    50
               }
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    51
               
64
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    52
    assigned_users = task.assigned_users.all()
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    53
    if assigned_users:
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    54
        context['assigned_users'] = assigned_users
e743fe1f0f99 updated view task in views to suit the new design .
nishanth
parents: 55
diff changeset
    55
   
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    56
    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
    57
        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
    58
            data = request.POST["data"]
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 36
diff changeset
    59
            task = getTask(tid)
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    60
            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
    61
            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
    62
            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
    63
        else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    64
            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
    65
            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
    66
    else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    67
        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
    68
        
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
    69
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
    70
    """ 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
    71
    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
    72
    """
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
    73
    
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
    74
    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
    75
    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
    76
    
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
    77
    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
    78
        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
    79
        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
    80
        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
    81
            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
    82
                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
    83
                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
    84
                    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
    85
                    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
    86
                    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
    87
                    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
    88
                    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
    89
                    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
    90
                    
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
    91
                    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
    92
                        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
    93
                        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
    94
                    
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
    95
                    addMentor(task, 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
    96
                    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
    97
                    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
    98
                    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
    99
                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
   100
                    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
   101
            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
   102
                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
   103
                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
   104
        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
   105
            return show_msg('You are not authorised to create a 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
   106
    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
   107
        return show_msg('You are not authorised to create a task.')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   108
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   109
def add_mentor(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   110
    """ 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
   111
    if user is not authenticated, redirect him to concerned page. """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   112
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   113
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   114
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   115
    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
   116
    task = getTask(tid)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   117
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   118
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   119
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   120
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   121
    if (not is_guest) and user in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   122
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   123
        ## now iam going for a brute force method
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   124
        user_list = list(User.objects.all())
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   125
        for mentor in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   126
            user_list.remove(mentor)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   127
            
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   128
        for a_user in task.claimed_users.all():
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   129
            user_list.remove(a_user)
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   130
            
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   131
        non_mentors = ((_.id,_.username) for _ in user_list)
34
22f302094806 fixed a bug in views/task/add_mentor method .
nishanth
parents: 33
diff changeset
   132
        ## 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
   133
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   134
        form = AddMentorForm(non_mentors)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   135
        if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   136
            uid = request.POST['mentor']
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   137
            new_mentor = User.objects.get(id=uid)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   138
            addMentor(task, new_mentor)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   139
            return redirect(task_url)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   140
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   141
            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
   142
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   143
    else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   144
        return show_msg('You are not authorised to add mentors for this task', task_url, 'view the task')
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   145
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   146
def add_tasks(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   147
    """ 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
   148
    """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   149
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   150
    task_url = "/task/view/tid=%s"%tid
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
    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
   153
    task = getTask(tid)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   154
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   155
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   156
    is_guest = True if not user.is_authenticated() else False
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
    if (not is_guest) and user in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   159
        if task.status in ["OP", "LO"]:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   160
            if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   161
                ## 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
   162
                ## only exclude tasks with status deleted
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   163
                pass
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   164
            else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   165
                ## write a form just like add mentor and get the form here
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   166
                pass
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   167
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   168
            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
   169
#            return render_to_response('task/add.html', {'form':form, 'errors':errors})
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   170
            return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task')
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   171
    else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   172
        return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   173
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   174
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   175
def claim_task(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   176
    """ 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
   177
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   178
    ## 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
   179
    ## 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
   180
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   181
    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
   182
    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
   183
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   184
    errors = []
21
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
    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
   187
    task = getTask(tid)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   188
    claims = Claim.objects.filter(task=task)
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   189
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   190
    is_guest = True if not user.is_authenticated() else False
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   191
    if user in task.mentors.all():
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   192
        is_mentor = True 
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   193
    else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   194
         is_mentor = False
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   195
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   196
    task_claimable = True if task.status in ["OP", "RE", "CL"] else False
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   197
    user_can_claim = True if  task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() )  else False
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
   198
    task_claimed = True if task.status == "CL" else False
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   199
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   200
    context = {'is_mentor':is_mentor,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   201
               'task':task,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   202
               'claims':claims,
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   203
               '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
   204
               '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
   205
               'task_claimed':task_claimed,
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   206
               'errors':errors}
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   207
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   208
    if not is_guest:
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   209
        if request.method == "POST":
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   210
            claim_proposal = request.POST['message']
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   211
            if claim_proposal:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   212
                addClaim(task, claim_proposal, user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   213
                return redirect(claim_url)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   214
            else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   215
                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
   216
                return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   217
        else:
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   218
            return render_to_response('task/claim.html', context)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   219
    else:
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   220
        return show_msg('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
   221
    
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
   222
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   223
def assign_task(request, tid):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   224
    """ 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
   225
    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
   226
    """
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
   227
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   228
    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
   229
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   230
    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
   231
    task = getTask(tid)
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   232
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   233
    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
   234
    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
   235
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   236
    task_claimed = True if task.status == "CL" 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
   237
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   238
    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
   239
        if task_claimed:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   240
            user_list = ((user.id,user.username) for user in task.claimed_users.all())
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   241
            form = AssignTaskForm(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
   242
    
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   243
            if request.method == "POST":
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   244
                uid = request.POST['user']
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   245
                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
   246
                assignTask(task, assigned_user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   247
                return redirect(task_url)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   248
            else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   249
                return render_to_response('task/assign.html',{'form':form})
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
   250
        elif task.status == "AS":
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
   251
            return show_msg('The task is already assigned', task_url, 'view the task')
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
   252
        elif task.status == "OP":
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
   253
            return show_msg('No one has still claimed the task', 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
   254
        else:
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
   255
            return show_msg('The task status is %s. how can you assign it now'%task.status, 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
   256
    else:
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   257
        return show_msg('You are not authorised to perform this action', task_url, 'view the task')
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   258
        
36
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   259
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
   260
    """ 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
   261
    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
   262
    """
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
   263
    
36
0f10deac0a9b made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents: 34
diff changeset
   264
    return None