author | Nishanth Amuluru <nishanth@fossee.in> |
Thu, 06 Jan 2011 12:08:36 +0530 | |
changeset 226 | b4a3ec34c061 |
parent 218 | 59107ce0a618 |
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 |
|
206
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
10 |
from pytask.taskapp.events.user import createUser |
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 = { |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
20 |
"addreviewers": "about/addreviewers.html", |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
21 |
"reviewer": "about/reviewer.html", |
184 | 22 |
"starthere": "about/starthere.html", |
185 | 23 |
"task": "about/task.html", |
24 |
"tasklife": "about/tasklife.html", |
|
186
c083ebb6f8d7
finished the phase-2 successfully. added all the learnmore templates. hav to look for bugs if any.
nishanth
parents:
185
diff
changeset
|
25 |
"developer": "about/developer.html", |
c083ebb6f8d7
finished the phase-2 successfully. added all the learnmore templates. hav to look for bugs if any.
nishanth
parents:
185
diff
changeset
|
26 |
"notification": "about/notification.html", |
c083ebb6f8d7
finished the phase-2 successfully. added all the learnmore templates. hav to look for bugs if any.
nishanth
parents:
185
diff
changeset
|
27 |
"request": "about/request.html", |
c083ebb6f8d7
finished the phase-2 successfully. added all the learnmore templates. hav to look for bugs if any.
nishanth
parents:
185
diff
changeset
|
28 |
"manager": "about/manager.html", |
c083ebb6f8d7
finished the phase-2 successfully. added all the learnmore templates. hav to look for bugs if any.
nishanth
parents:
185
diff
changeset
|
29 |
"admin": "about/admin.html", |
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
30 |
} |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
31 |
|
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
32 |
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
|
33 |
""" 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
|
34 |
|
111 | 35 |
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
|
36 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
37 |
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
|
38 |
""" check for authentication and display accordingly. """ |
137
e56b95298254
now requests in sidebar shows the no.of unread notifications.
nishanth
parents:
133
diff
changeset
|
39 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
40 |
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
|
41 |
is_guest = False |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
42 |
is_reviewer = False |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
disp_num = 10 |
169 | 49 |
task_list = Task.objects.exclude(status="UP").exclude(status="CD").exclude(status="CM").order_by('published_datetime').reverse()[:10] |
137
e56b95298254
now requests in sidebar shows the no.of unread notifications.
nishanth
parents:
133
diff
changeset
|
50 |
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
|
51 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
52 |
else: |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
53 |
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
|
54 |
user_profile = user.get_profile() |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
55 |
is_reviewer = True if user.task_reviewers.all() else False |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
56 |
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
|
57 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
58 |
context = {'user':user, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
59 |
'is_guest':is_guest, |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
60 |
'is_reviewer':is_reviewer, |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
61 |
'task_list':task_list, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
62 |
'can_create_task':can_create_task, |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
63 |
} |
125 | 64 |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
65 |
context["unpublished_tasks"] = user.task_reviewers.filter(status="UP") |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
208
diff
changeset
|
66 |
context["reviewered_tasks"] = user.task_reviewers.exclude(status="UP").exclude(status="CM").exclude(status="CD").exclude(status="DL") |
168 | 67 |
context["claimed_tasks"] = user.task_claimed_users.exclude(status="UP").exclude(status="CM").exclude(status="CD").exclude(status="DL") |
68 |
context["working_tasks"] = user.task_assigned_users.filter(status="WR") |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
69 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
20
diff
changeset
|
70 |
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
|
71 |
|
39 | 72 |
@login_required |
127
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
73 |
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
|
74 |
""" 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
|
75 |
""" |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
76 |
|
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
if not disp_template: |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
80 |
raise Http404 |
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
81 |
else: |
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
82 |
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
|
83 |
|
71888e23f323
created a view for about pages and added about pages for mentor and addmentors.
nishanth
parents:
125
diff
changeset
|
84 |
@login_required |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
85 |
def view_my_profile(request,uid=None): |
23 | 86 |
""" 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
|
87 |
user = get_user(request.user) |
208
ba839dd7c7d7
admins and managers can see full profile of user, including email, address and phone number.
anoop
parents:
206
diff
changeset
|
88 |
request_user_profile = request.user.get_profile() |
ba839dd7c7d7
admins and managers can see full profile of user, including email, address and phone number.
anoop
parents:
206
diff
changeset
|
89 |
request_user_privilege = True if request_user_profile.rights in ['AD','MG'] else False |
42
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
90 |
if uid == None: |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
91 |
edit_profile = True |
9b5b8c997598
started using django-registration default backend, removed browse users functionality.
anoop
parents:
40
diff
changeset
|
92 |
profile = Profile.objects.get(user = request.user) |
208
ba839dd7c7d7
admins and managers can see full profile of user, including email, address and phone number.
anoop
parents:
206
diff
changeset
|
93 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user, 'privilege':request_user_privilege}) |
23 | 94 |
edit_profile = True if request.user == User.objects.get(pk=uid) else False |
95 |
try: |
|
96 |
profile = Profile.objects.get(user = User.objects.get(pk=uid)) |
|
97 |
except Profile.DoesNotExist: |
|
98 |
raise Http404 |
|
208
ba839dd7c7d7
admins and managers can see full profile of user, including email, address and phone number.
anoop
parents:
206
diff
changeset
|
99 |
return render_to_response('user/my_profile.html', {'edit_profile':edit_profile,'profile':profile, 'user':user, 'privilege':request_user_privilege}) |
23 | 100 |
|
45 | 101 |
@login_required |
23 | 102 |
def edit_my_profile(request): |
103 |
""" 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
|
104 |
|
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
105 |
user = get_user(request.user) |
206
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
106 |
user_profile = user.get_profile() |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
107 |
|
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
108 |
edit_profile_form = UserProfileEditForm(instance = user_profile) |
23 | 109 |
if request.method == 'POST': |
206
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
110 |
|
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
111 |
data = request.POST.copy() |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
112 |
uploaded_photo = request.FILES.get('photo', None) |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
113 |
data.__setitem__('photo', uploaded_photo) |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
114 |
|
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
115 |
edit_profile_form = UserProfileEditForm(data, instance=user_profile) |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
116 |
if edit_profile_form.is_valid(): |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
117 |
edit_profile_form.save() |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
118 |
return redirect('/user/view/uid='+str(user.id)) |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
119 |
else: |
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
120 |
return render_to_response('user/edit_profile.html',{'user':user, 'edit_profile_form' : edit_profile_form}) |
23 | 121 |
else: |
206
85660d75683d
now user profile editing is done thro forms in a more elegant way.
nishanth
parents:
186
diff
changeset
|
122 |
profile = user.get_profile() |
23 | 123 |
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
|
124 |
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
|
125 |
|
83 | 126 |
@login_required |
127 |
def browse_requests(request): |
|
128 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
129 |
user = get_user(request.user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
130 |
active_reqs = user.request_sent_to.filter(is_replied=False).exclude(is_valid=False) |
83 | 131 |
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
|
132 |
|
83 | 133 |
context = { |
134 |
'user':user, |
|
135 |
'reqs':reqs, |
|
136 |
} |
|
137 |
||
138 |
return render_to_response('user/browse_requests.html', context) |
|
139 |
||
140 |
@login_required |
|
141 |
def view_request(request, rid): |
|
142 |
""" please note that request variable in this method is that of django. |
|
143 |
our app request is called user_request. |
|
144 |
""" |
|
145 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
146 |
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
|
147 |
user_rights = user.get_profile().rights |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
148 |
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
|
149 |
if not user_request: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
150 |
raise Http404 |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
151 |
|
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
152 |
user_request.is_read = True |
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
153 |
user_request.save() |
83 | 154 |
|
155 |
context = { |
|
156 |
'user':user, |
|
157 |
'req':user_request, |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
158 |
'sent_users':user_request.sent_to.all(), |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
159 |
'newest':newest, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
160 |
'newer':newer, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
161 |
'older':older, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
162 |
'oldest':oldest, |
83 | 163 |
} |
164 |
||
165 |
return render_to_response('user/view_request.html', context) |
|
166 |
||
167 |
@login_required |
|
168 |
def process_request(request, rid, reply): |
|
169 |
""" check if the method is post and then update the request. |
|
170 |
if it is get, display a 404 error. |
|
171 |
""" |
|
172 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
173 |
user = get_user(request.user) |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
174 |
browse_request_url= '/user/requests' |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
175 |
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
|
176 |
|
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
177 |
if not req_obj: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
111
diff
changeset
|
178 |
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
|
179 |
|
83 | 180 |
if request.method=="POST": |
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
181 |
reply = True if reply == "yes" else False |
104 | 182 |
req_obj.remarks = request.POST.get('remarks', "") |
183 |
req_obj.save() |
|
184 |
||
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
97
diff
changeset
|
185 |
reply_to_request(req_obj, reply, user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
186 |
|
152
a65e1ef725dd
after replying to a request, you are redirected to browse redirects page.
nishanth
parents:
148
diff
changeset
|
187 |
return redirect('/user/requests/') |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
188 |
return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests") |
83 | 189 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
190 |
return show_msg(user, "You are not authorised to do this", browse_request_url, "view other requests") |
101 | 191 |
|
192 |
@login_required |
|
193 |
def browse_notifications(request): |
|
194 |
""" get the list of notifications that are not deleted and display in datetime order. |
|
195 |
""" |
|
196 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
197 |
user = get_user(request.user) |
101 | 198 |
|
123 | 199 |
active_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date').reverse() |
101 | 200 |
|
201 |
context = { |
|
202 |
'user':user, |
|
203 |
'notifications':active_notifications, |
|
204 |
} |
|
205 |
||
206 |
return render_to_response('user/browse_notifications.html', context) |
|
103 | 207 |
|
208 |
@login_required |
|
209 |
def view_notification(request, nid): |
|
210 |
""" get the notification depending on nid. |
|
211 |
Display it. |
|
212 |
""" |
|
213 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
214 |
user = get_user(request.user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
215 |
newest, newer, notification, older, oldest = get_notification(nid, user) |
123 | 216 |
if not notification: |
217 |
raise Http404 |
|
218 |
||
103 | 219 |
notification.is_read = True |
220 |
notification.save() |
|
221 |
||
222 |
context = { |
|
223 |
'user':user, |
|
224 |
'notification':notification, |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
225 |
'newest':newest, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
226 |
'newer':newer, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
227 |
'older':older, |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
228 |
'oldest':oldest, |
103 | 229 |
} |
230 |
||
231 |
return render_to_response('user/view_notification.html', context) |
|
232 |
||
233 |
@login_required |
|
234 |
def edit_notification(request, nid, action): |
|
235 |
""" if action is delete, set is_deleted. |
|
236 |
if it is unread, unset is_read. |
|
237 |
save the notification and redirect to browse_notifications. |
|
238 |
""" |
|
239 |
||
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
137
diff
changeset
|
240 |
user = get_user(request.user) |
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
241 |
newest, newer, notification, older, oldest = get_notification(nid, user) |
123 | 242 |
|
243 |
if not notification: |
|
244 |
raise Http404 |
|
245 |
||
103 | 246 |
notifications_url = "/user/notifications/" |
247 |
||
248 |
if request.method == "POST": |
|
249 |
if action == "delete": |
|
123 | 250 |
notification.is_deleted = True |
103 | 251 |
elif action == "unread": |
252 |
notification.is_read = False |
|
253 |
||
254 |
notification.save() |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
255 |
if older: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
256 |
return redirect('/user/notifications/nid=%s'%older.id) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
257 |
else: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
127
diff
changeset
|
258 |
return redirect(notifications_url) |
103 | 259 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
104
diff
changeset
|
260 |
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
|
261 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
262 |
@login_required |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
263 |
def change_rights(request, role): |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
264 |
""" 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
|
265 |
""" |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
266 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
267 |
user = get_user(request.user) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
268 |
role = role.upper() |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
269 |
user_profile = user.get_profile() |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
270 |
user_rights = user_profile.rights |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
271 |
|
145
0c97a02b9bdb
now accepting to be a MG deleted pending DV and MG reqs.
nishanth
parents:
143
diff
changeset
|
272 |
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
|
273 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
274 |
if user_can_view: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
275 |
if role == "DV": |
148
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
276 |
current_contributors = list(User.objects.filter(is_active=True,profile__rights="CT")) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
277 |
pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
278 |
pending_dv_requests = pending_requests.filter(role="DV") |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
279 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
280 |
## one cannot make same request many times |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
281 |
for req in pending_dv_requests: |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
282 |
current_contributors.remove(req.sent_to.all()[0]) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
283 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
284 |
choices = [ (_.id,_.username ) for _ in current_contributors ] |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
285 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
286 |
elif role == "MG": |
148
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
287 |
active_users = User.objects.filter(is_active=True) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
288 |
dv_ct_users = list(active_users.filter(profile__rights="CT") | active_users.filter(profile__rights="DV")) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
289 |
pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
290 |
pending_mg_requests = pending_requests.filter(role="MG") |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
291 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
292 |
## same logic here. you cannot make another request exactly the same. |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
293 |
## but iam still not decided whether someone who requests a user to be admin, |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
294 |
## can be given a chance to request the same user to be a manager or developer |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
295 |
for req in pending_mg_requests: |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
296 |
dv_ct_users.remove(req.sent_to.all()[0]) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
297 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
298 |
choices = [ (_.id, _.username ) for _ in dv_ct_users ] |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
299 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
300 |
elif role == "AD": |
148
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
301 |
active_users = User.objects.filter(is_active=True) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
302 |
non_ad_users = list(active_users.exclude(profile__rights="AD")) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
303 |
pending_requests = user.request_sent_by.filter(is_replied=False,is_valid=True) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
304 |
pending_ad_requests = pending_requests.filter(role="AD") |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
305 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
306 |
## we filter out users who have already been requested by the user to be an admin |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
307 |
for req in pending_ad_requests: |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
308 |
non_ad_users.remove(req.sent_to.all()[0]) |
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
309 |
|
665eaf56e1d0
now a user who was requested to be something cannot be requested to be the same again.
nishanth
parents:
145
diff
changeset
|
310 |
choices = [ (_.id,_.username ) for _ in non_ad_users ] |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
311 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
312 |
form = UserChoiceForm(choices) |
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 |
context = { |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
315 |
'user':user, |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
316 |
'form':form, |
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 |
if request.method=="POST": |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
320 |
data = request.POST |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
321 |
form = UserChoiceForm(choices, data) |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
322 |
if form.is_valid(): |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
327 |
raise Http404 |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
328 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
329 |
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
|
330 |
else: |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
331 |
raise Http404 |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
332 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
333 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
334 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
335 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
336 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
337 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
338 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
339 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
340 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
341 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
342 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
343 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
344 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
345 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
346 |
|
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
347 |