← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/bug-974021-sorted-nodes into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/bug-974021-sorted-nodes into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #974021 in MAAS: "Node listing is not sorted"
  https://bugs.launchpad.net/maas/+bug/974021

For more details, see:
https://code.launchpad.net/~rvb/maas/bug-974021-sorted-nodes/+merge/101587

This branch adds sorting to the node listing page.  It sorts the nodes newest first.

= Pre-imp =

Talked with jtv who is ready for anything as long as the nodes are sorted ;).
-- 
https://code.launchpad.net/~rvb/maas/bug-974021-sorted-nodes/+merge/101587
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/bug-974021-sorted-nodes into lp:maas.
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-04-11 07:30:47 +0000
+++ src/maasserver/tests/test_views.py	2012-04-11 15:39:24 +0000
@@ -516,6 +516,24 @@
         node_link = reverse('node-view', args=[node.system_id])
         self.assertIn(node_link, get_content_links(response))
 
+    def test_node_list_displays_sorted_list_of_nodes(self):
+        # Nodes are sorted on the node list page, newest first.
+        nodes = [factory.make_node() for i in range(3)]
+        nodes.reverse()
+        # Modify one node to make sure that the default db ordering
+        # (by modification date) is not used.
+        node = nodes[1]
+        node.hostname = factory.getRandomString()
+        node.save()
+        response = self.client.get(reverse('node-list'))
+        node_links = [
+            reverse('node-view', args=[node.system_id])
+            for node in nodes]
+        self.assertEqual(
+            node_links,
+            [link for link in get_content_links(response)
+                if link.startswith('/nodes')])
+
     def test_view_node_displays_node_info(self):
         # The node page features the basic information about the node.
         node = factory.make_node(owner=self.logged_in_user)

=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py	2012-04-04 17:39:33 +0000
+++ src/maasserver/views.py	2012-04-11 15:39:24 +0000
@@ -205,8 +205,10 @@
     context_object_name = "node_list"
 
     def get_queryset(self):
+        # Sort nodes, newest first.
         return Node.objects.get_nodes(
-            user=self.request.user, perm=NODE_PERMISSION.VIEW)
+            user=self.request.user,
+            perm=NODE_PERMISSION.VIEW).order_by('-id')
 
     def get_context_data(self, **kwargs):
         context = super(NodeListView, self).get_context_data(**kwargs)