pytask/taskapp/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 15 Jan 2011 03:59:00 +0530
changeset 408 0c12181e2c02
parent 387 32dd15eaf9d0
child 422 4bb891fc7a54
permissions -rwxr-xr-x
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
     1
from datetime import datetime
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
     2
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
     3
from django.http import Http404
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
     4
from django.contrib.auth.decorators import login_required
362
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
     5
from django.contrib.auth.models import User
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
     6
from django.core.context_processors import csrf
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
     7
from django.core.urlresolvers import reverse
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
     8
from django.shortcuts import redirect
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
     9
from django.shortcuts import render_to_response
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    10
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    11
from pytask.taskapp.forms import ChoiceForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    12
from pytask.taskapp.forms import ClaimTaskForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    13
from pytask.taskapp.forms import CreateTaskForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    14
from pytask.taskapp.forms import CreateTextbookForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    15
from pytask.taskapp.forms import EditTaskForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    16
from pytask.taskapp.forms import EditTextbookForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    17
from pytask.taskapp.forms import TaskCommentForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    18
from pytask.taskapp.forms import WorkReportForm
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    19
from pytask.taskapp.models import Task
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    20
from pytask.taskapp.models import TaskComment
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    21
from pytask.taskapp.models import TaskClaim
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    22
from pytask.taskapp.models import TextBook
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    23
from pytask.taskapp.models import WorkReport
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    24
from pytask.taskapp.utils import getTask
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    25
from pytask.taskapp.utils import getTextBook
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    26
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    27
from pytask.views import show_msg
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    28
339
bce480ff6ddc used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents: 333
diff changeset
    29
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    30
@login_required
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    31
def create_task(request):
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    32
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    33
    user = request.user
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    34
    profile = user.get_profile()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    35
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    36
    context = {"user": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    37
               "profile": profile,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    38
              }
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    39
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    40
    context.update(csrf(request))
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    41
340
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    42
    can_create_task = False if profile.rights == "CT" else True
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    43
    if can_create_task:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    44
        if request.method == "POST":
340
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    45
            form = CreateTaskForm(request.POST)
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    46
            if form.is_valid():
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    47
                data = form.cleaned_data.copy()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    48
                data.update({"created_by": user,
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    49
                             "creation_datetime": datetime.now(),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    50
                             "uniq_key": make_key(Task),
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    51
                            })
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    52
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    53
                task = Task(**data)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    54
                task.save()
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    55
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    56
                task_url = reverse('view_task', kwargs={'task_id': task.id})
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    57
                return redirect(task_url)
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    58
            else:
340
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    59
                context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    60
                return render_to_response('task/create.html', context)
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    61
        else:
340
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    62
            form = CreateTaskForm()
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    63
            context.update({'form':form})
0f9d485609ac fixed a few bugs
Nishanth Amuluru <nishanth@fossee.in>
parents: 339
diff changeset
    64
            return render_to_response('task/create.html', context)
333
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    65
    else:
eb3a191850a1 created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
    66
        return show_msg(user, 'You are not authorised to create a task.')
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
    67
376
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    68
def browse_tasks(request):
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    69
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    70
    open_tasks = Task.objects.filter(status="OP")
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    71
    working_tasks = Task.objects.filter(status="WR")
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    72
    comp_tasks = Task.objects.filter(status="CM")
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    73
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    74
    context = {"open_tasks": open_tasks,
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    75
               "working_tasks": working_tasks,
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    76
               "comp_tasks": comp_tasks,
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    77
              }
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    78
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    79
    user = request.user
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    80
    if not user.is_authenticated():
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    81
        return render_to_response("task/browse.html")
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    82
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    83
    profile = user.get_profile()
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    84
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    85
    can_approve = True if profile.rights in ["MG", "DC"] else False
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    86
    unpub_tasks = Task.objects.filter(status="UP").exclude(status="DL")
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    87
    if can_approve:
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    88
        context.update({"unpub_tasks": unpub_tasks})
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    89
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    90
    context.update({"user": user,
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    91
                    "profile": profile,
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    92
                   })
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    93
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    94
    return render_to_response("task/browse.html", context)
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    95
5a94c774473c browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 374
diff changeset
    96
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    97
def view_task(request, task_id):
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
    98
    """ get the task depending on its task_id and display accordingly if it is a get.
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
    99
    check for authentication and add a comment if it is a post request.
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   100
    """
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   101
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   102
    task_url = reverse('view_task', kwargs={'task_id': task_id})
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   103
    task = getTask(task_id)
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   104
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   105
    user = request.user
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   106
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   107
    if not user.is_authenticated():
