self._snapshot = None # will store output dataset (ordered...)\r
self._rows = Rows(self)\r
self._columns = Columns(self)\r
- self._order_by = order_by\r
+\r
+ self.order_by = order_by\r
\r
# Make a copy so that modifying this will not touch the class\r
# definition. Note that this is different from forms, where the\r
order_by = (isinstance(value, basestring) \\r
and [value.split(',')] \\r
or [value])[0]\r
- # validate, remove all invalid order instructions\r
- validated_order_by = []\r
- for o in order_by:\r
- if self._validate_column_name((o[:1]=='-' and [o[1:]] or [o])[0], "order_by"):\r
- validated_order_by.append(o)\r
- elif not options.IGNORE_INVALID_OPTIONS:\r
- raise ValueError('Column name %s is invalid.' % o)\r
- self._order_by = OrderByTuple(validated_order_by)\r
+ if order_by:\r
+ # validate, remove all invalid order instructions\r
+ validated_order_by = []\r
+ for o in order_by:\r
+ if self._validate_column_name((o[:1]=='-' and [o[1:]] or [o])[0], "order_by"):\r
+ validated_order_by.append(o)\r
+ elif not options.IGNORE_INVALID_OPTIONS:\r
+ raise ValueError('Column name %s is invalid.' % o)\r
+ self._order_by = OrderByTuple(validated_order_by)\r
+ else:\r
+ self._order_by = ()\r
order_by = property(lambda s: s._order_by, _set_order_by)\r
\r
def __unicode__(self):\r
books.order_by = order\r
assert [b['id'] for b in books.rows] == result\r
\r
+ # None is normalized to an empty tuple, ensuring iterability; it's\r
+ # also the default value\r
+ assert books.order_by == ()\r
+ iter(books.order_by)\r
+ books.order_by = None\r
+ assert books.order_by == ()\r
+ iter(books.order_by)\r
+\r
# test various orderings\r
test_order(('num_pages',), [1,3,2,4])\r
test_order(('-num_pages',), [4,2,3,1])\r
assert not books.order_by\r
test_order(('language', 'num_pages'), [1,3,2,4]) # as if: 'num_pages'\r
\r
+ # [bug] order_by did not run through setter when passed to init\r
+ books = BookTable([], order_by='name')\r
+ assert books.order_by == ('name',)\r
+\r
def test_callable():\r
"""Data fields, ``default`` and ``data`` options can be callables.\r
"""\r