Move DBModel._id -> DBModel.id
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Fri, 30 Nov 2012 09:49:06 +0000 (10:49 +0100)
committerSebastian Spaeth <Sebastian@SSpaeth.de>
Thu, 20 Dec 2012 23:30:48 +0000 (00:30 +0100)
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>
30 files changed:
mediagoblin/auth/lib.py
mediagoblin/auth/views.py
mediagoblin/db/mixin.py
mediagoblin/db/sql/base.py
mediagoblin/db/sql/models.py
mediagoblin/decorators.py
mediagoblin/edit/lib.py
mediagoblin/edit/views.py
mediagoblin/plugins/api/views.py
mediagoblin/processing/__init__.py
mediagoblin/processing/task.py
mediagoblin/submit/views.py
mediagoblin/templates/mediagoblin/admin/panel.html
mediagoblin/templates/mediagoblin/edit/attachments.html
mediagoblin/templates/mediagoblin/edit/edit.html
mediagoblin/templates/mediagoblin/user_pages/collection.html
mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
mediagoblin/templates/mediagoblin/user_pages/media.html
mediagoblin/templates/mediagoblin/user_pages/media_collect.html
mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
mediagoblin/templates/mediagoblin/user_pages/processing_panel.html
mediagoblin/templates/mediagoblin/user_pages/user.html
mediagoblin/templates/mediagoblin/utils/collection_gallery.html
mediagoblin/tests/test_auth.py
mediagoblin/tests/test_submission.py
mediagoblin/tests/tools.py
mediagoblin/tools/pagination.py
mediagoblin/tools/request.py
mediagoblin/user_pages/lib.py
mediagoblin/user_pages/views.py

index c5b046d2550ebe363ecac9a144409ab49b13438d..8829995a7083f423b8072dfcb350d27c9c97331c 100644 (file)
@@ -109,7 +109,7 @@ def send_verification_email(user, request):
          'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
                 host=request.host,
                 uri=request.urlgen('mediagoblin.auth.verify_email'),
-                userid=unicode(user._id),
+                userid=unicode(user.id),
                 verification_key=user.verification_key)})
 
     # TODO: There is no error handling in place
@@ -144,7 +144,7 @@ def send_fp_verification_email(user, request):
          'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
                 host=request.host,
                 uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
-                userid=unicode(user._id),
+                userid=unicode(user.id),
                 fp_verification_key=user.fp_verification_key)})
 
     # TODO: There is no error handling in place
index 5b77c1229fb9871201ac97609a7344aefa483a9d..31f50fa660fa1c265cec69b1633cca070f2ae310 100644 (file)
@@ -90,7 +90,7 @@ def register(request):
             user.save(validate=True)
 
             # log the user in
-            request.session['user_id'] = unicode(user._id)
+            request.session['user_id'] = unicode(user.id)
             request.session.save()
 
             # send verification email
@@ -125,7 +125,7 @@ def login(request):
 
         if user and user.check_login(request.form['password']):
             # set up login in session
-            request.session['user_id'] = unicode(user._id)
+            request.session['user_id'] = unicode(user.id)
             request.session.save()
 
             if request.form.get('next'):
@@ -167,7 +167,7 @@ def verify_email(request):
         return render_404(request)
 
     user = request.db.User.find_one(
-        {'_id': ObjectId(unicode(request.GET['userid']))})
+        {'id': ObjectId(unicode(request.GET['userid']))})
 
     if user and user.verification_key == unicode(request.GET['token']):
         user.status = u'active'
@@ -308,7 +308,7 @@ def verify_forgot_password(request):
     # check if it's a valid Id
     try:
         user = request.db.User.find_one(
-            {'_id': ObjectId(unicode(formdata_userid))})
+            {'id': ObjectId(unicode(formdata_userid))})
     except InvalidId:
         return render_404(request)
 
index 3f395e90b68a1a257786ee397165954c493d7b49..9829bb6e92a1101a31ab2748f25998589b4ffd26 100644 (file)
@@ -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
 
index ca0c8166e262be4e9a52b656661834d25fbfafce..8aa9cc3abd5105468f3a49c8310b2070dd77abdf 100644 (file)
@@ -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
index b48c1fbea2ed0b854ba5d62fa04acdbe14841176..8315d05c0f9e905d7c2df249bdbfc9cd3ed82b6b 100644 (file)
@@ -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'),
         {})