386
026f2059a97a fixed a few broken links to templates
Nishanth Amuluru <nishanth@fossee.in>
parents: 383
diff changeset
   108
        return render_to_response("task/view.html", {"task": task})
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   109
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   110
    profile = user.get_profile()
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   111
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   112
    context = {"user": user,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   113
               "profile": profile,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   114
               "task": task,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   115
              }
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   116
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   117
    context.update(csrf(request))
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   118
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   119
    if task.status == "DL":
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   120
        return show_msg(user, 'This task no longer exists',
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   121
                        reverse('browse_tasks'), 'browse the tasks')
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   122
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   123
    task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   124
                         else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   125
    if not task_viewable:
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   126
        return show_msg(user, "You are not authorised to view this task",
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   127
                        reverse('browse_tasks'), "browse the tasks")
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   128
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   129
    reviewers = task.reviewers.all()
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   130
    is_reviewer = True if user in task.reviewers.all() else False
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   131
    comments = task.comments.filter(
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   132
      is_deleted=False).order_by('comment_datetime')
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   133
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   134
    context.update({'is_reviewer':is_reviewer,
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   135
                    'comments':comments,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   136
                    'reviewers':reviewers,
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   137
                   })
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   138
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   139
    claimed_users = task.claimed_users.all()
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   140
    selected_users = task.selected_users.all()
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   141
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   142
    is_creator = True if user == task.created_by else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   143
    has_claimed = True if user in claimed_users else False
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   144
365
32457bce3437 prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents: 363
diff changeset
   145
    context['selected_users'] = selected_users
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   146
    context['is_selected'] = True if user in selected_users else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   147
    context['can_approve'] = True if task.status == "UP" and\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   148
                                     profile.rights in ["MG", "DC"]\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   149
                                     else False
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   150
    context['can_edit'] = True if is_creator and task.status == "UP" else False
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   151
    context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   152
    context['can_delete'] = True if task.status == "UP" and is_creator else False
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   153
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   154
    context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   155
    context['task_claimable'] = True if task.status in ["OP", "WR"] else False
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   156
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   157
    context['can_comment'] = True if task.status != "UP" or\
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   158
                                     profile.rights!="CT" else False
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   159
381
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   160
    context['can_mod_reviewers'] = True if profile.rights in ["MG", "DC"] else\
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   161
                                   False
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   162
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   163
    if request.method == 'POST':
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   164
        form = TaskCommentForm(request.POST)
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   165
        if form.is_valid():
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   166
            data = form.cleaned_data['data']
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   167
            new_comment = TaskComment(task=task, data=data,
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   168
                                      uniq_key=make_key(TaskComment),
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   169
                                      commented_by=user, comment_datetime=datetime.now())
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   170
            new_comment.save()
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   171
            return redirect(task_url)
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   172
        else:
350
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   173
            context['form'] = form
4cc40503bf3c view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents: 349
diff changeset
   174
            return render_to_response('task/view.html', context)
349
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   175
    else:
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   176
        form = TaskCommentForm()
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   177
        context['form'] = form
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   178
        return render_to_response('task/view.html', context)
1cc8d0b2eefb commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents: 340
diff changeset
   179
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   180
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   181
def edit_task(request, task_id):
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   182
    """ only creator gets to edit the task and that too only before it gets
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   183
    approved.
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   184
    """
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   185
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   186
    user = request.user
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   187
    profile = user.get_profile()
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   188
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   189
    task_url = reverse('view_task', kwargs={'task_id': task_id})
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   190
    task = getTask(task_id)
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   191
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   192
    is_creator = True if user == task.created_by else False
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   193
    can_edit = True if task.status == "UP" and is_creator else False
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   194
    if not can_edit:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   195
        raise Http404
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   196
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   197
    context = {"user": user,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   198
               "profile": profile,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   199
               "task": task,
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   200
              }
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   201
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   202
    context.update(csrf(request))
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   203
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   204
    if request.method == "POST":
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   205
        form = EditTaskForm(request.POST, instance=task)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   206
        if form.is_valid():
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   207
            form.save()
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   208
            return redirect(task_url)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   209
        else:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   210
            context.update({"form": form})
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   211
            return render_to_response("task/edit.html", context)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   212
    else:
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   213
        form = EditTaskForm(instance=task)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   214
        context.update({"form": form})
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   215
        return render_to_response("task/edit.html", context)
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   216
368
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   217
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   218
def approve_task(request, task_id):
374
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   219
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   220
    user = request.user
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   221
    profile = user.get_profile()
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   222
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   223
    task = getTask(task_id)
