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