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