374
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   224
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   225
    if profile.rights not in ["MG", "DC"] or task.status != "UP":
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   226
        raise Http404
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   227
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   228
    context = {"user": user,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   229
               "profile": profile,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   230
               "task": task,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   231
              }
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   232
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   233
    return render_to_response("task/confirm_approval.html", context)
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   234
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   235
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   236
def approved_task(request, task_id):
374
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   237
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   238
    user = request.user
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   239
    profile = user.get_profile()
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   240
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   241
    task = getTask(task_id)
374
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   242
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   243
    if profile.rights not in ["MG", "DC"] or task.status != "UP":
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   244
        raise Http404
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   245
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   246
    task.approved_by = user
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   247
    task.approval_datetime = datetime.now()
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   248
    task.status = "OP"
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   249
    task.save()
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   250
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   251
    context = {"user": user,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   252
               "profile": profile,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   253
               "task": task,
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   254
              }
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   255
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   256
    return render_to_response("task/approved_task.html", context)
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   257
cdd8026ee60e task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents: 373
diff changeset
   258
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   259
def addreviewer(request, task_id):
381
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   260
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   261
    user = request.user
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   262
    profile = user.get_profile()
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   263
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   264
    task_url = reverse('view_task', kwargs={'task_id': task_id})
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   265
    task = getTask(task_id)
381
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   266
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   267
    can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   268
    if not can_mod_reviewers:
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   269
        raise Http404
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   270
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   271
    context = {"user": user,
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   272
               "profile": profile,
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   273
               "task": task,
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   274
              }
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   275
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   276
    context.update(csrf(request))
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   277
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   278
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   279
    # This part has to be made better
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   280
    reviewer_choices = User.objects.filter(is_active=True).\
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   281
                                           exclude(reviewing_tasks__uniq_key=task_id).\
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   282
                                           exclude(claimed_tasks__uniq_key=task_id).\
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   283
                                           exclude(selected_tasks__uniq_key=task_id).\
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   284
                                           exclude(created_tasks__uniq_key=task_id)
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   285
381
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   286
    choices = ((a_user.id,a_user.username) for a_user in reviewer_choices)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   287
    label = "Reviewer"
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   288
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   289
    if request.method == "POST":
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   290
        form = ChoiceForm(choices, data=request.POST, label=label)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   291
        if form.is_valid():
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   292
            data = form.cleaned_data.copy()
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   293
            uid = data['choice']
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   294
            reviewer = User.objects.get(id=uid)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   295
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   296
            task.reviewers.add(reviewer)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   297
            return redirect(task_url)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   298
        else:
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   299
            context.update({"form": form})
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   300
            return render_to_response("task/addreviewer.html", context)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   301
    else:
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   302
        form = ChoiceForm(choices, label=label)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   303
        context.update({"form": form})
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   304
        return render_to_response("task/addreviewer.html", context)
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   305
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   306
def view_work(request, task_id):
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   307
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   308
    task = getTask(task_id)
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   309
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   310
    user = request.user
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   311
    old_reports = task.reports.all()
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   312
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   313
    context = {"task": task,
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   314
               "old_reports": old_reports,
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   315
              }
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   316
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   317
    if not user.is_authenticated():
