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>
This commit is contained in:
parent
7e55bcb898
commit
5c2b84869f
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'),
|
||||
{})
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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': {}})
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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>
|
||||
@ -101,7 +101,7 @@
|
||||
</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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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,
|
||||
|
@ -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>
|
||||
|
@ -79,15 +79,15 @@
|
||||
{{ 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 %}
|
||||
@ -104,7 +104,7 @@
|
||||
{% 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>
|
||||
@ -117,11 +117,11 @@
|
||||
{% 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') }}" />
|
||||
@ -131,7 +131,7 @@
|
||||
</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") }}
|
||||
@ -181,7 +181,7 @@
|
||||
{% 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>
|
||||
@ -189,7 +189,7 @@
|
||||
<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 %}
|
||||
|
||||
@ -197,7 +197,7 @@
|
||||
<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') }}"
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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 %}
|
||||
@ -112,7 +112,7 @@
|
||||
<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 -%}
|
||||
@ -139,7 +139,7 @@
|
||||
{% 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 -%}
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
# -----------------
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user