0001-studio-show-only-recent-changes-of-current-user-6295.patch
tests/admin_pages/test_studio.py | ||
---|---|---|
137 | 137 | |
138 | 138 |
def test_studio_home_recent_changes(sql_pub): |
139 | 139 |
pub = sql_pub |
140 |
create_superuser(pub) |
|
140 |
user = create_superuser(pub) |
|
141 |
other_user = pub.user_class(name='other') |
|
142 |
other_user.store() |
|
141 | 143 | |
142 | 144 |
BlockDef.wipe() |
143 | 145 |
CardDef.wipe() |
... | ... | |
163 | 165 | |
164 | 166 |
app = login(get_app(pub)) |
165 | 167 |
resp = app.get('/backoffice/studio/') |
168 |
assert len(resp.pyquery.find('ul.recent-changes li')) == 0 |
|
169 | ||
170 |
for snapshot in pub.snapshot_class.select(): |
|
171 |
snapshot.user_id = other_user.id |
|
172 |
snapshot.store() |
|
173 |
resp = app.get('/backoffice/studio/') |
|
174 |
assert len(resp.pyquery.find('ul.recent-changes li')) == 0 |
|
175 | ||
176 |
for snapshot in pub.snapshot_class.select(): |
|
177 |
snapshot.user_id = user.id |
|
178 |
snapshot.store() |
|
179 |
resp = app.get('/backoffice/studio/') |
|
180 |
assert len(resp.pyquery.find('ul.recent-changes li')) == 5 |
|
181 | ||
166 | 182 |
# too old |
167 | 183 |
for i in range(5): |
168 | 184 |
assert 'backoffice/forms/blocks/%s/' % objects[BlockDef.xml_root_node][i].id not in resp |
wcs/backoffice/studio.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
from quixote import get_publisher |
|
17 |
from quixote import get_publisher, get_request
|
|
18 | 18 |
from quixote.directory import Directory |
19 | 19 | |
20 | 20 |
from wcs.admin.logged_errors import LoggedErrorsDirectory |
... | ... | |
78 | 78 |
} |
79 | 79 |
if get_publisher().snapshot_class: |
80 | 80 |
context['recent_objects'] = get_publisher().snapshot_class.get_recent_changes( |
81 |
object_types=[ot.xml_root_node for ot in object_types] |
|
81 |
object_types=[ot.xml_root_node for ot in object_types], |
|
82 |
user=get_request().user, |
|
82 | 83 |
) |
83 | 84 |
return template.QommonTemplateResponse( |
84 | 85 |
templates=['wcs/backoffice/studio.html'], context=context, is_django_native=True |
wcs/snapshots.py | ||
---|---|---|
184 | 184 |
obj.store() |
185 | 185 | |
186 | 186 |
@classmethod |
187 |
def get_recent_changes(cls, object_types): |
|
188 |
elements = cls._get_recent_changes(object_types) |
|
187 |
def get_recent_changes(cls, object_types, user):
|
|
188 |
elements = cls._get_recent_changes(object_types, user)
|
|
189 | 189 |
instances = [] |
190 | 190 |
for object_type, object_id, snapshot_timestamp in elements: |
191 | 191 |
klass = cls.get_class(object_type) |
wcs/sql.py | ||
---|---|---|
3788 | 3788 |
return cls.get(row[0]) |
3789 | 3789 | |
3790 | 3790 |
@classmethod |
3791 |
def _get_recent_changes(cls, object_types): |
|
3791 |
def _get_recent_changes(cls, object_types, user):
|
|
3792 | 3792 |
conn, cur = get_connection_and_cursor() |
3793 | 3793 |
sql_statement = '''SELECT object_type, object_id, MAX(timestamp) AS m |
3794 | 3794 |
FROM snapshots |
3795 | 3795 |
WHERE object_type IN %(object_types)s |
3796 |
AND user_id = %(user_id)s |
|
3796 | 3797 |
GROUP BY object_type, object_id |
3797 | 3798 |
ORDER BY m DESC |
3798 | 3799 |
LIMIT 5''' |
3799 |
parameters = {'object_types': tuple(object_types)} |
|
3800 |
parameters = {'object_types': tuple(object_types), 'user_id': str(user.id)}
|
|
3800 | 3801 |
cur.execute(sql_statement, parameters) |
3801 | 3802 |
result = cur.fetchall() |
3802 | 3803 |
conn.commit() |
wcs/templates/wcs/backoffice/studio.html | ||
---|---|---|
34 | 34 | |
35 | 35 |
<div class="paragraph"> |
36 | 36 |
<h3>{% trans "Recent changes" context "studio" %}</h3> |
37 |
<ul> |
|
37 |
<ul class="recent-changes">
|
|
38 | 38 |
{% for obj in recent_objects %} |
39 | 39 |
<li><a href="{{ obj.get_admin_url }}">{{ obj.name }} ({{ obj.verbose_name }})</a> |
40 | 40 |
<span class="timestamp">{{ obj.snapshot_timestamp }}</span></li> |
41 |
- |