386
026f2059a97a fixed a few broken links to templates
Nishanth Amuluru <nishanth@fossee.in>
parents: 383
diff changeset
   318
        return render_to_response("task/view_work.html", context)
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   319
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   320
    profile = user.get_profile()
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   321
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   322
    context.update({"user": user,
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   323
                    "profile": profile,
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   324
                   })
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   325
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   326
    context.update(csrf(request))
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   327
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   328
    working_users = task.selected_users.all()
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   329
    is_working = True if user in working_users else False
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   330
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   331
    context.update({"is_working": is_working})
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   332
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   333
    return render_to_response("task/view_work.html", context)
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   334
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   335
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   336
def view_report(request, report_id):
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   337
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   338
    try:
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   339
        report = WorkReport.objects.get(uniq_key=report_id)
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   340
    except WorkReport.DoesNotExist:
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   341
        raise Http404
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   342
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   343
    user = request.user
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   344
    context = {"report": report,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   345
               "user": user,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   346
              }
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   347
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   348
    if not user.is_authenticated():
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   349
        return render_to_response("task/view_report.html", context)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   350
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   351
    profile = user.get_profile()
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   352
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   353
    context.update({"profile": profile})
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   354
    return render_to_response("task/view_report.html", context)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   355
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   356
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   357
def submit_report(request, task_id):
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   358
    """ Check if the work is in WR state and the user is in assigned_users.
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   359
    """
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   360
    task_url = reverse('view_task', kwargs={'task_id': task_id})
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   361
    task = getTask(task_id)
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   362
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   363
    user = request.user
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   364
    old_reports = task.reports.all()
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   365
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   366
    if not task.status == "WR":
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   367
        raise Http404
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   368
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   369
    can_upload = True if user in task.selected_users.all() else False
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   370
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   371
    context = {
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   372
        'user': user,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   373
        'task': task,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   374
        'can_upload': can_upload,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   375
    }
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   376
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   377
    context.update(csrf(request))
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   378
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   379
    if request.method == "POST":
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   380
        if not can_upload:
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   381
            return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task")
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   382
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   383
        form = WorkReportForm(request.POST, request.FILES)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   384
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   385
        if form.is_valid():
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   386
            data = form.cleaned_data.copy()
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   387
            data.update({"task":task,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   388
                         "revision": old_reports.count(),
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   389
                         "uniq_key": make_key(WorkReport),
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   390
                         "submitted_by": user,
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   391
                         "submitted_at": datetime.now(),
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   392
                        })
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   393
            r = WorkReport(**data)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   394
            r.save()
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   395
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   396
            report_url = reverse('view_report', kwargs={'report_id': r.id})
383
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   397
            return redirect(report_url)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   398
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   399
        else:
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   400
            context.update({"form":form})
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   401
            return render_to_response('task/submit_report.html', context)
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   402
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   403
    else:
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   404
        form = WorkReportForm()
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   405
        context.update({"form":form})
4252da60a4ef submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 382
diff changeset
   406
        return render_to_response('task/submit_report.html', context)
382
daca865314e7 view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents: 381
diff changeset
   407
381
da4c6b1cec7d add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 380
diff changeset
   408
@login_required
368
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   409
def create_textbook(request):
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   410
368
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   411
    user = request.user
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   412
    profile = user.get_profile()
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   413
368
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   414
    can_create = True if profile.rights != "CT" else False
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   415
    if not can_create:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   416
        raise Http404
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   417
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   418
    context = {"user": user,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   419
               "profile": profile,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   420
              }
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   421
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   422
    context.update(csrf(request))
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   423
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   424
    if request.method == "POST":
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   425
        form = CreateTextbookForm(request.POST)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   426
        if form.is_valid():
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   427
            data = form.cleaned_data.copy()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   428
            data.update({"uniq_key": make_key(TextBook),
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   429
                         "created_by": user,
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   430
                         "creation_datetime": datetime.now()})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   431
            del data['chapters']
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   432
            new_textbook = TextBook(**data)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   433
            new_textbook.save()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   434
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   435
            new_textbook.chapters = form.cleaned_data['chapters']
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   436
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   437
            textbook_url = reverse(
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   438
              'view_textbook', kwargs={'task_id': new_textbook.id})
368
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   439
            return redirect(textbook_url)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   440
        else:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   441
            context.update({"form": form})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   442
            return render_to_response("task/create_textbook.html", context)
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   443
    else:
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   444
        form = CreateTextbookForm()
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   445
        context.update({"form": form})
a4fa11b2cb5c add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 366
diff changeset
   446
        return render_to_response("task/create_textbook.html", context)
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   447
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   448
def view_textbook(request, task_id):
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   449
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   450
    textbook = getTextBook(task_id)
387
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   451
    chapters = textbook.chapters.all()
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   452
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   453
    user = request.user
387
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   454
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   455
    context = {"user": user,
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   456
               "textbook": textbook,
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   457
               "chapters": chapters,
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   458
              }
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   459
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   460
    if not user.is_authenticated():
