More refactoring: Custom table classes now don't need to assign to the _snapshot...
authorMichael Elsdörfer <michael@elsdoerfer.info>
Wed, 24 Mar 2010 17:10:03 +0000 (18:10 +0100)
committerMichael Elsdörfer <michael@elsdoerfer.info>
Wed, 24 Mar 2010 17:10:03 +0000 (18:10 +0100)
django_tables/base.py
django_tables/memory.py
django_tables/models.py

index 540ab637d0bc7939c5d6dc1ac9da277343aac1d2..bdb97bb29ac6af6647139213b2f7cba325fd081b 100644 (file)
@@ -443,6 +443,15 @@ class BaseTable(object):
         # ``Table`` class docstring for more information.\r
         self.base_columns = copy.deepcopy(type(self).base_columns)\r
 \r
+    def _reset_snapshot(self, reason):\r
+        """Called to reset the current snaptshot, for example when\r
+        options change that could affect it.\r
+\r
+        ``reason`` is given so that subclasses can decide that a\r
+        given change may not affect their snaptshot.\r
+        """\r
+        self._snapshot = None\r
+\r
     def _build_snapshot(self):\r
         """Rebuild the table for the current set of options.\r
 \r
@@ -452,11 +461,11 @@ class BaseTable(object):
 \r
         Subclasses should override this.\r
         """\r
-        self._snapshot = copy.copy(self._data)\r
+        return self._data\r
 \r
     def _get_data(self):\r
         if self._snapshot is None:\r
-            self._build_snapshot()\r
+            self._snapshot = self._build_snapshot()\r
         return self._snapshot\r
     data = property(lambda s: s._get_data())\r
 \r
@@ -516,8 +525,7 @@ class BaseTable(object):
             return True\r
 \r
     def _set_order_by(self, value):\r
-        if self._snapshot is not None:\r
-            self._snapshot = None\r
+        self._reset_snapshot('order_by')\r
         # accept both string and tuple instructions\r
         order_by = (isinstance(value, basestring) \\r
             and [value.split(',')] \\r
index cd2118b5d8d0fa3c650d6acd8e82372a50816d7d..35ccac61c9b8ab3497ccb8ba1c342579f5e28cf6 100644 (file)
@@ -79,7 +79,7 @@ class MemoryTable(BaseTable):
         if self.order_by:
             actual_order_by = self._resolve_sort_directions(self.order_by)
             sort_table(snapshot, self._cols_to_fields(actual_order_by))
-        self._snapshot = snapshot
+        return snapshot
 
 
 class Table(MemoryTable):
index b7bf76cfbc29c5c88ddc78fda3e0522cd6173808..4a24ad502ec464a834a4aa999c271311502efd98 100644 (file)
@@ -245,4 +245,4 @@ class ModelTable(BaseTable):
         if self.order_by:\r
             actual_order_by = self._resolve_sort_directions(self.order_by)\r
             queryset = queryset.order_by(*self._cols_to_fields(actual_order_by))\r
-        self._snapshot = queryset\r
+        return queryset\r