author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 14 Feb 2009 20:22:17 +0000 | |
changeset 1323 | a666374587df |
parent 1308 | 35b75ffcbb37 |
child 1343 | 4ba39392c854 |
permissions | -rw-r--r-- |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
2 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
4 |
# |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
7 |
# You may obtain a copy of the License at |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
8 |
# |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
10 |
# |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
15 |
# limitations under the License. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
16 |
|
747
ad62f4c3245e
In soc.views.models.notification module remove unused imports, add missing white space, change list() method definition to comply with base View list() method declaration. Add missing Meta class docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
738
diff
changeset
|
17 |
"""This module contains the view code for Notifications. |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
18 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
19 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
20 |
__authors__ = [ |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
22 |
] |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
23 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
24 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
25 |
import time |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
26 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
27 |
from django import forms |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
890
diff
changeset
|
28 |
from django.utils.translation import ugettext |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
29 |
|
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
763
diff
changeset
|
30 |
from soc.logic import cleaning |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
31 |
from soc.logic import dicts |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
32 |
from soc.logic import validate |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
33 |
from soc.models import notification as notification_model |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
34 |
from soc.views import helper |
830
ef0786e8bb63
Added missing import to views/models/notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents:
829
diff
changeset
|
35 |
from soc.views import out_of_band |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
36 |
from soc.views.helper import access |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
37 |
from soc.views.helper import decorators |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
38 |
from soc.views.helper import lists as list_helper |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
39 |
from soc.views.helper import redirects |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
40 |
from soc.views.models import base |
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
41 |
from soc.logic.models.notification import logic as notification_logic |
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
42 |
from soc.logic.models.user import logic as user_logic |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
43 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
44 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
45 |
class CreateForm(helper.forms.BaseForm): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
46 |
"""Form for creating a Notification. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
47 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
48 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
49 |
# to user field |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
50 |
to_user = forms.fields.CharField(label='To User') |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
51 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
52 |
def __init__(self, *args, **kwargs): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
53 |
""" Calls super and then redefines the order in which the fields appear. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
54 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
55 |
for parameters see BaseForm.__init__() |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
56 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
57 |
super(CreateForm, self).__init__(*args, **kwargs) |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
58 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
59 |
# set form fields order |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
60 |
self.fields.keyOrder = ['to_user', 'subject', 'message'] |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
61 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
62 |
class Meta: |
747
ad62f4c3245e
In soc.views.models.notification module remove unused imports, add missing white space, change list() method definition to comply with base View list() method declaration. Add missing Meta class docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
738
diff
changeset
|
63 |
"""Inner Meta class that defines some behavior for the form. |
ad62f4c3245e
In soc.views.models.notification module remove unused imports, add missing white space, change list() method definition to comply with base View list() method declaration. Add missing Meta class docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
738
diff
changeset
|
64 |
""" |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
65 |
model = notification_model.Notification |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
66 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
67 |
# exclude the necessary fields from the form |
737
4c78ee183eb6
Notification property has_been_read changed into unread
Lennard de Rijk <ljvderijk@gmail.com>
parents:
736
diff
changeset
|
68 |
exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread'] |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
69 |
|
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
763
diff
changeset
|
70 |
clean_to_user = cleaning.clean_existing_user('to_user') |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
71 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
72 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
73 |
class View(base.View): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
74 |
"""View methods for the Notification model. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
75 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
76 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
77 |
def __init__(self, params=None): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
78 |
"""Defines the fields and methods required for the base View class |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
79 |
to provide the user with list, public, create, edit and delete views. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
80 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
81 |
Params: |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
82 |
params: a dict with params for this View |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
83 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
84 |
|
1007
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
986
diff
changeset
|
85 |
rights = access.Checker(params) |
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
986
diff
changeset
|
86 |
rights['unspecified'] = ['deny'] |
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
986
diff
changeset
|
87 |
rights['edit'] = ['deny'] |
1176
c211191e7d81
Fixed access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1163
diff
changeset
|
88 |
rights['show'] = [('checkIsMyEntity', [notification_logic, 'scope_path'])] |
1197
7785b5091f07
Fixes a bug where notifications can't be deleted.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1176
diff
changeset
|
89 |
rights['delete'] = [('checkIsMyEntity', [notification_logic, 'scope_path'])] |
1012
73f0b61f2d9d
Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1007
diff
changeset
|
90 |
rights['list'] = ['checkIsUser'] |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
91 |
# create is developer only for the time being to test functionality |
1007
3b66772d21a5
Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
986
diff
changeset
|
92 |
rights['create'] = ['checkIsDeveloper'] |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
93 |
|
734
1ebd40380aa5
Make the place of the rights declaration consistent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
733
diff
changeset
|
94 |
new_params = {} |
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
95 |
new_params['logic'] = notification_logic |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
96 |
new_params['rights'] = rights |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
97 |
|
734
1ebd40380aa5
Make the place of the rights declaration consistent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
733
diff
changeset
|
98 |
new_params['name'] = "Notification" |
1ebd40380aa5
Make the place of the rights declaration consistent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
733
diff
changeset
|
99 |
|
763
c31a2eb14d6d
Set no_create_with_key_fields paramater to True for Notifications.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
762
diff
changeset
|
100 |
new_params['no_create_with_key_fields'] = True |
734
1ebd40380aa5
Make the place of the rights declaration consistent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
733
diff
changeset
|
101 |
new_params['create_form'] = CreateForm |
1ebd40380aa5
Make the place of the rights declaration consistent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
733
diff
changeset
|
102 |
|
738
61867ffea8a8
Brown-paper-bag fix in notification.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
737
diff
changeset
|
103 |
new_params['edit_redirect'] = '/%(url_name)s/list' |
736
c70d56182ce2
No override needed in notifications.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
734
diff
changeset
|
104 |
|
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
105 |
params = dicts.merge(params, new_params) |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
106 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
107 |
super(View, self).__init__(params=params) |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
108 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
109 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
110 |
@decorators.check_access |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
111 |
def list(self, request, access_type, |
747
ad62f4c3245e
In soc.views.models.notification module remove unused imports, add missing white space, change list() method definition to comply with base View list() method declaration. Add missing Meta class docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
738
diff
changeset
|
112 |
page_name=None, params=None, filter=None): |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
113 |
"""Lists all notifications that the current logged in user has stored. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
114 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
115 |
for parameters see base.list() |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
116 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
117 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
118 |
# get the current user |
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
119 |
user_entity = user_logic.getForCurrentAccount() |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
120 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
121 |
# only select the notifications for this user so construct a filter |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
122 |
filter = { |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
123 |
'scope': user_entity, |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
124 |
'unread': True, |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
125 |
} |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
126 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
127 |
# create the list parameters |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
128 |
un_params = params.copy() # unread notifications |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
129 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
130 |
# define the list redirect action to show the notification |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
131 |
un_params['list_action'] = (redirects.getPublicRedirect, params) |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
890
diff
changeset
|
132 |
un_params['list_description'] = ugettext( |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
133 |
"An overview of your unread Notifications.") |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
134 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
135 |
# TODO(Lennard) when list sorting is implemented sort on descending date |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
136 |
un_list = list_helper.getListContent( |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
137 |
request, un_params, filter, 0) |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
138 |
|
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
139 |
# Now get the read list |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
140 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
141 |
# Reuse the filter, but only for read notifications |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
142 |
filter['unread'] = False |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
143 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
144 |
rn_params = params.copy() # read notifications |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
145 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
146 |
rn_params['list_action'] = (redirects.getPublicRedirect, params) |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
890
diff
changeset
|
147 |
rn_params['list_description'] = ugettext( |
827
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
148 |
"An overview of your read Notifications.") |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
149 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
150 |
rn_list = list_helper.getListContent( |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
151 |
request, rn_params, filter, 1) |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
152 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
153 |
# fill contents with all the needed lists |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
154 |
contents = [un_list, rn_list] |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
155 |
|
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
156 |
# call the _list method from base to display the list |
88c186556a80
Split the notification list in read/unread
Sverre Rabbelier <srabbelier@gmail.com>
parents:
799
diff
changeset
|
157 |
return self._list(request, params, contents, page_name) |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
158 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
159 |
def _editPost(self, request, entity, fields): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
160 |
"""See base.View._editPost(). |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
161 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
162 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
163 |
# get the current user |
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
164 |
current_user = user_logic.getForCurrentAccount() |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
165 |
|
1059
17221b578fe7
prefixing the link_id of a notification with a t for time to agree to the new link_id pattern.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1012
diff
changeset
|
166 |
fields['link_id'] = 't%i' % (time.time()) |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
763
diff
changeset
|
167 |
fields['scope'] = fields['to_user'] |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
168 |
fields['from_user'] = current_user |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
763
diff
changeset
|
169 |
fields['scope_path'] = fields['to_user'].link_id |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
170 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
171 |
def _editSeed(self, request, seed): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
172 |
"""Checks if scope_path is seeded and puts it into to_user. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
173 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
174 |
for parameters see base._editSeed() |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
175 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
176 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
177 |
# if scope_path is present |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
178 |
if 'scope_path' in seed.keys(): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
179 |
# fill the to_user field with the scope path |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
180 |
seed['to_user'] = seed['scope_path'] |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
181 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
182 |
def _public(self, request, entity, context): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
183 |
"""Marks the Notification as read if that hasn't happened yet. |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
184 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
185 |
for parameters see base._public() |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
186 |
""" |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
187 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
188 |
# if the user viewing is the user for which this notification is meant |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
189 |
# and the notification has not been read yet |
737
4c78ee183eb6
Notification property has_been_read changed into unread
Lennard de Rijk <ljvderijk@gmail.com>
parents:
736
diff
changeset
|
190 |
if entity.unread: |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
191 |
# get the current user |
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1059
diff
changeset
|
192 |
user = user_logic.getForCurrentAccount() |
737
4c78ee183eb6
Notification property has_been_read changed into unread
Lennard de Rijk <ljvderijk@gmail.com>
parents:
736
diff
changeset
|
193 |
|
4c78ee183eb6
Notification property has_been_read changed into unread
Lennard de Rijk <ljvderijk@gmail.com>
parents:
736
diff
changeset
|
194 |
# if the message is meant for the user that is reading it |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
195 |
if entity.scope.key() == user.key(): |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
196 |
# mark the entity as read |
986
e9611a2288ca
Rename ModelProperties to EntityProperties
Sverre Rabbelier <srabbelier@gmail.com>
parents:
970
diff
changeset
|
197 |
self._logic.updateEntityProperties(entity, {'unread' : False} ) |
732
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
198 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
199 |
context['entity_type_url'] = self._params['url_name'] |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
200 |
context['entity_suffix'] = self._logic.getKeySuffix(entity) |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
201 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
202 |
|
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
203 |
view = View() |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
204 |
create = view.create |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
205 |
edit = view.edit |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
206 |
delete = view.delete |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
207 |
list = view.list |
0a8e60228311
Fix whitespace and EOL damage in notifcation.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
727
diff
changeset
|
208 |
public = view.public |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
830
diff
changeset
|
209 |
export = view.export |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
830
diff
changeset
|
210 |