index 90b3677136fcf9b46b5e5d2bc0f9a2170be27b84..2955c9276688095208016b3c839b3eaf94e76aad 100644 (file)
@@ -75,9 +75,9 @@ def user_may_delete_media(controller):
     @wraps(controller)
     def wrapper(request, *args, **kwargs):
         uploader_id = request.db.MediaEntry.find_one(
-            {'_id': ObjectId(request.matchdict['media'])}).uploader
+            {'id': ObjectId(request.matchdict['media'])}).uploader
         if not (request.user.is_admin or
-                request.user._id == uploader_id):
+                request.user.id == uploader_id):
             return exc.HTTPForbidden()
 
         return controller(request, *args, **kwargs)
@@ -94,7 +94,7 @@ def user_may_alter_collection(controller):
         creator_id = request.db.User.find_one(
             {'username': request.matchdict['user']}).id
         if not (request.user.is_admin or
-                request.user._id == creator_id):
+                request.user.id == creator_id):
             return exc.HTTPForbidden()
 
         return controller(request, *args, **kwargs)
@@ -134,15 +134,15 @@ def get_user_media_entry(controller):
         media = request.db.MediaEntry.find_one(
             {'slug': request.matchdict['media'],
              'state': u'processed',
-             'uploader': user._id})
+             'uploader': user.id})
 
         # no media via slug?  Grab it via ObjectId
         if not media:
             try:
                 media = request.db.MediaEntry.find_one(
-                    {'_id': ObjectId(request.matchdict['media']),
+                    {'id': ObjectId(request.matchdict['media']),
                      'state': u'processed',
-                     'uploader': user._id})
+                     'uploader': user.id})
             except InvalidId:
                 return render_404(request)
 
@@ -169,7 +169,7 @@ def get_user_collection(controller):
 
         collection = request.db.Collection.find_one(
             {'slug': request.matchdict['collection'],
-             'creator': user._id})
+             'creator': user.id})
 
         # Still no collection?  Okay, 404.
         if not collection:
@@ -194,10 +194,10 @@ def get_user_collection_item(controller):
 
         collection = request.db.Collection.find_one(
             {'slug': request.matchdict['collection'],
-             'creator': user._id})
+             'creator': user.id})
 
         collection_item = request.db.CollectionItem.find_one(
-            {'_id': request.matchdict['collection_item'] })
+            {'id': request.matchdict['collection_item'] })
 
         # Still no collection item?  Okay, 404.
         if not collection_item:
@@ -216,7 +216,7 @@ def get_media_entry_by_id(controller):
     def wrapper(request, *args, **kwargs):
         try:
             media = request.db.MediaEntry.find_one(
-                {'_id': ObjectId(request.matchdict['media']),
+                {'id': ObjectId(request.matchdict['media']),
                  'state': u'processed'})
         except InvalidId:
             return render_404(request)
index b4715134bf347dff7ed856cca8c23a450a8b1229..aab537a095ea3c7bb4d34d788d8e9de614ac6467 100644 (file)
@@ -17,7 +17,7 @@
 
 def may_edit_media(request, media):
     """Check, if the request's user may edit the media details"""
-    if media.uploader == request.user._id:
+    if media.uploader == request.user.id:
         return True
     if request.user.is_admin:
         return True
index 111f9ae8967fcb857221b1c97cf056710d78c4f6..6d938f7ce06d4d33dc6c5e89efa480918fda6ce2 100644 (file)
@@ -79,7 +79,7 @@ def edit_media(request, media):
                 location=media.url_for_self(request.urlgen))
 
     if request.user.is_admin \
