diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-20 13:02:15 +0000 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-20 13:02:15 +0000 |
commit | 03bb1b7907d2d0fa522bf4705e4891494839da09 (patch) | |
tree | f60658eb937886dfd1cc349cab605c13a02942e5 /mediagoblin/db/base.py | |
parent | fd703bb4d0665958d853b89f6069eefd8a8c8113 (diff) | |
parent | 64a456a4e50b03e4fa2b33ceb208e88d2e02fce7 (diff) | |
download | mediagoblin-03bb1b7907d2d0fa522bf4705e4891494839da09.tar.lz mediagoblin-03bb1b7907d2d0fa522bf4705e4891494839da09.tar.xz mediagoblin-03bb1b7907d2d0fa522bf4705e4891494839da09.zip |
Merge branch 'comments'
Diffstat (limited to 'mediagoblin/db/base.py')
-rw-r--r-- | mediagoblin/db/base.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/mediagoblin/db/base.py b/mediagoblin/db/base.py index a62cbebc..11afbcec 100644 --- a/mediagoblin/db/base.py +++ b/mediagoblin/db/base.py @@ -13,6 +13,9 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import six +import copy + from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import inspect @@ -22,6 +25,30 @@ if not DISABLE_GLOBALS: from sqlalchemy.orm import scoped_session, sessionmaker Session = scoped_session(sessionmaker()) +class FakeCursor(object): + + def __init__ (self, cursor, mapper, filter=None): + self.cursor = cursor + self.mapper = mapper + self.filter = filter + + def count(self): + return self.cursor.count() + + def __copy__(self): + # Or whatever the function is named to make + # copy.copy happy? + return FakeCursor(copy.copy(self.cursor), self.mapper, self.filter) + + def __iter__(self): + return six.moves.filter(self.filter, six.moves.map(self.mapper, self.cursor)) + + def __getitem__(self, key): + return self.mapper(self.cursor[key]) + + def slice(self, *args, **kwargs): + r = self.cursor.slice(*args, **kwargs) + return list(six.moves.filter(self.filter, six.moves.map(self.mapper, r))) class GMGTableBase(object): # Deletion types @@ -93,7 +120,7 @@ class GMGTableBase(object): id=self.actor ).first() tombstone.object_type = self.object_type - tombstone.save() + tombstone.save(commit=False) # There will be a lot of places where the GenericForeignKey will point # to the model, we want to remap those to our tombstone. |