author | nishanth |
Sun, 28 Feb 2010 16:16:57 +0530 | |
changeset 147 | 8c1ed28d04d2 |
parent 145 | 0c97a02b9bdb |
child 148 | 665eaf56e1d0 |
permissions | -rw-r--r-- |
61 | 1 |
import os |
83 | 2 |
|
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
3 |
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
|
4 |
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
|
5 |
from django.contrib.auth.models import User |
39 | 6 |
from django.contrib.auth.decorators import login_required |
7 |
||
83 | 8 |
from pytask.taskapp.models import Task, Profile, Request |
123 | 9 |
|
83 | 10 |
from pytask.taskapp.events.user import createUser, updateProfile |
123 | 11 |
from pytask.taskapp.events.request import reply_to_request |
12 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
13 |
from pytask.taskapp.forms.user import UserProfileEditForm, UserChoiceForm |
123 | 14 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
15 |
from pytask.taskapp.utilities.request import get_request, create_request |
143
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
16 |
from pytask.taskapp.utilities.notification import get_notification, create_notification |
137
e56b95298254
now requests in sidebar shows the no.of unread notifications.
nishanth
parents:
133
diff
changeset
|
17 |
from pytask.taskapp.utilities.user import get_user |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
18 |
|
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
19 |
about = { |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
20 |
"addmentors":"about/addmentors.html", |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
21 |
"mentor":"about/mentor.html", |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
22 |
} |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
23 |
|
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
24 |
def show_msg(user, 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
|
25 |
""" 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
|
26 |
|
111 | 27 |
return render_to_response('show_msg.html',{'user':user, '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
|
28 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
29 |
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
|
30 |
""" check for authentication and display accordingly. """ |
137
e56b95298254
now requests in sidebar shows the no.of unread notifications.
nishanth
parents:
133
diff
changeset
|
31 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
32 |
user = request.user |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
45 |
task_list = Task.objects.order_by('id').reverse()[:10] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
46 |
|
137
e56b95298254
now requests in sidebar shows the no.of unread notifications.
nishanth
parents:
133
diff
changeset
|
47 |
return render_to_response('index.html', {'user':user, 'is_guest':is_guest, 'task_list':task_list}) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
48 |
|
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 |
else: |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
50 |
user = get_user(request.user) |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
55 |
context = {'user':user, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
56 |
'is_guest':is_guest, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
57 |
'is_mentor':is_mentor, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
58 |
'task_list':task_list, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
59 |
'can_create_task':can_create_task, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
60 |
} |
125 | 61 |
|
62 |
context["unpublished_tasks"] = user.task_mentors.filter(status="UP") |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
63 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
64 |
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
|
65 |
|
39 | 66 |
@login_required |
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
67 |
def learn_more(request, what): |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
68 |
""" depending on what was asked for, we render different pages. |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
69 |
""" |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
70 |
|
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
71 |
user = get_user(request.user) |
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
72 |
disp_template = about.get(what, None) |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
73 |
if not disp_template: |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
74 |
raise Http404 |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
75 |
else: |
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
76 |
return render_to_response(disp_template, {'user':user}) |
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
77 |
|
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
78 |
@login_required |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
79 |
def view_my_profile(request,uid=None): |
23 | 80 |
""" allows the user to view the profiles of users """ |
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
81 |
user = get_user(request.user) |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
82 |
if uid == None: |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
83 |
edit_profile = True |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
84 |
profile = Profile.objects.get(user = request.user) |
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
85 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user}) |
23 | 86 |
edit_profile = True if request.user == User.objects.get(pk=uid) else False |
87 |
try: |
|
88 |
profile = Profile.objects.get(user = User.objects.get(pk=uid)) |
|
89 |
except Profile.DoesNotExist: |
|
90 |
raise Http404 |
|
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
91 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user}) |
23 | 92 |
|
45 | 93 |
@login_required |
23 | 94 |
def edit_my_profile(request): |
95 |
""" enables the user to edit his/her user profile """ |
|
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
96 |
|
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
97 |
user = get_user(request.user) |
23 | 98 |
if request.method == 'POST': |
99 |
form = UserProfileEditForm(request.POST) |
|
100 |
# if not form.is_valid(): |
|
101 |
# edit_profile_form = UserProfileEditForm(instance = form) |
|
102 |
# return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form}) |
|
103 |
if request.user.is_authenticated() == True: |
|
104 |
profile = Profile.objects.get(user = request.user) |
|
105 |
data = request.POST#form.cleaned_data |
|
61 | 106 |
properties = {'aboutme':data['aboutme'], |
107 |
'foss_comm':data['foss_comm'], |
|
108 |
'phonenum':data['phonenum'], |
|
109 |
'homepage':data['homepage'], |
|
110 |
'street':data['street'], |
|
111 |
'city':data['city'], |
|
112 |
'country':data['country'], |
|
113 |
'nick':data['nick']} |
|
114 |
uploaded_photo = request.FILES.get('photo',None) |
|
115 |
prev_photo = profile.photo |
|
116 |
if uploaded_photo: |
|
117 |
if prev_photo: |
|
118 |
os.remove(prev_photo.path) |
|
119 |
properties['photo'] = uploaded_photo |
|
23 | 120 |
#fields = ['dob','gender','credits','aboutme','foss_comm','phonenum','homepage','street','city','country','nick'] |
121 |
updateProfile(profile,properties) |
|
122 |
return redirect('/user/view/uid='+str(profile.user_id)) |
|
123 |
else: |
|
124 |
profile = Profile.objects.get(user = request.user) |
|
125 |
edit_profile_form = UserProfileEditForm(instance = profile) |
|
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
126 |
return render_to_response('user/edit_profile.html',{'edit_profile_form' : edit_profile_form, 'user':user}) |
28
e137b605b888
added browse users functionality, added user/browse.html, fixed view my profile template.
anoop
parents:
27
diff
changeset
|
127 |
|
83 | 128 |
@login_required |
129 |
def browse_requests(request): |
|
130 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
131 |
user = get_user(request.user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
132 |
active_reqs = user.request_sent_to.filter(is_replied=False).exclude(is_valid=False) |
83 | 133 |
reqs = active_reqs.order_by('creation_date').reverse() |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
134 |
|
83 | 135 |
context = { |
136 |
'user':user, |
|
137 |
'reqs':reqs, |
|
138 |
} |
|
139 |
||
140 |
return render_to_response('user/browse_requests.html', context) |
|
141 |
||
142 |
@login_required |
|
143 |
def view_request(request, rid): |
|
144 |
""" please note that request variable in this method is that of django. |
|
145 |
our app request is called user_request. |
|
146 |
""" |
|
147 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
148 |
user = get_user(request.user) |
143
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
149 |
user_rights = user.get_profile().rights |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
150 |
newest, newer, user_request, older, oldest = get_request(rid, user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
151 |
if not user_request: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
152 |
raise Http404 |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
153 |
|
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
154 |
user_request.is_read = True |
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
155 |
user_request.save() |
83 | 156 |
|
157 |
context = { |
|
158 |
'user':user, |
|
159 |
'req':user_request, |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
160 |
'sent_users':user_request.sent_to.all(), |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
161 |
'newest':newest, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
162 |
'newer':newer, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
163 |
'older':older, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
164 |
'oldest':oldest, |
83 | 165 |
} |
166 |
||
143
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
167 |
## see if user has already accepted such request and is a high previleged user |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
168 |
## made_invalid = if ( user_request.role == "DV" and user_rights in ["DV", "MG", "AD"] ) or \ |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
169 |
## ( user_request.role == "MG" and user_rights in ["MG", "AD"] ) or \ |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
170 |
## ( user_request.role == "AD" and user_rights == "AD" ) or \ |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
171 |
## ( user_request.role == "MT" and user.task_mentors.filter(task=request.task) else False |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
172 |
|
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
173 |
## create_notification(user_request.role, user_request.sent_by, user, False, remarks = "User has accepted a similar request and is same or higher privileged than the request", requested_by = user_request.sent_by ) |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
174 |
##def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None): |
796ff9e279a8
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
nishanth
parents:
141
diff
changeset
|
175 |
|
83 | 176 |
return render_to_response('user/view_request.html', context) |
177 |
||
178 |
@login_required |
|
179 |
def process_request(request, rid, reply): |
|
180 |
""" check if the method is post and then update the request. |
|
181 |
if it is get, display a 404 error. |
|
182 |
""" |
|
183 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
184 |
user = get_user(request.user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
185 |
browse_request_url= '/user/requests' |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
186 |
newest, newer, req_obj, older, oldest = get_request(rid, user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
187 |
|
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
188 |
if not req_obj: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
189 |
return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests") |
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
190 |
|
83 | 191 |
if request.method=="POST": |
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
192 |
reply = True if reply == "yes" else False |
104 | 193 |
req_obj.remarks = request.POST.get('remarks', "") |
194 |
req_obj.save() |
|
195 |
||
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
196 |
reply_to_request(req_obj, reply, user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
197 |
|
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
198 |
return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests") |
83 | 199 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
200 |
return show_msg(user, "You are not authorised to do this", browse_request_url, "view other requests") |
101 | 201 |
|
202 |
@login_required |
|
203 |
def browse_notifications(request): |
|
204 |
""" get the list of notifications that are not deleted and display in datetime order. |
|
205 |
""" |
|
206 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
207 |
user = get_user(request.user) |
101 | 208 |
|
123 | 209 |
active_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date').reverse() |
101 | 210 |
|
211 |
context = { |
|
212 |
'user':user, |
|
213 |
'notifications':active_notifications, |
|
214 |
} |
|
215 |
||
216 |
return render_to_response('user/browse_notifications.html', context) |
|
103 | 217 |
|
218 |
@login_required |
|
219 |
def view_notification(request, nid): |
|
220 |
""" get the notification depending on nid. |
|
221 |
Display it. |
|
222 |
""" |
|
223 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
224 |
user = get_user(request.user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
225 |
newest, newer, notification, older, oldest = get_notification(nid, user) |
123 | 226 |
if not notification: |
227 |
raise Http404 |
|
228 |
||
103 | 229 |
notification.is_read = True |
230 |
notification.save() |
|
231 |
||
232 |
context = { |
|
233 |
'user':user, |
|
234 |
'notification':notification, |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
235 |
'newest':newest, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
236 |
'newer':newer, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
237 |
'older':older, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
238 |
'oldest':oldest, |
103 | 239 |
} |
240 |
||
241 |
return render_to_response('user/view_notification.html', context) |
|
242 |
||
243 |
@login_required |
|
244 |
def edit_notification(request, nid, action): |
|
245 |
""" if action is delete, set is_deleted. |
|
246 |
if it is unread, unset is_read. |
|
247 |
save the notification and redirect to browse_notifications. |
|
248 |
""" |
|
249 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
250 |
user = get_user(request.user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
251 |
newest, newer, notification, older, oldest = get_notification(nid, user) |
123 | 252 |
|
253 |
if not notification: |
|
254 |
raise Http404 |
|
255 |
||
103 | 256 |
notifications_url = "/user/notifications/" |
257 |
||
258 |
if request.method == "POST": |
|
259 |
if action == "delete": |
|
123 | 260 |
notification.is_deleted = True |
103 | 261 |
elif action == "unread": |
262 |
notification.is_read = False |
|
263 |
||
264 |
notification.save() |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
265 |
if older: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
266 |
return redirect('/user/notifications/nid=%s'%older.id) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
267 |
else: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
268 |
return redirect(notifications_url) |
103 | 269 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
270 |
return show_msg(user, 'This is wrong', notification_url, "view the notification") |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
271 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
272 |
@login_required |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
273 |
def change_rights(request, role): |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
274 |
""" check if the current user has privileges to do this. |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
275 |
""" |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
276 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
277 |
user = get_user(request.user) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
278 |
role = role.upper() |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
279 |
user_profile = user.get_profile() |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
280 |
user_rights = user_profile.rights |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
281 |
|
145
0c97a02b9bdb
now accepting to be a MG deleted pending DV and MG reqs.
nishanth
parents:
143
diff
changeset
|
282 |
user_can_view = True if user_rights == "AD" or ( user_rights == "MG" and role in ["MG", "DV"] ) else False |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
283 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
284 |
if user_can_view: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
285 |
if role == "DV": |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
286 |
choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.filter(rights="CT",user__is_active=True) ] |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
287 |
elif role == "MG": |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
288 |
choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.exclude(rights="MG",user__is_active=True).exclude(rights="AD") ] |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
289 |
elif role == "AD": |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
290 |
choices = [ (_.user.id,_.user.username ) for _ in Profile.objects.exclude(rights="AD",user__is_active=True) ] |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
291 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
292 |
form = UserChoiceForm(choices) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
293 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
294 |
context = { |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
295 |
'user':user, |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
296 |
'form':form, |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
297 |
} |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
298 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
299 |
if request.method=="POST": |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
300 |
data = request.POST |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
301 |
form = UserChoiceForm(choices, data) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
302 |
if form.is_valid(): |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
303 |
user_to_change = User.objects.get(id=form.cleaned_data['user']) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
304 |
create_request(sent_by=user, role=role, sent_to=user_to_change) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
305 |
return show_msg(user, "A request has been sent", "/", "return to home page") |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
306 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
307 |
raise Http404 |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
308 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
309 |
return render_to_response('user/changerole.html', context) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
310 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
311 |
raise Http404 |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
312 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
313 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
314 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
315 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
316 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
317 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
318 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
319 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
320 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
321 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
322 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
323 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
324 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
325 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
326 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
327 |