387
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   461
        return render_to_response("task/view_textbook.html", context)
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   462
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   463
    profile = user.get_profile()
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   464
387
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   465
    context.update({"profile": profile,
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   466
                    "textbook": textbook,
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   467
                   })
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   468
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   469
    context.update(csrf(request))
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   470
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   471
    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   472
                       else False
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   473
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   474
    can_approve = True if profile.rights in ["MG", "DC"] and \
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   475
                          textbook.status == "UP" else False
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   476
387
32dd15eaf9d0 fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents: 386
diff changeset
   477
    context.update({"can_edit": can_edit,
370
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   478
                    "can_approve": can_approve})
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   479
    return render_to_response("task/view_textbook.html", context)
1be4a3c09a47 view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 368
diff changeset
   480
372
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   481
def browse_textbooks(request):
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   482
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   483
    user = request.user
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   484
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   485
    open_textbooks = TextBook.objects.filter(status="OP").\
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   486
                                      order_by("creation_datetime")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   487
    comp_textbooks = TextBook.objects.filter(status="CM").\
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   488
                                      order_by("creation_datetime")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   489
    context = {"user": user,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   490
               "open_textbooks": open_textbooks,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   491
               "comp_textbooks": comp_textbooks,
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   492
              }
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   493
377
4f0cfd486d9b approve text book is meaningful now
Nishanth Amuluru <nishanth@fossee.in>
parents: 376
diff changeset
   494
    if user.is_authenticated() and user.get_profile().rights in ["DC", "MG"]:
372
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   495
        unpub_textbooks = TextBook.objects.filter(status="UP")
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   496
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   497
        context.update({"unpub_textbooks": unpub_textbooks})
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   498
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   499
    return render_to_response("task/browse_textbooks.html", context)
563fe356947d created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents: 370
diff changeset
   500
366
4c349f310dfc edit task works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 365
diff changeset
   501
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   502
def edit_textbook(request, task_id):
373
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   503
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   504
    user = request.user
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   505
    profile = user.get_profile()
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   506
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   507
    textbook = getTextBook(task_id)
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   508
    textbook_url = reverse(
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   509
      'view_textbook', kwargs={'task_id': textbook.id})
373
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   510
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   511
    can_edit = True if user == textbook.created_by and textbook.status == "UP"\
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   512
                       else False
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   513
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   514
    if not can_edit:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   515
        raise Http404
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   516
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   517
    context = {"user": user,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   518
               "profile": profile,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   519
               "textbook": textbook,
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   520
              }
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   521
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   522
    context.update(csrf(request))
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   523
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   524
    if request.method == "POST":
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   525
        form = EditTextbookForm(request.POST, instance=textbook)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   526
        if form.is_valid():
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   527
            form.save()
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   528
            return redirect(textbook_url)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   529
        else:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   530
            context.update({"form": form})
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   531
            return render_to_response("task/edit_textbook.html", context)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   532
    else:
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   533
        form = EditTextbookForm(instance=textbook)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   534
        context.update({"form": form})
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   535
        return render_to_response("task/edit_textbook.html", context)
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   536
014d812e625e edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 372
diff changeset
   537
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   538
def claim_task(request, task_id):
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   539
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   540
    claim_url = "/task/claim/task_id=%s"%task_id
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   541
    task = getTask(task_id)
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   542
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   543
    if task.status == "UP":
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   544
        raise Http404
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   545
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   546
    user = request.user
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   547
    profile = user.get_profile()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   548
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   549
    context = {"user": user,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   550
               "profile": profile,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   551
               "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   552
              }
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   553
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   554
    context.update(csrf(request))
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   555
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   556
    reviewers = task.reviewers.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   557
    claimed_users = task.claimed_users.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   558
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   559
    is_creator = True if user == task.created_by else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   560
    is_reviewer = True if user in reviewers else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   561
    has_claimed = True if user in claimed_users else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   562
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   563
    task_claimable = True if task.status in ["OP", "WR"] else False
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   564
    can_claim = True if task_claimable and ( not has_claimed )\
357
ec7f2f4256f5 now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents: 356
diff changeset
   565
                        and ( not is_reviewer ) and (not is_creator ) \
ec7f2f4256f5 now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents: 356
diff changeset
   566
                        else False
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   567
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   568
    old_claims = task.claims.all()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   569
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   570
    context.update({"is_creator": is_creator,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   571
                    "task_claimable": task_claimable,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   572
                    "can_claim": can_claim,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   573
                    "old_claims": old_claims})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   574
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   575
    if request.method == "POST" and can_claim:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   576
        form = ClaimTaskForm(request.POST)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   577
        if form.is_valid():
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   578
            data = form.cleaned_data.copy()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   579
            data.update({"uniq_key": make_key(TaskClaim),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   580
                         "task": task,
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   581
                         "claim_datetime": datetime.now(),
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   582
                         "claimed_by": user,})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   583
            new_claim = TaskClaim(**data)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   584
            new_claim.save()
