taskapp/views/task.py
author nishanth
Thu, 04 Feb 2010 23:10:30 +0530
changeset 22 36d3173ab7f9
parent 21 c28774fe7ffd
child 25 c0e4fc8b8b5b
permissions -rw-r--r--
addded link to view claims in 'view task' page .
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
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
     7
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm 
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
     8
from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask
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
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    33
    task = Task.objects.get(id=tid)
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
    
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    41
    task_claimable = True if task.status in ["OP", "RE"] else False
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    42
    user_can_view_claim = True if ( task_claimable and not ( is_guest or is_mentor ) ) else False
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    43
    
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    44
    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
    45
               '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
    46
               'comments':comments,
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    47
               '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
    48
               '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
    49
               'is_mentor':is_mentor,
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    50
               'user_can_view_claim':user_can_view_claim,
17
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    51
               '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
    52
               }
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    53
    
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    54
    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
    55
        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
    56
            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
    57
            task = Task.objects.get(id=tid)
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    58
            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
    59
            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
    60
            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
    61
        else:
aa45fec40e7e renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff changeset
    62
            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
    63
            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
    64
    else:
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)
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
    66
        
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
    67
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
    68
    """ 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
    69
    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
    70
    """
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
    
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
    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
    73
    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
    74
    
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
    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
    76
        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
    77
        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
    78
        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
    79
            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
    80
                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
    81
                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
    82
                    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
    83
                    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
    84
                    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
    85
                    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
    86
                    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
    87
                    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
    88
                    
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
                    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
    90
                        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
    91
                        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
    92
                    
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
                    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
    94
                    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
    95
                    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
    96
                    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
    97
                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
    98
                    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
    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
                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
   101
                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
   102
        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
   103
            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
   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.')
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   106
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   107
def add_mentor(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   108
    """ 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
   109
    if user is not authenticated, redirect him to concerned page. """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   110
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   111
    task_url = "/task/view/tid=%s"%tid
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
    user = request.user
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   114
    task = Task.objects.get(id=tid)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   115
    errors = []
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   116
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   117
    is_guest = True if not user.is_authenticated() else False
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
    if (not is_guest) and user in task.mentors.all():
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
        ## now iam going for a brute force method
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   122
        user_list = list(User.objects.all())
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   123
        for mentor in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   124
            user_list.remove(mentor)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   125
        non_mentors = ((_.id,_.username) for _ in user_list)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   126
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   127
        form = AddMentorForm(non_mentors)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   128
        if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   129
            uid = request.POST['mentor']
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   130
            new_mentor = User.objects.get(id=uid)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   131
            addMentor(task, new_mentor)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   132
            return redirect(task_url)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   133
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   134
            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
   135
        
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   136
    else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   137
        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
   138
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   139
def add_tasks(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   140
    """ 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
   141
    """
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
    task_url = "/task/view/tid=%s"%tid
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   144
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   145
    user = request.user
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   146
    task = Task.objects.get(id=tid)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   147
    errors = []
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
    is_guest = True if not user.is_authenticated() else False
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   150
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   151
    if (not is_guest) and user in task.mentors.all():
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   152
        if task.status in ["OP", "LO"]:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   153
            if request.method == "POST":
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   154
                ## 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
   155
                ## only exclude tasks with status deleted
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   156
                pass
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   157
            else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   158
                ## 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
   159
                pass
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   160
        else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   161
            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
   162
#            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
   163
            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
   164
    else:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   165
        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
   166
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   167
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   168
def claim_task(request, tid):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   169
    """ 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
   170
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   171
    ## 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
   172
    ## 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
   173
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   174
    task_url = "/task/view/tid=%s"%tid
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
    user = request.user
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
   177
    task = Task.objects.get(id=tid)
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   178
    claims = Claim.objects.filter(task=task)
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   179
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   180
    is_guest = True if not user.is_authenticated() else False
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   181
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   182
    task_claimable = True if task.status in ["OP", "RE"] else False
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   183
    user_can_claim = True if ( task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() ) ) else False
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   184
    
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   185
    if not is_guest:
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   186
        if task_claimable:
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   187
            pass
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   188
        else:
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   189
            return show_msg('You are not logged in to view claims for this task', task_url, 'view the task')
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   190
    else:
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
   191
        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
   192
    
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
   193
    
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
   194
    
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
   195
    
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
   196