author | nishanth |
Fri, 29 Jan 2010 19:27:26 +0530 | |
changeset 5 | aea7e764c033 |
parent 2 | 3db830ff66ee |
child 6 | 94136f9a48bc |
permissions | -rw-r--r-- |
5
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
1 |
from django.http import HttpResponse |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
2 |
from django.shortcuts import redirect, render_to_response |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
3 |
from pytask.taskapp.models import Task |
2 | 4 |
|
5
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
5 |
def redirect_to_homepage(request): |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
6 |
""" simply redirect to homepage """ |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
7 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
8 |
return redirect('/') |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
9 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
10 |
def homepage(request): |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
11 |
""" check for authentication and display accordingly. """ |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
12 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
13 |
user = request.user |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
14 |
is_guest = False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
15 |
is_mentor = False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
16 |
can_create_task = False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
17 |
task_list = [] |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
18 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
19 |
if not user.is_authenticated(): |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
20 |
is_guest = True |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
21 |
disp_num = 10 |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
22 |
tasks_count = Task.objects.count() |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
23 |
if tasks_count <= disp_num: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
24 |
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
|
25 |
else: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
26 |
task_list = Task.objects.order_by('id').reverse()[:10] |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
27 |
else: |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
28 |
user_profile = user.get_profile() |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
29 |
is_mentor = True if user.task_mentors.all() else False |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
30 |
can_create_task = False if user_profile.rights == u"CT" else True |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
31 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
32 |
context = {'user':user, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
33 |
'is_guest':is_guest, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
34 |
'is_mentor':is_mentor, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
35 |
'task_list':task_list, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
36 |
'can_create_task':can_create_task, |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
37 |
} |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
38 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
39 |
return render_to_response('index.html', context) |
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
40 |
|
aea7e764c033
created views and templates for homepage,browse_task and added actions.
nishanth
parents:
2
diff
changeset
|
41 |