355
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 353
diff changeset
   585
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 353
diff changeset
   586
            task.claimed_users.add(user)
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 353
diff changeset
   587
            task.save()
c693def6510f added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents: 353
diff changeset
   588
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   589
            return redirect(claim_url)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   590
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   591
        else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   592
            context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   593
            return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   594
    else:
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   595
        form = ClaimTaskForm()
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   596
        context.update({"form": form})
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   597
        return render_to_response("task/claim.html", context)
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   598
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   599
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   600
def select_user(request, task_id):
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   601
    """ first get the status of the task and then select one of claimed users
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   602
    generate list of claimed users by passing it as an argument to a function.
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   603
    """
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   604
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   605
    task_url = reverse('view_task', kwargs={'task_id': task_id})
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   606
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   607
    user = request.user
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   608
    profile = user.get_profile()
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   609
    task = getTask(task_id)
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   610
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   611
    context = {"user": user,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   612
               "profile": profile,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   613
               "task": task,
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   614
              }
353
181d4eb9f419 created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 350
diff changeset
   615
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   616
    context.update(csrf(request))
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   617
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   618
    claimed_users = task.claimed_users.all()
362
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
   619
    task_claimed = True if claimed_users else False
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   620
    
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   621
    is_creator = True if user == task.created_by else False
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   622
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   623
    if ( is_creator or profile.rights in ["CR", "DC"] ) and \
362
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
   624
       task.status in ["OP", "WR"]:
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   625
362
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
   626
        if task_claimed:
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   627
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   628
            user_list = ((user.id,user.username) for user in claimed_users)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   629
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   630
            if request.method == "POST":
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   631
                form = ChoiceForm(user_list, request.POST)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   632
                if form.is_valid():
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   633
                    uid = form.cleaned_data['choice']
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   634
                    selected_user = User.objects.get(id=uid)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   635
362
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
   636
                    task.selected_users.add(selected_user)
070f01dd7d8e Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 360
diff changeset
   637
                    task.claimed_users.remove(selected_user)
363
9b0812962133 created the home page
Nishanth Amuluru <nishanth@fossee.in>
parents: 362
diff changeset
   638
                    task.status = "WR"
360
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   639
                    task.save()
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   640
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   641
                    return redirect(task_url)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   642
                else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   643
                    context.update({"form": form})
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   644
                    return render_to_response('task/select_user.html', context)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   645
            else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   646
                form = ChoiceForm(user_list)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   647
                context.update({"form": form})
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   648
                return render_to_response('task/select_user.html', context)
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   649
        else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   650
            return show_msg(user, 'There are no pending claims for this task',
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   651
                            task_url, 'view the task')
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   652
    else:
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   653
        raise Http404
b4988ede9e3d created the view
Nishanth Amuluru <nishanth@fossee.in>
parents: 357
diff changeset
   654
380
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   655
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   656
def approve_textbook(request, task_id):
380
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   657
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   658
    user = request.user
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   659
    profile = user.get_profile()
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   660
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   661
    textbook = getTextBook(task_id)
380
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   662
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   663
    if profile.rights not in ["MG", "DC"] or textbook.status != "UP":
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   664
        raise Http404
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   665
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   666
    context = {"user": user,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   667
               "profile": profile,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   668
               "textbook": textbook,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   669
              }
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   670
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   671
    return render_to_response("task/confirm_textbook_approval.html", context)
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   672
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   673
@login_required
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   674
def approved_textbook(request, task_id):
380
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   675
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   676
    user = request.user
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   677
    profile = user.get_profile()
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   678
408
0c12181e2c02 Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 387
diff changeset
   679
    textbook = getTextBook(task_id)
380
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   680
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   681
    if profile.rights not in ["MG", "DC"] or textbook.status != "UP":
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   682
        raise Http404
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   683
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   684
    textbook.approved_by = user
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   685
    textbook.approval_datetime = datetime.now()
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   686
    textbook.status = "OP"
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   687
    textbook.save()
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   688
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   689
    context = {"user": user,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   690
               "profile": profile,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   691
               "textbook": textbook,
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   692
              }
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   693
e848bd3ad41f approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents: 377
diff changeset
   694
    return render_to_response("task/approved_textbook.html", context)