aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/base.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-10-20 12:24:54 +0000
committerJessica Tallon <tsyesika@tsyesika.se>2015-10-20 12:24:54 +0000
commit64a456a4e50b03e4fa2b33ceb208e88d2e02fce7 (patch)
treef60658eb937886dfd1cc349cab605c13a02942e5 /mediagoblin/db/base.py
parentfd703bb4d0665958d853b89f6069eefd8a8c8113 (diff)
downloadmediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.tar.lz
mediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.tar.xz
mediagoblin-64a456a4e50b03e4fa2b33ceb208e88d2e02fce7.zip
Comment changes for federation
This adds a new Comment link table that is used to link between some object and then the comment object, which can be more or less any object in Mediagoblin. The MediaComment has been renamed to TextComment as that more aptly describes what it is. There is migrations for these changes. There is also the conslidation of the Report tables into a single Report table, the same with the Notification objects. This is because both of them split out MediaEntry and Comment versions into their own polymorphic versions from a base, this is no longer a meaningful distinction as comments can be anything.
Diffstat (limited to 'mediagoblin/db/base.py')
-rw-r--r--mediagoblin/db/base.py29
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.