author | anoop |
Tue, 23 Feb 2010 19:42:12 +0530 | |
changeset 60 | 3eac96608091 |
parent 45 | ab8918e654ae |
child 61 | 708dd49d531b |
permissions | -rw-r--r-- |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
1 |
from django.http import HttpResponse, Http404 |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
2 |
from django.shortcuts import redirect, render_to_response |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
3 |
from pytask.taskapp.models import Task |
40
43853e376bb8
deleted unwanted code to start using django-registration.
anoop
parents:
39
diff
changeset
|
4 |
from pytask.taskapp.forms.user import UserProfileEditForm |
23 | 5 |
from pytask.taskapp.events.user import createUser, updateProfile |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
6 |
from django.contrib.auth.models import User |
23 | 7 |
from pytask.taskapp.models import Profile |
39 | 8 |
from django.contrib.auth.decorators import login_required |
9 |
||
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
10 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
11 |
def show_msg(message, redirect_url=None, url_desc=None): |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
12 |
""" simply redirect to homepage """ |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
13 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
14 |
return render_to_response('show_msg.html',{'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc}) |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
15 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
16 |
def homepage(request): |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
17 |
""" check for authentication and display accordingly. """ |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
18 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
19 |
user = request.user |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
20 |
is_guest = False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
21 |
is_mentor = False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
22 |
can_create_task = False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
23 |
task_list = [] |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
24 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
25 |
if not user.is_authenticated(): |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
26 |
is_guest = True |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
27 |
disp_num = 10 |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
28 |
tasks_count = Task.objects.count() |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
29 |
if tasks_count <= disp_num: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
30 |
task_list = Task.objects.order_by('id').reverse() |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
31 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
32 |
task_list = Task.objects.order_by('id').reverse()[:10] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
33 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
34 |
return render_to_response('index.html', {'is_guest':is_guest, 'task_list':task_list}) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
35 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
36 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
37 |
user_profile = user.get_profile() |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
38 |
is_mentor = True if user.task_mentors.all() else False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
39 |
can_create_task = False if user_profile.rights == u"CT" else True |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
40 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
41 |
context = {'user':user, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
42 |
'is_guest':is_guest, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
43 |
'is_mentor':is_mentor, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
44 |
'task_list':task_list, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
45 |
'can_create_task':can_create_task, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
46 |
} |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
47 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
48 |
return render_to_response('index.html', context) |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
49 |
|
39 | 50 |
@login_required |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
51 |
def view_my_profile(request,uid=None): |
23 | 52 |
""" allows the user to view the profiles of users """ |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
53 |
if uid == None: |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
54 |
edit_profile = True |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
55 |
profile = Profile.objects.get(user = request.user) |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
56 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile}) |
23 | 57 |
edit_profile = True if request.user == User.objects.get(pk=uid) else False |
58 |
try: |
|
59 |
profile = Profile.objects.get(user = User.objects.get(pk=uid)) |
|
60 |
except Profile.DoesNotExist: |
|
61 |
raise Http404 |
|
27 | 62 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile}) |
23 | 63 |
|
45 | 64 |
@login_required |
23 | 65 |
def edit_my_profile(request): |
66 |
""" enables the user to edit his/her user profile """ |
|
67 |
if str(request.user) == 'AnonymousUser': |
|
68 |
return show_msg('Please register yourself to activate the functionality') |
|
69 |
if request.method == 'POST': |
|
70 |
form = UserProfileEditForm(request.POST) |
|
71 |
# if not form.is_valid(): |
|
72 |
# edit_profile_form = UserProfileEditForm(instance = form) |
|
73 |
# return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form}) |
|
74 |
if request.user.is_authenticated() == True: |
|
75 |
profile = Profile.objects.get(user = request.user) |
|
76 |
data = request.POST#form.cleaned_data |
|
60 | 77 |
properties = {'aboutme':data['aboutme'], 'foss_comm':data['foss_comm'], 'phonenum':data['phonenum'], 'homepage':data['homepage'], 'street':data['street'], 'city':data['city'], 'country':data['country'], 'nick':data['nick'],'photo':request.FILES['photo']} |
23 | 78 |
#fields = ['dob','gender','credits','aboutme','foss_comm','phonenum','homepage','street','city','country','nick'] |
79 |
updateProfile(profile,properties) |
|
80 |
return redirect('/user/view/uid='+str(profile.user_id)) |
|
81 |
else: |
|
82 |
profile = Profile.objects.get(user = request.user) |
|
83 |
edit_profile_form = UserProfileEditForm(instance = profile) |
|
84 |
return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form}) |
|
28
e137b605b888
added browse users functionality, added user/browse.html, fixed view my profile template.
anoop
parents:
27
diff
changeset
|
85 |