+ # Just creare some nodes to have something in the list
typo 'create'
However, why do we need the nodes to actually get the links? I would
tend to have no more than 1 'make_node()' call.
...
+ node_links = [
+ reverse('node-view', args=[node.system_id])
+
+ for node in sorted_nodes]
The spacing in this test looks wrong. You probably want to run 'make
lint' and handle anything that it brings up as a problem.
+ # Now check the reverse order
+ sorted_nodes = sorted(
+ nodes, key=lambda x: x.status, reverse=True)
I don't think you need to re-do the sort, if anything just do
"sorted_nodes = reversed(sorted_nodes)".
However, I think all you actually need to do is:
node_links = reversed(node_links) and not do anything with re-sorting
the node objects themselves.
I'm hesitant about using 'filter' in these cases. I'm wondering if
there is a better way to write the tests. Perhaps giving a specific
class id for the node links, or one for the sorting links?
I kind of feel like we want to always have a sort field that is
unique. What I mean, is that if you sort by 'status' then all nodes
with the same status can occur in arbitrary order. (It is probably
reasonably static because the db isn't changing a lot in the
background, but it isn't guaranteed). Certainly an unrelated action
that would otherwise not affect the nodes being shown could cause a
node that was on page 1 to suddenly swap places with a node on page 2.
I'm not sure about the specific order of operations, but I think we
want something like:
.order_by(id).order_by(order_by)
Or
.order_by(order_by).order_by(id)
Since the existing order was '-created' we might keep that one?
John
=:->
review: approve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 10/24/2012 02:57 PM, Dimiter Naydenov wrote: reviewers) /bugs.launchpad .net/maas/ +bug/994887 /code.launchpad .net/~dimitern/ maas/bug- 994887- alternate- nodes-list- sorting/ +merge/ 131177 /code.launchpad .net/~dimitern/ maas/bug- 994887- nodes-listing- does-not- support- sorting/ +merge/ 130600
> Dimiter Naydenov has proposed merging
> lp:~dimitern/maas/bug-994887-alternate-nodes-list-sorting into
> lp:maas.
>
> Commit message: Fix bug #994887: Nodes list view now supports
> sorting by hostname(mac) or status columns.
>
> Requested reviews: Launchpad code reviewers (launchpad-
> Related bugs: Bug #994887 in MAAS: "Nodes listing does not support
> sorting" https:/
>
> For more details, see:
> https:/
>
> Implemented sorting for /MAAS/nodes/ list - by hostname or status
> (asc/desc). This is an alternative, simpler solution, compared to
> https:/
> - not using third party modules (django-sortable) anymore. UI
> changes (sorting up/down arrows) were already approved, so just the
> code changes need approval.
>
+ # Just creare some nodes to have something in the list
typo 'create'
However, why do we need the nodes to actually get the links? I would
tend to have no more than 1 'make_node()' call.
... 'node-view' , args=[node. system_ id])
+ node_links = [
+ reverse(
+
+ for node in sorted_nodes]
The spacing in this test looks wrong. You probably want to run 'make
lint' and handle anything that it brings up as a problem.
+ # Now check the reverse order
+ sorted_nodes = sorted(
+ nodes, key=lambda x: x.status, reverse=True)
I don't think you need to re-do the sort, if anything just do sorted_ nodes)" . node_links) and not do anything with re-sorting
"sorted_nodes = reversed(
However, I think all you actually need to do is:
node_links = reversed(
the node objects themselves.
That should simplify the test a bit.
+ # Exclude header sorting links
self. assertEqual( [last_node_ link], xpath(" //div[@ id='nodes' ]/table/ /a/@href" )) xpath(" //div[@ id='nodes' ]/table/ /a/@href" )))
- - document.
+ filter(
+ lambda x: 'sort=' not in x,
+ document.
I'm hesitant about using 'filter' in these cases. I'm wondering if
there is a better way to write the tests. Perhaps giving a specific
class id for the node links, or one for the sorting links?
nodes = Node.objects. get_nodes(
user= self.request. user, prefetch_mac=True, PERMISSION. VIEW,). order_by( '-created' ) PERMISSION. VIEW,). order_by( order_by)
- - perm=NODE_
+ perm=NODE_
I kind of feel like we want to always have a sort field that is
unique. What I mean, is that if you sort by 'status' then all nodes
with the same status can occur in arbitrary order. (It is probably
reasonably static because the db isn't changing a lot in the
background, but it isn't guaranteed). Certainly an unrelated action
that would otherwise not affect the nodes being shown could cause a
node that was on page 1 to suddenly swap places with a node on page 2.
I'm not sure about the specific order of operations, but I think we
want something like:
.order_ by(id). order_by( order_by)
Or by(order_ by).order_ by(id)
.order_
Since the existing order was '-created' we might keep that one?
John
=:->
review: approve
-----BEGIN PGP SIGNATURE----- www.enigmail. net/
H8TYACgkQJdeBCY SNAAOqvgCgkd3RV 3BCLh/Ledkqfm8t /rZE 1azGvPsYLuH8CSo qG
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAlC
Jn0Anj3W6PSxQGG
=YOlj
-----END PGP SIGNATURE-----