-            and media.uploader != request.user._id \
+            and media.uploader != request.user.id \
             and request.method != 'POST':
         messages.add_message(
             request, messages.WARNING,
@@ -130,7 +130,7 @@ def edit_attachments(request, media):
 
             attachment_public_filepath \
                 = mg_globals.public_store.get_unique_filepath(
-                ['media_entries', unicode(media._id), 'attachment',
+                ['media_entries', unicode(media.id), 'attachment',
                  public_filename])
 
             attachment_public_file = mg_globals.public_store.get_file(
@@ -278,7 +278,7 @@ def edit_collection(request, collection):
 
         # Make sure there isn't already a Collection with this title
         existing_collection = request.db.Collection.find_one({
-                'creator': request.user._id,
+                'creator': request.user.id,
                 'title':request.form['title']})
 
         if existing_collection and existing_collection.id != collection.id:
@@ -301,7 +301,7 @@ def edit_collection(request, collection):
                             collection=collection.slug)
 
     if request.user.is_admin \
-            and collection.creator != request.user._id \
+            and collection.creator != request.user.id \
             and request.method != 'POST':
         messages.add_message(
             request, messages.WARNING,
index a1b1bcace7a261a61799f127373511405b960a07..7f93108e9298a5a8787df909828d35fa039a8d90 100644 (file)
@@ -108,7 +108,7 @@ def post_entry(request):
     process_media = registry.tasks[ProcessMedia.name]
     try:
         process_media.apply_async(
-            [unicode(entry._id)], {},
+            [unicode(entry.id)], {},
             task_id=task_id)
     except BaseException as e:
         # The purpose of this section is because when running in "lazy"
@@ -119,7 +119,7 @@ def post_entry(request):
         #
         # ... not completely the diaper pattern because the
         # exception is re-raised :)
-        mark_entry_failed(entry._id, e)
+        mark_entry_failed(entry.id, e)
         # re-raise the exception
         raise
 
index 6b2d50e2808a116f39eeaaf67998a6de799fd401..e2bc1a130f28952c45b2214795b2aee729ed6fe1 100644 (file)
@@ -38,7 +38,7 @@ class ProgressCallback(object):
 def create_pub_filepath(entry, filename):
     return mgg.public_store.get_unique_filepath(
             ['media_entries',
-             unicode(entry._id),
+             unicode(entry.id),
              filename])
 
 
@@ -93,7 +93,7 @@ def mark_entry_failed(entry_id, exc):
         # Looks like yes, so record information about that failure and any
         # metadata the user might have supplied.
         atomic_update(mgg.database.MediaEntry,
-            {'_id': entry_id},
+            {'id': entry_id},
             {u'state': u'failed',
              u'fail_error': unicode(exc.exception_path),
              u'fail_metadata': exc.metadata})
@@ -104,7 +104,7 @@ def mark_entry_failed(entry_id, exc):
         # metadata (in fact overwrite it if somehow it had previous info
         # here)
         atomic_update(mgg.database.MediaEntry,
-            {'_id': entry_id},
+            {'id': entry_id},
             {u'state': u'failed',
              u'fail_error': None,
              u'fail_metadata': {}})
index a8bc0f2f5adf04d64f82c7f4fe343cfe6f749313..06a26bb710b7b8bb80f9db53f5073666dbac4e7e 100644 (file)
@@ -42,7 +42,7 @@ class ProcessMedia(Task):
         (for now just process_image...)
         """
         entry = mgg.database.MediaEntry.one(
-            {'_id': ObjectId(media_id)})
+            {'id': ObjectId(media_id)})
 
         # Try to process, and handle expected errors.
         try:
@@ -61,7 +61,7 @@ class ProcessMedia(Task):
 
             json_processing_callback(entry)
         except BaseProcessingFail as exc:
-            mark_entry_failed(entry._id, exc)
+            mark_entry_failed(entry.id, exc)
             json_processing_callback(entry)
             return
 
@@ -72,7 +72,7 @@ class ProcessMedia(Task):
                     entry.title,
                     exc))
 
-            mark_entry_failed(entry._id, exc)
+            mark_entry_failed(entry.id, exc)
             json_processing_callback(entry)
 
         except Exception as exc:
@@ -80,7 +80,7 @@ class ProcessMedia(Task):
                     + ' processing {0}'.format(
                         entry))
 
-            mark_entry_failed(entry._id, exc)
+            mark_entry_failed(entry.id, exc)
             json_processing_callback(entry)
             raise
 
index 02026f45605bf14e8ceb8c5afd36c2dd466d8916..3628fa0da679fcb49ef5194ce2ee7ca58c4f41d3 100644 (file)
@@ -76,7 +76,7 @@ def submit_start(request):
 
                 entry.license = unicode(request.form.get('license', "")) or None
 
-                entry.uploader = request.user._id
+                entry.uploader = request.user.id
 
                 # Process the user's folksonomy "tags"
                 entry.tags = convert_to_tag_list_of_dicts(
@@ -121,7 +121,7 @@ def submit_start(request):
                 process_media = registry.tasks[ProcessMedia.name]
                 try:
                     process_media.apply_async(
-                        [unicode(entry._id)], {},
+                        [unicode(entry.id)], {},
                         task_id=task_id)
                 except BaseException as exc:
                     # The purpose of this section is because when running in "lazy"
@@ -132,7 +132,7 @@ def submit_start(request):
                     #
                     # ... not completely the diaper pattern because the
                     # exception is re-raised :)
-                    mark_entry_failed(entry._id, exc)
+                    mark_entry_failed(entry.id, exc)
                     # re-raise the exception
                     raise
 
@@ -198,12 +198,12 @@ def add_collection(request, media=None):
             collection.title = unicode(request.form['title'])
 
             collection.description = unicode(request.form.get('description'))
-            collection.creator = request.user._id
+            collection.creator = request.user.id
             collection.generate_slug()
 
             # Make sure this user isn't duplicating an existing collection
             existing_collection = request.db.Collection.find_one({
-                    'creator': request.user._id,
+                    'creator': request.user.id,
                     'title':collection.title})
 
             if existing_collection:
index d3c6c9582092c26de2eed9b561814ae5dc0e905c..6bcb5c24e3437f8c71dc4b5d1f2a9e679a794f69 100644 (file)
@@ -42,7 +42,7 @@
     </tr>
     {% for media_entry in processing_entries %}
       <tr>
-        <td>{{ media_entry._id }}</td>
+        <td>{{ media_entry.id }}</td>
         <td>{{ media_entry.get_uploader.username }}</td>
         <td>{{ media_entry.title }}</td>
         <td>{{ media_entry.created.strftime("%F %R") }}</td>
@@ -72,7 +72,7 @@
     </tr>
     {% for media_entry in failed_entries %}
       <tr>
-        <td>{{ media_entry._id }}</td>
+        <td>{{ media_entry.id }}</td>
         <td>{{ media_entry.get_uploader.username }}</td>
         <td>{{ media_entry.title }}</td>
         <td>{{ media_entry.created.strftime("%F %R") }}</td>
     </tr>
     {% for media_entry in processed_entries %}
       <tr>
-        <td>{{ media_entry._id }}</td>
+        <td>{{ media_entry.id }}</td>
         <td>{{ media_entry.get_uploader.username }}</td>
         <td><a href="{{ media_entry.url_for_self(request.urlgen) }}">{{ media_entry.title }}</a></td>
         <td>{{ media_entry.created.strftime("%F %R") }}</td>
index 6e7da0a1a53568e10819b0a2bea01b636671968d..55d446deed8e928a6b29aefa159f3ead4a8ef346 100644 (file)
@@ -28,7 +28,7 @@
 {% block mediagoblin_content %}
   <form action="{{ request.urlgen('mediagoblin.edit.attachments',
                                user= media.get_uploader.username,
-                               media= media._id) }}"
+                               media= media.id) }}"
         method="POST" enctype="multipart/form-data">
     <div class="form_box">
       <h1>
index 144184dfbeeec706c23175a025cebceaebf47c6e..1f5b91f79994fb3b4f8963079dc90f7092c94d25 100644 (file)
@@ -29,7 +29,7 @@
 
   <form action="{{ request.urlgen('mediagoblin.edit.edit_media',
                                user= media.get_uploader.username,
-                               media= media._id) }}"
+                               media= media.id) }}"
         method="POST" enctype="multipart/form-data">
     <div class="form_box_xl edit_box">
       <h1>{% trans media_title=media.title %}Editing {{ media_title }}{% endtrans %}</h1>
index f53c164f00f4f8510564f175ee18a8b910aa0cf0..f1ab7a428f6a24f61904ae06cbd3ba02a1d9df40 100644 (file)
@@ -44,7 +44,7 @@
       {{ collection_title }} by <a href="{{ user_url }}">{{ username }}</a>
     {%- endtrans %}
   </h1>
-  {% if request.user and (collection.creator == request.user._id or 
+  {% if request.user and (collection.creator == request.user.id or 
                                                 request.user.is_admin) %}
     {% set edit_url = request.urlgen('mediagoblin.edit.edit_collection',
                                      user=collection.get_creator.username,
index 9be1032114c811a4a33541ad37792cdb330a208a..447201cd6d113ef0c222f487f12cf92e7f8b624e 100644 (file)
@@ -24,7 +24,7 @@
   <form action="{{ request.urlgen('mediagoblin.user_pages.collection_item_confirm_remove',
                                  user=collection_item.in_collection.get_creator.username,
                                  collection=collection_item.in_collection.slug,
-                                 collection_item=collection_item._id) }}"
+                                 collection_item=collection_item.id) }}"
         method="POST" enctype="multipart/form-data">
     <div class="form_box">
       <h1>
index cb06c7ba1f64ab85dfbd406c871142b1f6f8996c..11f2a2a1c7004f04e9baca59d2e7799de2ba878d 100644 (file)
       {{ media.title }}
     </h2>
     {% if request.user and
-          (media.uploader == request.user._id or 
+          (media.uploader == request.user.id or 
            request.user.is_admin) %}
       {% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
                                  user= media.get_uploader.username,
-                                 media= media._id) %}
+                                 media= media.id) %}
       <a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
       {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
                                  user= media.get_uploader.username,
-                                 media= media._id) %}
+                                 media= media.id) %}
       <a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
     {% endif %}
     {% autoescape False %}
       {% if request.user %}
         <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', 
                                          user= media.get_uploader.username,
-                                         media=media._id) }}" method="POST" id="form_comment">
+                                         media=media.id) }}" method="POST" id="form_comment">
           <p>
             {% trans %}You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %}
           </p>
       {% endif %}
       {% for comment in comments %}
         {% set comment_author = comment.get_author %}
-               {% if pagination.active_id == comment._id %}
-            <div class="comment_wrapper comment_active" id="comment-{{ comment._id }}">
+               {% if pagination.active_id == comment.id %}
+            <div class="comment_wrapper comment_active" id="comment-{{ comment.id }}">
                          <a name="comment" id="comment"></a>
           {% else %}
-            <div class="comment_wrapper" id="comment-{{ comment._id }}">
+            <div class="comment_wrapper" id="comment-{{ comment.id }}">
                {% endif %}
                <div class="comment_author">
             <img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
             </a>
             {% trans %}at{% endtrans %}
             <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
-                   comment = comment._id,
+                   comment = comment.id,
                    user = media.get_uploader.username,
                    media = media.slug_or_id) }}#comment">
               {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
     {% endif %}
     {% if app_config['allow_attachments']
           and request.user
-          and (media.uploader == request.user._id
+          and (media.uploader == request.user.id
                or request.user.is_admin) %}
       {% if not media.attachment_files|count %}
         <h3>{% trans %}Attachments{% endtrans %}</h3>
       <p>
         <a href="{{ request.urlgen('mediagoblin.edit.attachments',
                       user=media.get_uploader.username,
-                      media=media._id) }}">{% trans %}Add attachment{% endtrans %}</a>
+                      media=media.id) }}">{% trans %}Add attachment{% endtrans %}</a>
       </p>
     {% endif %}
 
       <p>
         <a type="submit" href="{{ request.urlgen('mediagoblin.user_pages.media_collect', 
                                     user=media.get_uploader.username,
-                                    media=media._id) }}"
+                                    media=media.id) }}"
            class="button_action"
            title="{% trans %}Add media to collection{% endtrans %}">
           <img src="{{ request.staticdirect('/images/icon_collect.png') }}"
index cefe638bb9813315a72ab787df342a964462b941..4f35dfa39ff5e2561c89b23ebe1432eaea6a0d04 100644 (file)
@@ -28,7 +28,7 @@
 
   <form action="{{ request.urlgen('mediagoblin.user_pages.media_collect',
                                  user=media.get_uploader.username,
-                                 media=media._id) }}"
+                                 media=media.id) }}"
         method="POST" enctype="multipart/form-data">
     <div class="form_box">
       <h1>
index a3cf0210c296e498459cabb0640bb2ac65595db4..833f500dd3753f58815bd5a85c8eeffd266ce107 100644 (file)
@@ -23,7 +23,7 @@
 
   <form action="{{ request.urlgen('mediagoblin.user_pages.media_confirm_delete',
                                  user=media.get_uploader.username,
-                                 media=media._id) }}"
+                                 media=media.id) }}"
         method="POST" enctype="multipart/form-data">
     <div class="form_box">
       <h1>
index e673902bc3cba7225203fe58cbbccad2a377130a..2a449d450dbce773b12ffd248e63d12ba475a10c 100644 (file)
@@ -41,7 +41,7 @@
     </tr>
     {% for media_entry in processing_entries %}
       <tr>
-        <td>{{ media_entry._id }}</td>
+        <td>{{ media_entry.id }}</td>
         <td>{{ media_entry.title }}</td>
         <td>{{ media_entry.created.strftime("%F %R") }}</td>
         {% if media_entry.transcoding_progress %}
@@ -69,7 +69,7 @@
     </tr>
     {% for media_entry in failed_entries %}
       <tr>
-        <td>{{ media_entry._id }}</td>
+        <td>{{ media_entry.id }}</td>
         <td>{{ media_entry.title }}</td>
         <td>{{ media_entry.created.strftime("%F %R") }}</td>
         {% if media_entry.get_fail_exception() %}
@@ -97,7 +97,7 @@
     </tr>
     {% for entry in processed_entries %}
       <tr>
-        <td>{{ entry._id }}</td>
+        <td>{{ entry.id }}</td>
         <td><a href="{{ entry.url_for_self(request.urlgen) }}">{{ entry.title }}</a></td>
         <td>{{ entry.created.strftime("%F %R") }}</td>
       </tr>
index 4f7b1208fb87cff70f6f51ae0a0d4dc0e576e851..65c636b9b9398f3b6b71453b99fd9cb3ab216a44 100644 (file)
@@ -90,7 +90,7 @@
     </h1>
 
     {% if not user.url and not user.bio %}
-      {% if request.user and (request.user._id == user._id) %}
+      {% if request.user and (request.user.id == user.id) %}
         <div class="profile_sidebar empty_space">
           <p>
             {% trans %}Here's a spot to tell others about yourself.{% endtrans %}
       <div class="profile_sidebar">
         {% include "mediagoblin/utils/profile.html" %}
         {% if request.user and
-              (request.user._id == user._id or request.user.is_admin) %}
+              (request.user.id == user.id or request.user.is_admin) %}
           <a href="{{ request.urlgen('mediagoblin.edit.profile') }}?username={{
                           user.username }}">
             {%- trans %}Edit profile{% endtrans -%}
         {% include "mediagoblin/utils/feed_link.html" %}
       </div>
     {% else %}
-      {% if request.user and (request.user._id == user._id) %}
+      {% if request.user and (request.user.id == user.id) %}
         <div class="profile_showcase empty_space">
           <p>
             {% trans -%}
index ab5e46ea413548ce7e4fb403d4e34784e83711e1..dcc59244b7433b18081e9ed52dbf2805cf739849 100644 (file)
@@ -38,7 +38,7 @@
               <a href="{{ entry_url }}">{{ item.note }}</a>
             {% endif %}
            {% if request.user and
-                  (item.in_collection.creator == request.user._id or 
+                  (item.in_collection.creator == request.user.id or 
                   request.user.is_admin) %}
              {%- set remove_url=request.urlgen(
                                  'mediagoblin.user_pages.collection_item_confirm_remove',
index da17554b873086e0f4966e97d94af662fdfa70db..063651613f01ce065a11658602e57b4137f825d5 100644 (file)
@@ -154,7 +154,7 @@ def test_register_views(test_app):
     ## Make sure user is logged in
     request = template.TEMPLATE_TEST_CONTEXT[
         'mediagoblin/user_pages/user.html']['request']
-    assert request.session['user_id'] == unicode(new_user._id)
+    assert request.session['user_id'] == unicode(new_user.id)
 
     ## Make sure we get email confirmation, and try verifying
     assert len(mail.EMAIL_TEST_INBOX) == 1
@@ -171,7 +171,7 @@ def test_register_views(test_app):
 
     ### user should have these same parameters
     assert parsed_get_params['userid'] == [
-        unicode(new_user._id)]
+        unicode(new_user.id)]
     assert parsed_get_params['token'] == [
         new_user.verification_key]
 
@@ -179,7 +179,7 @@ def test_register_views(test_app):
     template.clear_test_template_context()
     response = test_app.get(
         "/auth/verify_email/?userid=%s&token=total_bs" % unicode(
-            new_user._id))
+            new_user.id))
     response.follow()
     context = template.TEMPLATE_TEST_CONTEXT[
         'mediagoblin/user_pages/user.html']
@@ -254,7 +254,7 @@ def test_register_views(test_app):
 
     # user should have matching parameters
     new_user = mg_globals.database.User.find_one({'username': u'happygirl'})
-    assert parsed_get_params['userid'] == [unicode(new_user._id)]
+    assert parsed_get_params['userid'] == [unicode(new_user.id)]
     assert parsed_get_params['token'] == [new_user.fp_verification_key]
 
     ### The forgotten password token should be set to expire in ~ 10 days
@@ -265,7 +265,7 @@ def test_register_views(test_app):
     template.clear_test_template_context()
     response = test_app.get(
         "/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode(
-            new_user._id), status=404)
+            new_user.id), status=404)
     assert_equal(response.status, '404 Not Found')
 
     ## Try using an expired token to change password, shouldn't work
@@ -393,7 +393,7 @@ def test_authentication_views(test_app):
     # Make sure user is in the session
     context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
     session = context['request'].session
-    assert session['user_id'] == unicode(test_user._id)
+    assert session['user_id'] == unicode(test_user.id)
 
     # Successful logout
     # -----------------
index b6fe00157b632b4806f0349a3f632f4ce20655cd..589ba7ed6f0bb181868934b7041c80bc0b1650f3 100644 (file)
@@ -184,7 +184,7 @@ class TestSubmission:
         # ---------------------------------------------------
         response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT,
                                          do_follow=True, url=delete_url)
-        self.check_media(request, {'_id': media_id}, 0)
+        self.check_media(request, {'id': media_id}, 0)
         self.check_comments(request, media_id, 0)
 
     def test_evil_file(self):
index d336983133f3e433b485ffa089ca6fcd940d718d..8c09c7ec9f671e807cedd120764fad639d3024e5 100644 (file)
@@ -184,20 +184,20 @@ def assert_db_meets_expected(db, expected):
     """
     Assert a database contains the things we expect it to.
 
-    Objects are found via '_id', so you should make sure your document
-    has an _id.
+    Objects are found via 'id', so you should make sure your document
+    has an id.
 
     Args:
      - db: pymongo or mongokit database connection
      - expected: the data we expect.  Formatted like:
          {'collection_name': [
-             {'_id': 'foo',
+             {'id': 'foo',
               'some_field': 'some_value'},]}
     """
     for collection_name, collection_data in expected.iteritems():
         collection = db[collection_name]
         for expected_document in collection_data:
-            document = collection.find_one({'_id': expected_document['_id']})
+            document = collection.find_one({'id': expected_document['id']})
             assert document is not None  # make sure it exists
             assert document == expected_document  # make sure it matches
 
index 50e590707052dd613cfb923ceafb5a7387382e41..141d91cc0e2eb0b8bea3c42c417c269fa23c531d 100644 (file)
@@ -41,7 +41,7 @@ class Pagination(object):
          - per_page: number of objects per page
          - cursor: db cursor
          - jump_to_id: ObjectId, sets the page to the page containing the
-           object with _id == jump_to_id.
+           object with id == jump_to_id.
         """
         self.page = page
         self.per_page = per_page
@@ -53,7 +53,7 @@ class Pagination(object):
             cursor = copy.copy(self.cursor)
 
             for (doc, increment) in izip(cursor, count(0)):
-                if doc._id == jump_to_id:
+                if doc.id == jump_to_id:
                     self.page = 1 + int(floor(increment / self.per_page))
 
                     self.active_id = jump_to_id
index ae372c92a0a7fad652dcb6dcca3a3556a401bb49..66d7ffa34d907163a65bf60b1bbba749bc28e503 100644 (file)
@@ -34,7 +34,7 @@ def setup_user_in_request(request):
     except InvalidId:
         user = None
     else:
-        user = request.db.User.find_one({'_id': oid})
+        user = request.db.User.find_one({'id': oid})
 
     if not user:
         # Something's wrong... this user doesn't exist?  Invalidate
index a4be14c2dc185a8ed9f244e706449577c0805407..8a064a7c5d0f218496b006fb33f4564f2726bdf4 100644 (file)
@@ -33,7 +33,7 @@ def send_comment_email(user, comment, media, request):
 
     comment_url = request.urlgen(
                     'mediagoblin.user_pages.media_home.view_comment',
-                    comment=comment._id,
+                    comment=comment.id,
                     user=media.get_uploader.username,
                     media=media.slug_or_id,
                     qualified=True) + '#comment'
index cbf3f15f7f72ff6866420dd38dc0a98318229b24..a091f13b56ebe7895ee57a55d48a04eee412e4b2 100644 (file)
@@ -53,7 +53,7 @@ def user_home(request, page):
             {'user': user})
 
     cursor = request.db.MediaEntry.find(
-        {'uploader': user._id,
+        {'uploader': user.id,
          'state': u'processed'}).sort('created', DESCENDING)
 
     pagination = Pagination(page, cursor)
@@ -196,12 +196,12 @@ def media_collect(request, media):
 
                 collection.description = unicode(
                         request.form.get('collection_description'))
-                collection.creator = request.user._id
+                collection.creator = request.user.id
                 collection.generate_slug()
 
                 # Make sure this user isn't duplicating an existing collection
                 existing_collection = request.db.Collection.find_one({
-                                        'creator': request.user._id,
+                                        'creator': request.user.id,
                                         'title': collection.title})
 
                 if existing_collection:
@@ -220,7 +220,7 @@ def media_collect(request, media):
             # Otherwise, use the collection selected from the drop-down
             else:
                 collection = request.db.Collection.find_one({
-                    '_id': request.form.get('collection')})
+                    'id': request.form.get('collection')})
                 collection_item.collection = collection.id
 
             # Make sure the user actually selected a collection
@@ -306,7 +306,7 @@ def media_confirm_delete(request, media):
                 location=media.url_for_self(request.urlgen))
 
     if ((request.user.is_admin and
-         request.user._id != media.uploader)):
+         request.user.id != media.uploader)):
         messages.add_message(
             request, messages.WARNING,
             _("You are about to delete another user's media. "
@@ -378,7 +378,7 @@ def collection_item_confirm_remove(request, collection_item):
                         collection=collection.slug)
 
     if ((request.user.is_admin and
-         request.user._id != collection_item.in_collection.creator)):
+         request.user.id != collection_item.in_collection.creator)):
         messages.add_message(
             request, messages.WARNING,
             _("You are about to delete an item from another user's collection. "
@@ -428,7 +428,7 @@ def collection_confirm_delete(request, collection):
                             collection=collection.slug)
 
     if ((request.user.is_admin and
-         request.user._id != collection.creator)):
+         request.user.id != collection.creator)):
         messages.add_message(
             request, messages.WARNING,
             _("You are about to delete another user's collection. "
@@ -456,7 +456,7 @@ def atom_feed(request):
         return render_404(request)
 
     cursor = request.db.MediaEntry.find({
-                 'uploader': user._id,
+                 'uploader': user.id,
                  'state': u'processed'}) \
                  .sort('created', DESCENDING) \
                  .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
@@ -524,7 +524,7 @@ def collection_atom_feed(request):
                'slug': request.matchdict['collection']})
 
     cursor = request.db.CollectionItem.find({
-                 'collection': collection._id}) \
+                 'collection': collection.id}) \
                  .sort('added', DESCENDING) \
                  .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
 
@@ -601,7 +601,7 @@ def processing_panel(request):
     #
     # Make sure we have permission to access this user's panel.  Only
     # admins and this user herself should be able to do so.
-    if not (user._id == request.user._id
+    if not (user.id == request.user.id
             or request.user.is_admin):
         # No?  Let's simply redirect to this user's homepage then.
         return redirect(
@@ -610,16 +610,16 @@ def processing_panel(request):
 
     # Get media entries which are in-processing
     processing_entries = request.db.MediaEntry.find(
-        {'uploader': user._id,
+        {'uploader': user.id,
          'state': u'processing'}).sort('created', DESCENDING)
 
     # Get media entries which have failed to process
     failed_entries = request.db.MediaEntry.find(
-        {'uploader': user._id,
+        {'uploader': user.id,
          'state': u'failed'}).sort('created', DESCENDING)
 
     processed_entries = request.db.MediaEntry.find(
-            {'uploader': user._id,
+            {'uploader': user.id,
                 'state': u'processed'}).sort('created', DESCENDING).limit(10)
 
     # Render to response