Merge lp:~ltrager/maas/lp1598461 into lp:~maas-committers/maas/trunk

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: no longer in the source branch.
Merged at revision: 5161
Proposed branch: lp:~ltrager/maas/lp1598461
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 75 lines (+36/-4)
2 files modified
src/maas/settings.py (+3/-3)
src/maasserver/views/tests/test_images.py (+33/-1)
To merge this branch: bzr merge lp:~ltrager/maas/lp1598461
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+299371@code.launchpad.net

Commit message

Show image last update using the time format consistent with other areas of the MAAS UI

Description of the change

The images page is generated with a Django template. While we convert the last update field for Ubuntu images we let Django handle the conversion of a datetime object for other image types. Because we set USE_L10N = True in maas/settings.py Django converts the datetime object using its default format which differs from the format we use in the rest of MAAS.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

> While we convert the last update field for Ubuntu images we let Django
> handle the conversion of a datetime object for other image types.

That makes it sound like the fix in this branch is cosmetic only, in
that it makes everything look the same but isn't consistent.

It would be best if date fields for all images are treated consistently,
so that a future maintainer doesn't have to figure out which way to do
it.

> Because we set USE_L10N = True in maas/settings.py Django converts the
> datetime object using its default format which differs from the format
> we use in the rest of MAAS.

Perhaps we should switch this to False instead of overriding its effects
at the edges of the application? Any guesses as to what the fallout
would be?

review: Needs Information
Revision history for this message
Lee Trager (ltrager) wrote :

I removed USE_L10N so I could set DATETIME_FORMAT. This ensures that whenever a datetime object is used in a Django template it will always be in UTC with the same format the web sockets are using. I went through the UI and everything looks fine.

Revision history for this message
Gavin Panella (allenap) wrote :

Tip top, I think that's a better solution. There is the possibility of unintended consequences -- I bet USE_L10N acts at a distance on a lot of stuff in Django -- so the start of a dev cycle is the right time to do this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maas/settings.py'
2--- src/maas/settings.py 2016-06-07 19:59:49 +0000
3+++ src/maas/settings.py 2016-07-08 00:04:26 +0000
4@@ -156,9 +156,9 @@
5 # to load the internationalization machinery.
6 USE_I18N = True
7
8-# If you set this to False, Django will not format dates, numbers and
9-# calendars according to the current locale
10-USE_L10N = True
11+# Set the datetime format Django uses in templates to show the time in UTC.
12+# The format is consistent with what the websockets use.
13+DATETIME_FORMAT = 'D, d M. o H:i:s'
14
15 # Absolute filesystem path to the directory that will hold user-uploaded files.
16 # Example: "/home/media/media.lawrence.com/media/"
17
18=== modified file 'src/maasserver/views/tests/test_images.py'
19--- src/maasserver/views/tests/test_images.py 2016-06-10 17:54:17 +0000
20+++ src/maasserver/views/tests/test_images.py 2016-07-08 00:04:26 +0000
21@@ -308,7 +308,11 @@
22 last_update = doc.cssselect(
23 'table#other-resources > tbody > '
24 'tr > td')[5].text_content().strip()
25- self.assertNotEqual('not synced', last_update)
26+ dt = datetime.datetime.strptime(last_update, '%a, %d %b. %Y %H:%M:%S')
27+ # TimestampedModel includes microseconds which we don't print. To
28+ # confirm the right time is returned its easiest to just compare the
29+ # ctimes
30+ self.assertEquals(cache.updated.ctime(), dt.ctime())
31
32 def test_shows_number_of_nodes_for_synced_resource(self):
33 self.client_log_in(as_admin=True)
34@@ -480,6 +484,20 @@
35 1, len(delete_btn),
36 "Didn't show delete button for generated image.")
37
38+ def test_shows_last_update_time_for_synced_resource(self):
39+ self.client_log_in(as_admin=True)
40+ resource = self.make_generated_resource()
41+ response = self.client.get(reverse('images'))
42+ doc = fromstring(response.content)
43+ last_update = doc.cssselect(
44+ 'table#generated-resources > tbody > '
45+ 'tr > td')[5].text_content().strip()
46+ dt = datetime.datetime.strptime(last_update, '%a, %d %b. %Y %H:%M:%S')
47+ # TimestampedModel includes microseconds which we don't print. To
48+ # confirm the right time is returned its easiest to just compare the
49+ # ctimes
50+ self.assertEquals(resource.updated.ctime(), dt.ctime())
51+
52 def test_hides_delete_button_for_generated_resource_when_not_admin(self):
53 self.client_log_in()
54 self.make_generated_resource()
55@@ -552,6 +570,20 @@
56 'table#uploaded-resources > tbody > tr > td')[1].text_content()
57 self.assertEqual(name, name_col.strip())
58
59+ def test_shows_last_update_time_for_synced_resource(self):
60+ self.client_log_in(as_admin=True)
61+ resource = self.make_uploaded_resource()
62+ response = self.client.get(reverse('images'))
63+ doc = fromstring(response.content)
64+ last_update = doc.cssselect(
65+ 'table#uploaded-resources > tbody > '
66+ 'tr > td')[5].text_content().strip()
67+ dt = datetime.datetime.strptime(last_update, '%a, %d %b. %Y %H:%M:%S')
68+ # TimestampedModel includes microseconds which we don't print. To
69+ # confirm the right time is returned its easiest to just compare the
70+ # ctimes
71+ self.assertEquals(resource.updated.ctime(), dt.ctime())
72+
73 def test_shows_delete_button_for_uploaded_resource(self):
74 self.client_log_in(as_admin=True)
75 self.make_uploaded_resource()