diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-11-30 10:49:06 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-21 00:30:48 +0100 |
commit | 5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868 (patch) | |
tree | 6b2ec753c753745ee7964b9544835619b915d0f2 /mediagoblin/db | |
parent | 7e55bcb898d37010a5e9bd8a666cd3ddfa63de33 (diff) | |
download | mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.tar.lz mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.tar.xz mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.zip |
Move DBModel._id -> DBModel.id
We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.
It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.
This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)
I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/db')
-rw-r--r-- | mediagoblin/db/mixin.py | 8 | ||||
-rw-r--r-- | mediagoblin/db/sql/base.py | 17 | ||||
-rw-r--r-- | mediagoblin/db/sql/models.py | 10 |
3 files changed, 6 insertions, 29 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index 3f395e90..9829bb6e 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -99,14 +99,14 @@ class MediaEntryMixin(object): @property def slug_or_id(self): - return (self.slug or self._id) + return (self.slug or self.id) def url_for_self(self, urlgen, **extra_args): """ Generate an appropriate url for ourselves - Use a slug if we have one, else use our '_id'. + Use a slug if we have one, else use our 'id'. """ uploader = self.get_uploader @@ -208,13 +208,13 @@ class CollectionMixin(object): @property def slug_or_id(self): - return (self.slug or self._id) + return (self.slug or self.id) def url_for_self(self, urlgen, **extra_args): """ Generate an appropriate url for ourselves - Use a slug if we have one, else use our '_id'. + Use a slug if we have one, else use our 'id'. """ creator = self.get_creator diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index ca0c8166..8aa9cc3a 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -42,28 +42,15 @@ class GMGQuery(Query): Session = scoped_session(sessionmaker(query_cls=GMGQuery)) -def _fix_query_dict(query_dict): - if '_id' in query_dict: - query_dict['id'] = query_dict.pop('_id') - - class GMGTableBase(object): query = Session.query_property() @classmethod - def find(cls, query_dict=None): - if query_dict is None: - query_dict = {} - - _fix_query_dict(query_dict) + def find(cls, query_dict): return cls.query.filter_by(**query_dict) @classmethod - def find_one(cls, query_dict=None): - if query_dict is None: - query_dict = {} - - _fix_query_dict(query_dict) + def find_one(cls, query_dict): return cls.query.filter_by(**query_dict).first() @classmethod diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index b48c1fbe..8315d05c 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -83,8 +83,6 @@ class User(Base, UserMixin): ## TODO # plugin data would be in a separate model - _id = SimpleFieldAlias("id") - def __repr__(self): return '<{0} #{1} {2} {3} "{4}">'.format( self.__class__.__name__, @@ -161,8 +159,6 @@ class MediaEntry(Base, MediaEntryMixin): # media_data # fail_error - _id = SimpleFieldAlias("id") - def get_comments(self, ascending=False): order_col = MediaComment.created if not ascending: @@ -359,8 +355,6 @@ class MediaComment(Base, MediaCommentMixin): get_author = relationship(User) - _id = SimpleFieldAlias("id") - class Collection(Base, CollectionMixin): __tablename__ = "core__collections" @@ -383,8 +377,6 @@ class Collection(Base, CollectionMixin): return CollectionItem.query.filter_by( collection=self.id).order_by(order_col) - _id = SimpleFieldAlias("id") - class CollectionItem(Base, CollectionItemMixin): __tablename__ = "core__collection_items" @@ -400,8 +392,6 @@ class CollectionItem(Base, CollectionItemMixin): get_media_entry = relationship(MediaEntry) - _id = SimpleFieldAlias("id") - __table_args__ = ( UniqueConstraint('collection', 'media_entry'), {}) |