author | nishanth |
Sat, 30 Jan 2010 13:04:58 +0530 | |
changeset 12 | c823b42970a4 |
parent 11 | d28fcc644fbb |
child 14 | f2623fb8041a |
permissions | -rw-r--r-- |
5
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
1 |
from datetime import datetime |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
2 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
3 |
from django.http import HttpResponse |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
4 |
from django.shortcuts import render_to_response, redirect |
11
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
5 |
|
5
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
6 |
from pytask.taskapp.models import Task, Comment |
11
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
7 |
from pytask.taskapp.forms.task import TaskCreateForm |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
8 |
from pytask.taskapp.events.task import createTask, addMentor, publishTask |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
9 |
from pytask.taskapp.views.user import show_msg |
5
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
10 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
11 |
def browse_tasks(request): |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
12 |
""" display all the tasks """ |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
13 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
14 |
user = request.user |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
15 |
task_list = Task.objects.order_by('id').reverse() |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
16 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
17 |
context = {'user':user, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
18 |
'task_list':task_list, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
19 |
} |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
20 |
return render_to_response('task/browse.html', context) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
21 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
22 |
def view_task(request, tid): |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
23 |
""" get the task depending on its tid and display accordingly if it is a get. |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
24 |
check for authentication and add a comment if it is a post request. |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
25 |
""" |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
26 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
27 |
task_url = "/task/view/tid=%s"%tid |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
28 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
29 |
user = request.user |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
30 |
task = Task.objects.get(id=tid) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
31 |
comments = Comment.objects.filter(task=task) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
32 |
errors = [] |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
33 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
34 |
is_guest = True if not user.is_authenticated() else False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
35 |
is_mentor = True if user in task.mentors.all() else False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
36 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
37 |
context = {'user':user, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
38 |
'task':task, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
39 |
'comments':comments, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
40 |
'is_guest':is_guest, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
41 |
'is_mentor':is_mentor, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
42 |
'errors':errors, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
43 |
} |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
44 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
45 |
if request.method == 'POST': |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
46 |
if not is_guest: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
47 |
data = request.POST["data"] |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
48 |
task = Task.objects.get(id=tid) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
49 |
new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now()) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
50 |
new_comment.save() |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
51 |
return redirect(task_url) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
52 |
else: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
53 |
errors.append("You must be logged in to post a comment") |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
54 |
return render_to_response('task/view.html', context) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
55 |
else: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
56 |
return render_to_response('task/view.html', context) |
11
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
57 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
58 |
def create_task(request): |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
59 |
""" check for rights and create a task if applicable. |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
60 |
if user cannot create a task, redirect to homepage. |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
61 |
""" |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
62 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
63 |
user = request.user |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
64 |
is_guest = True if not user.is_authenticated() else False |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
65 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
66 |
if not is_guest: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
67 |
user_profile = user.get_profile() |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
68 |
can_create_task = False if user_profile.rights == "CT" else True |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
69 |
if can_create_task: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
70 |
if request.method == "POST": |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
71 |
form = TaskCreateForm(request.POST) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
72 |
if form.is_valid(): |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
73 |
data = form.cleaned_data |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
74 |
title = data['title'] |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
75 |
desc = data['desc'] |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
76 |
credits = data['credits'] |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
77 |
publish = data['publish'] |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
78 |
task = createTask(title,desc,user,credits) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
79 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
80 |
if not task: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
81 |
error_msg = "Another task with the same title exists" |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
82 |
return render_to_response('task/create.html',{'form':form, 'error_msg':error_msg}) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
83 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
84 |
addMentor(task, user) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
85 |
if publish: publishTask(task) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
86 |
task_url = '/task/view/tid=%s'%task.id |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
87 |
return redirect(task_url) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
88 |
else: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
89 |
return render_to_response('task/create.html',{'form':form}) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
90 |
else: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
91 |
form = TaskCreateForm() |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
92 |
return render_to_response('task/create.html',{'form':form}) |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
93 |
else: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
94 |
return show_msg('You are not authorised to create a task.') |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
95 |
else: |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
96 |
return show_msg('You are not authorised to create a task.') |
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
97 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
98 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
99 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
100 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
101 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
102 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
103 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
104 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
105 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
106 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
107 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
108 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
109 |
|
d28fcc644fbb
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
10
diff
changeset
|
110 |