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(
|
'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
|
||||||
host=request.host,
|
host=request.host,
|
||||||
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
||||||
userid=unicode(user._id),
|
userid=unicode(user.id),
|
||||||
verification_key=user.verification_key)})
|
verification_key=user.verification_key)})
|
||||||
|
|
||||||
# TODO: There is no error handling in place
|
# 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(
|
'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
|
||||||
host=request.host,
|
host=request.host,
|
||||||
uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
|
uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
|
||||||
userid=unicode(user._id),
|
userid=unicode(user.id),
|
||||||
fp_verification_key=user.fp_verification_key)})
|
fp_verification_key=user.fp_verification_key)})
|
||||||
|
|
||||||
# TODO: There is no error handling in place
|
# TODO: There is no error handling in place
|
||||||
|
@ -90,7 +90,7 @@ def register(request):
|
|||||||
user.save(validate=True)
|
user.save(validate=True)
|
||||||
|
|
||||||
# log the user in
|
# log the user in
|
||||||
request.session['user_id'] = unicode(user._id)
|
request.session['user_id'] = unicode(user.id)
|
||||||
request.session.save()
|
request.session.save()
|
||||||
|
|
||||||
# send verification email
|
# send verification email
|
||||||
@ -125,7 +125,7 @@ def login(request):
|
|||||||
|
|
||||||
if user and user.check_login(request.form['password']):
|
if user and user.check_login(request.form['password']):
|
||||||
# set up login in session
|
# set up login in session
|
||||||
request.session['user_id'] = unicode(user._id)
|
request.session['user_id'] = unicode(user.id)
|
||||||
request.session.save()
|
request.session.save()
|
||||||
|
|
||||||
if request.form.get('next'):
|
if request.form.get('next'):
|
||||||
@ -167,7 +167,7 @@ def verify_email(request):
|
|||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
|
||||||
user = request.db.User.find_one(
|
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']):
|
if user and user.verification_key == unicode(request.GET['token']):
|
||||||
user.status = u'active'
|
user.status = u'active'
|
||||||
@ -308,7 +308,7 @@ def verify_forgot_password(request):
|
|||||||
# check if it's a valid Id
|
# check if it's a valid Id
|
||||||
try:
|
try:
|
||||||
user = request.db.User.find_one(
|
user = request.db.User.find_one(
|
||||||
{'_id': ObjectId(unicode(formdata_userid))})
|
{'id': ObjectId(unicode(formdata_userid))})
|
||||||
except InvalidId:
|
except InvalidId:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
|
||||||
|
@ -99,14 +99,14 @@ class MediaEntryMixin(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def slug_or_id(self):
|
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):
|
def url_for_self(self, urlgen, **extra_args):
|
||||||
"""
|
"""
|
||||||
Generate an appropriate url for ourselves
|
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
|
uploader = self.get_uploader
|
||||||
|
|
||||||
@ -208,13 +208,13 @@ class CollectionMixin(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def slug_or_id(self):
|
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):
|
def url_for_self(self, urlgen, **extra_args):
|
||||||
"""
|
"""
|
||||||
Generate an appropriate url for ourselves
|
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
|
creator = self.get_creator
|
||||||
|
|
||||||
|
@ -42,28 +42,15 @@ class GMGQuery(Query):
|
|||||||
Session = scoped_session(sessionmaker(query_cls=GMGQuery))
|
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):
|
class GMGTableBase(object):
|
||||||
query = Session.query_property()
|
query = Session.query_property()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find(cls, query_dict=None):
|
def find(cls, query_dict):
|
||||||
if query_dict is None:
|
|
||||||
query_dict = {}
|
|
||||||
|
|
||||||
_fix_query_dict(query_dict)
|
|
||||||
return cls.query.filter_by(**query_dict)
|
return cls.query.filter_by(**query_dict)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_one(cls, query_dict=None):
|
def find_one(cls, query_dict):
|
||||||
if query_dict is None:
|
|
||||||
query_dict = {}
|
|
||||||
|
|
||||||
_fix_query_dict(query_dict)
|
|
||||||
return cls.query.filter_by(**query_dict).first()
|
return cls.query.filter_by(**query_dict).first()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -83,8 +83,6 @@ class User(Base, UserMixin):
|
|||||||
## TODO
|
## TODO
|
||||||
# plugin data would be in a separate model
|
# plugin data would be in a separate model
|
||||||
|
|
||||||
_id = SimpleFieldAlias("id")
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{0} #{1} {2} {3} "{4}">'.format(
|
return '<{0} #{1} {2} {3} "{4}">'.format(
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
@ -161,8 +159,6 @@ class MediaEntry(Base, MediaEntryMixin):
|
|||||||
# media_data
|
# media_data
|
||||||
# fail_error
|
# fail_error
|
||||||
|
|
||||||
_id = SimpleFieldAlias("id")
|
|
||||||
|
|
||||||
def get_comments(self, ascending=False):
|
def get_comments(self, ascending=False):
|
||||||
order_col = MediaComment.created
|
order_col = MediaComment.created
|
||||||
if not ascending:
|
if not ascending:
|
||||||
@ -359,8 +355,6 @@ class MediaComment(Base, MediaCommentMixin):
|
|||||||
|
|
||||||
get_author = relationship(User)
|
get_author = relationship(User)
|
||||||
|
|
||||||
_id = SimpleFieldAlias("id")
|
|
||||||
|
|
||||||
|
|
||||||
class Collection(Base, CollectionMixin):
|
class Collection(Base, CollectionMixin):
|
||||||
__tablename__ = "core__collections"
|
__tablename__ = "core__collections"
|
||||||
@ -383,8 +377,6 @@ class Collection(Base, CollectionMixin):
|
|||||||
return CollectionItem.query.filter_by(
|
return CollectionItem.query.filter_by(
|
||||||
collection=self.id).order_by(order_col)
|
collection=self.id).order_by(order_col)
|
||||||
|
|
||||||
_id = SimpleFieldAlias("id")
|
|
||||||
|
|
||||||
|
|
||||||
class CollectionItem(Base, CollectionItemMixin):
|
class CollectionItem(Base, CollectionItemMixin):
|
||||||
__tablename__ = "core__collection_items"
|
__tablename__ = "core__collection_items"
|
||||||
@ -400,8 +392,6 @@ class CollectionItem(Base, CollectionItemMixin):
|
|||||||
|
|
||||||
get_media_entry = relationship(MediaEntry)
|
get_media_entry = relationship(MediaEntry)
|
||||||
|
|
||||||
_id = SimpleFieldAlias("id")
|
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
UniqueConstraint('collection', 'media_entry'),
|
UniqueConstraint('collection', 'media_entry'),
|
||||||
{})
|
{})
|
||||||
|
@ -75,9 +75,9 @@ def user_may_delete_media(controller):
|
|||||||
@wraps(controller)
|
@wraps(controller)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
uploader_id = request.db.MediaEntry.find_one(
|
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
|
if not (request.user.is_admin or
|
||||||
request.user._id == uploader_id):
|
request.user.id == uploader_id):
|
||||||
return exc.HTTPForbidden()
|
return exc.HTTPForbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kwargs)
|
return controller(request, *args, **kwargs)
|
||||||
@ -94,7 +94,7 @@ def user_may_alter_collection(controller):
|
|||||||
creator_id = request.db.User.find_one(
|
creator_id = request.db.User.find_one(
|
||||||
{'username': request.matchdict['user']}).id
|
{'username': request.matchdict['user']}).id
|
||||||
if not (request.user.is_admin or
|
if not (request.user.is_admin or
|
||||||
request.user._id == creator_id):
|
request.user.id == creator_id):
|
||||||
return exc.HTTPForbidden()
|
return exc.HTTPForbidden()
|
||||||
|
|
||||||
return controller(request, *args, **kwargs)
|
return controller(request, *args, **kwargs)
|
||||||
@ -134,15 +134,15 @@ def get_user_media_entry(controller):
|
|||||||
media = request.db.MediaEntry.find_one(
|
media = request.db.MediaEntry.find_one(
|
||||||
{'slug': request.matchdict['media'],
|
{'slug': request.matchdict['media'],
|
||||||
'state': u'processed',
|
'state': u'processed',
|
||||||
'uploader': user._id})
|
'uploader': user.id})
|
||||||
|
|
||||||
# no media via slug? Grab it via ObjectId
|
# no media via slug? Grab it via ObjectId
|
||||||
if not media:
|
if not media:
|
||||||
try:
|
try:
|
||||||
media = request.db.MediaEntry.find_one(
|
media = request.db.MediaEntry.find_one(
|
||||||
{'_id': ObjectId(request.matchdict['media']),
|
{'id': ObjectId(request.matchdict['media']),
|
||||||
'state': u'processed',
|
'state': u'processed',
|
||||||
'uploader': user._id})
|
'uploader': user.id})
|
||||||
except InvalidId:
|
except InvalidId:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ def get_user_collection(controller):
|
|||||||
|
|
||||||
collection = request.db.Collection.find_one(
|
collection = request.db.Collection.find_one(
|
||||||
{'slug': request.matchdict['collection'],
|
{'slug': request.matchdict['collection'],
|
||||||
'creator': user._id})
|
'creator': user.id})
|
||||||
|
|
||||||
# Still no collection? Okay, 404.
|
# Still no collection? Okay, 404.
|
||||||
if not collection:
|
if not collection:
|
||||||
@ -194,10 +194,10 @@ def get_user_collection_item(controller):
|
|||||||
|
|
||||||
collection = request.db.Collection.find_one(
|
collection = request.db.Collection.find_one(
|
||||||
{'slug': request.matchdict['collection'],
|
{'slug': request.matchdict['collection'],
|
||||||
'creator': user._id})
|
'creator': user.id})
|
||||||
|
|
||||||
collection_item = request.db.CollectionItem.find_one(
|
collection_item = request.db.CollectionItem.find_one(
|
||||||
{'_id': request.matchdict['collection_item'] })
|
{'id': request.matchdict['collection_item'] })
|
||||||
|
|
||||||
# Still no collection item? Okay, 404.
|
# Still no collection item? Okay, 404.
|
||||||
if not collection_item:
|
if not collection_item:
|
||||||
@ -216,7 +216,7 @@ def get_media_entry_by_id(controller):
|
|||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
media = request.db.MediaEntry.find_one(
|
media = request.db.MediaEntry.find_one(
|
||||||
{'_id': ObjectId(request.matchdict['media']),
|
{'id': ObjectId(request.matchdict['media']),
|
||||||
'state': u'processed'})
|
'state': u'processed'})
|
||||||
except InvalidId:
|
except InvalidId:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
def may_edit_media(request, media):
|
def may_edit_media(request, media):
|
||||||
"""Check, if the request's user may edit the media details"""
|
"""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
|
return True
|
||||||
if request.user.is_admin:
|
if request.user.is_admin:
|
||||||
return True
|
return True
|
||||||
|
@ -79,7 +79,7 @@ def edit_media(request, media):
|
|||||||
location=media.url_for_self(request.urlgen))
|
location=media.url_for_self(request.urlgen))
|
||||||
|
|
||||||
if request.user.is_admin \
|
if request.user.is_admin \
|
||||||
and media.uploader != request.user._id \
|
and media.uploader != request.user.id \
|
||||||
and request.method != 'POST':
|
and request.method != 'POST':
|
||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.WARNING,
|
request, messages.WARNING,
|
||||||
@ -130,7 +130,7 @@ def edit_attachments(request, media):
|
|||||||
|
|
||||||
attachment_public_filepath \
|
attachment_public_filepath \
|
||||||
= mg_globals.public_store.get_unique_filepath(
|
= mg_globals.public_store.get_unique_filepath(
|
||||||
['media_entries', unicode(media._id), 'attachment',
|
['media_entries', unicode(media.id), 'attachment',
|
||||||
public_filename])
|
public_filename])
|
||||||
|
|
||||||
attachment_public_file = mg_globals.public_store.get_file(
|
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
|
# Make sure there isn't already a Collection with this title
|
||||||
existing_collection = request.db.Collection.find_one({
|
existing_collection = request.db.Collection.find_one({
|
||||||
'creator': request.user._id,
|
'creator': request.user.id,
|
||||||
'title':request.form['title']})
|
'title':request.form['title']})
|
||||||
|
|
||||||
if existing_collection and existing_collection.id != collection.id:
|
if existing_collection and existing_collection.id != collection.id:
|
||||||
@ -301,7 +301,7 @@ def edit_collection(request, collection):
|
|||||||
collection=collection.slug)
|
collection=collection.slug)
|
||||||
|
|
||||||
if request.user.is_admin \
|
if request.user.is_admin \
|
||||||
and collection.creator != request.user._id \
|
and collection.creator != request.user.id \
|
||||||
and request.method != 'POST':
|
and request.method != 'POST':
|
||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.WARNING,
|
request, messages.WARNING,
|
||||||
|
@ -108,7 +108,7 @@ def post_entry(request):
|
|||||||
process_media = registry.tasks[ProcessMedia.name]
|
process_media = registry.tasks[ProcessMedia.name]
|
||||||
try:
|
try:
|
||||||
process_media.apply_async(
|
process_media.apply_async(
|
||||||
[unicode(entry._id)], {},
|
[unicode(entry.id)], {},
|
||||||
task_id=task_id)
|
task_id=task_id)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
# The purpose of this section is because when running in "lazy"
|
# 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
|
# ... not completely the diaper pattern because the
|
||||||
# exception is re-raised :)
|
# exception is re-raised :)
|
||||||
mark_entry_failed(entry._id, e)
|
mark_entry_failed(entry.id, e)
|
||||||
# re-raise the exception
|
# re-raise the exception
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class ProgressCallback(object):
|
|||||||
def create_pub_filepath(entry, filename):
|
def create_pub_filepath(entry, filename):
|
||||||
return mgg.public_store.get_unique_filepath(
|
return mgg.public_store.get_unique_filepath(
|
||||||
['media_entries',
|
['media_entries',
|
||||||
unicode(entry._id),
|
unicode(entry.id),
|
||||||
filename])
|
filename])
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def mark_entry_failed(entry_id, exc):
|
|||||||
# Looks like yes, so record information about that failure and any
|
# Looks like yes, so record information about that failure and any
|
||||||
# metadata the user might have supplied.
|
# metadata the user might have supplied.
|
||||||
atomic_update(mgg.database.MediaEntry,
|
atomic_update(mgg.database.MediaEntry,
|
||||||
{'_id': entry_id},
|
{'id': entry_id},
|
||||||
{u'state': u'failed',
|
{u'state': u'failed',
|
||||||
u'fail_error': unicode(exc.exception_path),
|
u'fail_error': unicode(exc.exception_path),
|
||||||
u'fail_metadata': exc.metadata})
|
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
|
# metadata (in fact overwrite it if somehow it had previous info
|
||||||
# here)
|
# here)
|
||||||
atomic_update(mgg.database.MediaEntry,
|
atomic_update(mgg.database.MediaEntry,
|
||||||
{'_id': entry_id},
|
{'id': entry_id},
|
||||||
{u'state': u'failed',
|
{u'state': u'failed',
|
||||||
u'fail_error': None,
|
u'fail_error': None,
|
||||||
u'fail_metadata': {}})
|
u'fail_metadata': {}})
|
||||||
|
@ -42,7 +42,7 @@ class ProcessMedia(Task):
|
|||||||
(for now just process_image...)
|
(for now just process_image...)
|
||||||
"""
|
"""
|
||||||
entry = mgg.database.MediaEntry.one(
|
entry = mgg.database.MediaEntry.one(
|
||||||
{'_id': ObjectId(media_id)})
|
{'id': ObjectId(media_id)})
|
||||||
|
|
||||||
# Try to process, and handle expected errors.
|
# Try to process, and handle expected errors.
|
||||||
try:
|
try:
|
||||||
@ -61,7 +61,7 @@ class ProcessMedia(Task):
|
|||||||
|
|
||||||
json_processing_callback(entry)
|
json_processing_callback(entry)
|
||||||
except BaseProcessingFail as exc:
|
except BaseProcessingFail as exc:
|
||||||
mark_entry_failed(entry._id, exc)
|
mark_entry_failed(entry.id, exc)
|
||||||
json_processing_callback(entry)
|
json_processing_callback(entry)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ProcessMedia(Task):
|
|||||||
entry.title,
|
entry.title,
|
||||||
exc))
|
exc))
|
||||||
|
|
||||||
mark_entry_failed(entry._id, exc)
|
mark_entry_failed(entry.id, exc)
|
||||||
json_processing_callback(entry)
|
json_processing_callback(entry)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@ -80,7 +80,7 @@ class ProcessMedia(Task):
|
|||||||
+ ' processing {0}'.format(
|
+ ' processing {0}'.format(
|
||||||
entry))
|
entry))
|
||||||
|
|
||||||
mark_entry_failed(entry._id, exc)
|
mark_entry_failed(entry.id, exc)
|
||||||
json_processing_callback(entry)
|
json_processing_callback(entry)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ def submit_start(request):
|
|||||||
|
|
||||||
entry.license = unicode(request.form.get('license', "")) or None
|
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"
|
# Process the user's folksonomy "tags"
|
||||||
entry.tags = convert_to_tag_list_of_dicts(
|
entry.tags = convert_to_tag_list_of_dicts(
|
||||||
@ -121,7 +121,7 @@ def submit_start(request):
|
|||||||
process_media = registry.tasks[ProcessMedia.name]
|
process_media = registry.tasks[ProcessMedia.name]
|
||||||
try:
|
try:
|
||||||
process_media.apply_async(
|
process_media.apply_async(
|
||||||
[unicode(entry._id)], {},
|
[unicode(entry.id)], {},
|
||||||
task_id=task_id)
|
task_id=task_id)
|
||||||
except BaseException as exc:
|
except BaseException as exc:
|
||||||
# The purpose of this section is because when running in "lazy"
|
# 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
|
# ... not completely the diaper pattern because the
|
||||||
# exception is re-raised :)
|
# exception is re-raised :)
|
||||||
mark_entry_failed(entry._id, exc)
|
mark_entry_failed(entry.id, exc)
|
||||||
# re-raise the exception
|
# re-raise the exception
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -198,12 +198,12 @@ def add_collection(request, media=None):
|
|||||||
collection.title = unicode(request.form['title'])
|
collection.title = unicode(request.form['title'])
|
||||||
|
|
||||||
collection.description = unicode(request.form.get('description'))
|
collection.description = unicode(request.form.get('description'))
|
||||||
collection.creator = request.user._id
|
collection.creator = request.user.id
|
||||||
collection.generate_slug()
|
collection.generate_slug()
|
||||||
|
|
||||||
# Make sure this user isn't duplicating an existing collection
|
# Make sure this user isn't duplicating an existing collection
|
||||||
existing_collection = request.db.Collection.find_one({
|
existing_collection = request.db.Collection.find_one({
|
||||||
'creator': request.user._id,
|
'creator': request.user.id,
|
||||||
'title':collection.title})
|
'title':collection.title})
|
||||||
|
|
||||||
if existing_collection:
|
if existing_collection:
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for media_entry in processing_entries %}
|
{% for media_entry in processing_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ media_entry._id }}</td>
|
<td>{{ media_entry.id }}</td>
|
||||||
<td>{{ media_entry.get_uploader.username }}</td>
|
<td>{{ media_entry.get_uploader.username }}</td>
|
||||||
<td>{{ media_entry.title }}</td>
|
<td>{{ media_entry.title }}</td>
|
||||||
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for media_entry in failed_entries %}
|
{% for media_entry in failed_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ media_entry._id }}</td>
|
<td>{{ media_entry.id }}</td>
|
||||||
<td>{{ media_entry.get_uploader.username }}</td>
|
<td>{{ media_entry.get_uploader.username }}</td>
|
||||||
<td>{{ media_entry.title }}</td>
|
<td>{{ media_entry.title }}</td>
|
||||||
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
||||||
@ -101,7 +101,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for media_entry in processed_entries %}
|
{% for media_entry in processed_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ media_entry._id }}</td>
|
<td>{{ media_entry.id }}</td>
|
||||||
<td>{{ media_entry.get_uploader.username }}</td>
|
<td>{{ media_entry.get_uploader.username }}</td>
|
||||||
<td><a href="{{ media_entry.url_for_self(request.urlgen) }}">{{ media_entry.title }}</a></td>
|
<td><a href="{{ media_entry.url_for_self(request.urlgen) }}">{{ media_entry.title }}</a></td>
|
||||||
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
{% block mediagoblin_content %}
|
{% block mediagoblin_content %}
|
||||||
<form action="{{ request.urlgen('mediagoblin.edit.attachments',
|
<form action="{{ request.urlgen('mediagoblin.edit.attachments',
|
||||||
user= media.get_uploader.username,
|
user= media.get_uploader.username,
|
||||||
media= media._id) }}"
|
media= media.id) }}"
|
||||||
method="POST" enctype="multipart/form-data">
|
method="POST" enctype="multipart/form-data">
|
||||||
<div class="form_box">
|
<div class="form_box">
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
<form action="{{ request.urlgen('mediagoblin.edit.edit_media',
|
<form action="{{ request.urlgen('mediagoblin.edit.edit_media',
|
||||||
user= media.get_uploader.username,
|
user= media.get_uploader.username,
|
||||||
media= media._id) }}"
|
media= media.id) }}"
|
||||||
method="POST" enctype="multipart/form-data">
|
method="POST" enctype="multipart/form-data">
|
||||||
<div class="form_box_xl edit_box">
|
<div class="form_box_xl edit_box">
|
||||||
<h1>{% trans media_title=media.title %}Editing {{ media_title }}{% endtrans %}</h1>
|
<h1>{% trans media_title=media.title %}Editing {{ media_title }}{% endtrans %}</h1>
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
{{ collection_title }} by <a href="{{ user_url }}">{{ username }}</a>
|
{{ collection_title }} by <a href="{{ user_url }}">{{ username }}</a>
|
||||||
{%- endtrans %}
|
{%- endtrans %}
|
||||||
</h1>
|
</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) %}
|
request.user.is_admin) %}
|
||||||
{% set edit_url = request.urlgen('mediagoblin.edit.edit_collection',
|
{% set edit_url = request.urlgen('mediagoblin.edit.edit_collection',
|
||||||
user=collection.get_creator.username,
|
user=collection.get_creator.username,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
<form action="{{ request.urlgen('mediagoblin.user_pages.collection_item_confirm_remove',
|
<form action="{{ request.urlgen('mediagoblin.user_pages.collection_item_confirm_remove',
|
||||||
user=collection_item.in_collection.get_creator.username,
|
user=collection_item.in_collection.get_creator.username,
|
||||||
collection=collection_item.in_collection.slug,
|
collection=collection_item.in_collection.slug,
|
||||||
collection_item=collection_item._id) }}"
|
collection_item=collection_item.id) }}"
|
||||||
method="POST" enctype="multipart/form-data">
|
method="POST" enctype="multipart/form-data">
|
||||||
<div class="form_box">
|
<div class="form_box">
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -79,15 +79,15 @@
|
|||||||
{{ media.title }}
|
{{ media.title }}
|
||||||
</h2>
|
</h2>
|
||||||
{% if request.user and
|
{% if request.user and
|
||||||
(media.uploader == request.user._id or
|
(media.uploader == request.user.id or
|
||||||
request.user.is_admin) %}
|
request.user.is_admin) %}
|
||||||
{% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
|
{% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
|
||||||
user= media.get_uploader.username,
|
user= media.get_uploader.username,
|
||||||
media= media._id) %}
|
media= media.id) %}
|
||||||
<a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
|
<a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
|
||||||
{% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
|
{% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
|
||||||
user= media.get_uploader.username,
|
user= media.get_uploader.username,
|
||||||
media= media._id) %}
|
media= media.id) %}
|
||||||
<a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
|
<a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% autoescape False %}
|
{% autoescape False %}
|
||||||
@ -104,7 +104,7 @@
|
|||||||
{% if request.user %}
|
{% if request.user %}
|
||||||
<form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment',
|
<form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment',
|
||||||
user= media.get_uploader.username,
|
user= media.get_uploader.username,
|
||||||
media=media._id) }}" method="POST" id="form_comment">
|
media=media.id) }}" method="POST" id="form_comment">
|
||||||
<p>
|
<p>
|
||||||
{% trans %}You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %}
|
{% trans %}You can use <a href="http://daringfireball.net/projects/markdown/basics">Markdown</a> for formatting.{% endtrans %}
|
||||||
</p>
|
</p>
|
||||||
@ -117,11 +117,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% for comment in comments %}
|
{% for comment in comments %}
|
||||||
{% set comment_author = comment.get_author %}
|
{% set comment_author = comment.get_author %}
|
||||||
{% if pagination.active_id == comment._id %}
|
{% if pagination.active_id == comment.id %}
|
||||||
<div class="comment_wrapper comment_active" id="comment-{{ comment._id }}">
|
<div class="comment_wrapper comment_active" id="comment-{{ comment.id }}">
|
||||||
<a name="comment" id="comment"></a>
|
<a name="comment" id="comment"></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="comment_wrapper" id="comment-{{ comment._id }}">
|
<div class="comment_wrapper" id="comment-{{ comment.id }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="comment_author">
|
<div class="comment_author">
|
||||||
<img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
|
<img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
|
||||||
@ -131,7 +131,7 @@
|
|||||||
</a>
|
</a>
|
||||||
{% trans %}at{% endtrans %}
|
{% trans %}at{% endtrans %}
|
||||||
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
|
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
|
||||||
comment = comment._id,
|
comment = comment.id,
|
||||||
user = media.get_uploader.username,
|
user = media.get_uploader.username,
|
||||||
media = media.slug_or_id) }}#comment">
|
media = media.slug_or_id) }}#comment">
|
||||||
{{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
|
{{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
|
||||||
@ -181,7 +181,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if app_config['allow_attachments']
|
{% if app_config['allow_attachments']
|
||||||
and request.user
|
and request.user
|
||||||
and (media.uploader == request.user._id
|
and (media.uploader == request.user.id
|
||||||
or request.user.is_admin) %}
|
or request.user.is_admin) %}
|
||||||
{% if not media.attachment_files|count %}
|
{% if not media.attachment_files|count %}
|
||||||
<h3>{% trans %}Attachments{% endtrans %}</h3>
|
<h3>{% trans %}Attachments{% endtrans %}</h3>
|
||||||
@ -189,7 +189,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<a href="{{ request.urlgen('mediagoblin.edit.attachments',
|
<a href="{{ request.urlgen('mediagoblin.edit.attachments',
|
||||||
user=media.get_uploader.username,
|
user=media.get_uploader.username,
|
||||||
media=media._id) }}">{% trans %}Add attachment{% endtrans %}</a>
|
media=media.id) }}">{% trans %}Add attachment{% endtrans %}</a>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<a type="submit" href="{{ request.urlgen('mediagoblin.user_pages.media_collect',
|
<a type="submit" href="{{ request.urlgen('mediagoblin.user_pages.media_collect',
|
||||||
user=media.get_uploader.username,
|
user=media.get_uploader.username,
|
||||||
media=media._id) }}"
|
media=media.id) }}"
|
||||||
class="button_action"
|
class="button_action"
|
||||||
title="{% trans %}Add media to collection{% endtrans %}">
|
title="{% trans %}Add media to collection{% endtrans %}">
|
||||||
<img src="{{ request.staticdirect('/images/icon_collect.png') }}"
|
<img src="{{ request.staticdirect('/images/icon_collect.png') }}"
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<form action="{{ request.urlgen('mediagoblin.user_pages.media_collect',
|
<form action="{{ request.urlgen('mediagoblin.user_pages.media_collect',
|
||||||
user=media.get_uploader.username,
|
user=media.get_uploader.username,
|
||||||
media=media._id) }}"
|
media=media.id) }}"
|
||||||
method="POST" enctype="multipart/form-data">
|
method="POST" enctype="multipart/form-data">
|
||||||
<div class="form_box">
|
<div class="form_box">
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<form action="{{ request.urlgen('mediagoblin.user_pages.media_confirm_delete',
|
<form action="{{ request.urlgen('mediagoblin.user_pages.media_confirm_delete',
|
||||||
user=media.get_uploader.username,
|
user=media.get_uploader.username,
|
||||||
media=media._id) }}"
|
media=media.id) }}"
|
||||||
method="POST" enctype="multipart/form-data">
|
method="POST" enctype="multipart/form-data">
|
||||||
<div class="form_box">
|
<div class="form_box">
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for media_entry in processing_entries %}
|
{% for media_entry in processing_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ media_entry._id }}</td>
|
<td>{{ media_entry.id }}</td>
|
||||||
<td>{{ media_entry.title }}</td>
|
<td>{{ media_entry.title }}</td>
|
||||||
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
||||||
{% if media_entry.transcoding_progress %}
|
{% if media_entry.transcoding_progress %}
|
||||||
@ -69,7 +69,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for media_entry in failed_entries %}
|
{% for media_entry in failed_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ media_entry._id }}</td>
|
<td>{{ media_entry.id }}</td>
|
||||||
<td>{{ media_entry.title }}</td>
|
<td>{{ media_entry.title }}</td>
|
||||||
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
<td>{{ media_entry.created.strftime("%F %R") }}</td>
|
||||||
{% if media_entry.get_fail_exception() %}
|
{% if media_entry.get_fail_exception() %}
|
||||||
@ -97,7 +97,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for entry in processed_entries %}
|
{% for entry in processed_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ entry._id }}</td>
|
<td>{{ entry.id }}</td>
|
||||||
<td><a href="{{ entry.url_for_self(request.urlgen) }}">{{ entry.title }}</a></td>
|
<td><a href="{{ entry.url_for_self(request.urlgen) }}">{{ entry.title }}</a></td>
|
||||||
<td>{{ entry.created.strftime("%F %R") }}</td>
|
<td>{{ entry.created.strftime("%F %R") }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{% if not user.url and not user.bio %}
|
{% 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">
|
<div class="profile_sidebar empty_space">
|
||||||
<p>
|
<p>
|
||||||
{% trans %}Here's a spot to tell others about yourself.{% endtrans %}
|
{% trans %}Here's a spot to tell others about yourself.{% endtrans %}
|
||||||
@ -112,7 +112,7 @@
|
|||||||
<div class="profile_sidebar">
|
<div class="profile_sidebar">
|
||||||
{% include "mediagoblin/utils/profile.html" %}
|
{% include "mediagoblin/utils/profile.html" %}
|
||||||
{% if request.user and
|
{% 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={{
|
<a href="{{ request.urlgen('mediagoblin.edit.profile') }}?username={{
|
||||||
user.username }}">
|
user.username }}">
|
||||||
{%- trans %}Edit profile{% endtrans -%}
|
{%- trans %}Edit profile{% endtrans -%}
|
||||||
@ -139,7 +139,7 @@
|
|||||||
{% include "mediagoblin/utils/feed_link.html" %}
|
{% include "mediagoblin/utils/feed_link.html" %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% 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">
|
<div class="profile_showcase empty_space">
|
||||||
<p>
|
<p>
|
||||||
{% trans -%}
|
{% trans -%}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
<a href="{{ entry_url }}">{{ item.note }}</a>
|
<a href="{{ entry_url }}">{{ item.note }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if request.user and
|
{% if request.user and
|
||||||
(item.in_collection.creator == request.user._id or
|
(item.in_collection.creator == request.user.id or
|
||||||
request.user.is_admin) %}
|
request.user.is_admin) %}
|
||||||
{%- set remove_url=request.urlgen(
|
{%- set remove_url=request.urlgen(
|
||||||
'mediagoblin.user_pages.collection_item_confirm_remove',
|
'mediagoblin.user_pages.collection_item_confirm_remove',
|
||||||
|
@ -154,7 +154,7 @@ def test_register_views(test_app):
|
|||||||
## Make sure user is logged in
|
## Make sure user is logged in
|
||||||
request = template.TEMPLATE_TEST_CONTEXT[
|
request = template.TEMPLATE_TEST_CONTEXT[
|
||||||
'mediagoblin/user_pages/user.html']['request']
|
'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
|
## Make sure we get email confirmation, and try verifying
|
||||||
assert len(mail.EMAIL_TEST_INBOX) == 1
|
assert len(mail.EMAIL_TEST_INBOX) == 1
|
||||||
@ -171,7 +171,7 @@ def test_register_views(test_app):
|
|||||||
|
|
||||||
### user should have these same parameters
|
### user should have these same parameters
|
||||||
assert parsed_get_params['userid'] == [
|
assert parsed_get_params['userid'] == [
|
||||||
unicode(new_user._id)]
|
unicode(new_user.id)]
|
||||||
assert parsed_get_params['token'] == [
|
assert parsed_get_params['token'] == [
|
||||||
new_user.verification_key]
|
new_user.verification_key]
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ def test_register_views(test_app):
|
|||||||
template.clear_test_template_context()
|
template.clear_test_template_context()
|
||||||
response = test_app.get(
|
response = test_app.get(
|
||||||
"/auth/verify_email/?userid=%s&token=total_bs" % unicode(
|
"/auth/verify_email/?userid=%s&token=total_bs" % unicode(
|
||||||
new_user._id))
|
new_user.id))
|
||||||
response.follow()
|
response.follow()
|
||||||
context = template.TEMPLATE_TEST_CONTEXT[
|
context = template.TEMPLATE_TEST_CONTEXT[
|
||||||
'mediagoblin/user_pages/user.html']
|
'mediagoblin/user_pages/user.html']
|
||||||
@ -254,7 +254,7 @@ def test_register_views(test_app):
|
|||||||
|
|
||||||
# user should have matching parameters
|
# user should have matching parameters
|
||||||
new_user = mg_globals.database.User.find_one({'username': u'happygirl'})
|
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]
|
assert parsed_get_params['token'] == [new_user.fp_verification_key]
|
||||||
|
|
||||||
### The forgotten password token should be set to expire in ~ 10 days
|
### 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()
|
template.clear_test_template_context()
|
||||||
response = test_app.get(
|
response = test_app.get(
|
||||||
"/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode(
|
"/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')
|
assert_equal(response.status, '404 Not Found')
|
||||||
|
|
||||||
## Try using an expired token to change password, shouldn't work
|
## 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
|
# Make sure user is in the session
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
||||||
session = context['request'].session
|
session = context['request'].session
|
||||||
assert session['user_id'] == unicode(test_user._id)
|
assert session['user_id'] == unicode(test_user.id)
|
||||||
|
|
||||||
# Successful logout
|
# Successful logout
|
||||||
# -----------------
|
# -----------------
|
||||||
|
@ -184,7 +184,7 @@ class TestSubmission:
|
|||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT,
|
response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT,
|
||||||
do_follow=True, url=delete_url)
|
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)
|
self.check_comments(request, media_id, 0)
|
||||||
|
|
||||||
def test_evil_file(self):
|
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.
|
Assert a database contains the things we expect it to.
|
||||||
|
|
||||||
Objects are found via '_id', so you should make sure your document
|
Objects are found via 'id', so you should make sure your document
|
||||||
has an _id.
|
has an id.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
- db: pymongo or mongokit database connection
|
- db: pymongo or mongokit database connection
|
||||||
- expected: the data we expect. Formatted like:
|
- expected: the data we expect. Formatted like:
|
||||||
{'collection_name': [
|
{'collection_name': [
|
||||||
{'_id': 'foo',
|
{'id': 'foo',
|
||||||
'some_field': 'some_value'},]}
|
'some_field': 'some_value'},]}
|
||||||
"""
|
"""
|
||||||
for collection_name, collection_data in expected.iteritems():
|
for collection_name, collection_data in expected.iteritems():
|
||||||
collection = db[collection_name]
|
collection = db[collection_name]
|
||||||
for expected_document in collection_data:
|
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 is not None # make sure it exists
|
||||||
assert document == expected_document # make sure it matches
|
assert document == expected_document # make sure it matches
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class Pagination(object):
|
|||||||
- per_page: number of objects per page
|
- per_page: number of objects per page
|
||||||
- cursor: db cursor
|
- cursor: db cursor
|
||||||
- jump_to_id: ObjectId, sets the page to the page containing the
|
- 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.page = page
|
||||||
self.per_page = per_page
|
self.per_page = per_page
|
||||||
@ -53,7 +53,7 @@ class Pagination(object):
|
|||||||
cursor = copy.copy(self.cursor)
|
cursor = copy.copy(self.cursor)
|
||||||
|
|
||||||
for (doc, increment) in izip(cursor, count(0)):
|
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.page = 1 + int(floor(increment / self.per_page))
|
||||||
|
|
||||||
self.active_id = jump_to_id
|
self.active_id = jump_to_id
|
||||||
|
@ -34,7 +34,7 @@ def setup_user_in_request(request):
|
|||||||
except InvalidId:
|
except InvalidId:
|
||||||
user = None
|
user = None
|
||||||
else:
|
else:
|
||||||
user = request.db.User.find_one({'_id': oid})
|
user = request.db.User.find_one({'id': oid})
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
# Something's wrong... this user doesn't exist? Invalidate
|
# 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(
|
comment_url = request.urlgen(
|
||||||
'mediagoblin.user_pages.media_home.view_comment',
|
'mediagoblin.user_pages.media_home.view_comment',
|
||||||
comment=comment._id,
|
comment=comment.id,
|
||||||
user=media.get_uploader.username,
|
user=media.get_uploader.username,
|
||||||
media=media.slug_or_id,
|
media=media.slug_or_id,
|
||||||
qualified=True) + '#comment'
|
qualified=True) + '#comment'
|
||||||
|
@ -53,7 +53,7 @@ def user_home(request, page):
|
|||||||
{'user': user})
|
{'user': user})
|
||||||
|
|
||||||
cursor = request.db.MediaEntry.find(
|
cursor = request.db.MediaEntry.find(
|
||||||
{'uploader': user._id,
|
{'uploader': user.id,
|
||||||
'state': u'processed'}).sort('created', DESCENDING)
|
'state': u'processed'}).sort('created', DESCENDING)
|
||||||
|
|
||||||
pagination = Pagination(page, cursor)
|
pagination = Pagination(page, cursor)
|
||||||
@ -196,12 +196,12 @@ def media_collect(request, media):
|
|||||||
|
|
||||||
collection.description = unicode(
|
collection.description = unicode(
|
||||||
request.form.get('collection_description'))
|
request.form.get('collection_description'))
|
||||||
collection.creator = request.user._id
|
collection.creator = request.user.id
|
||||||
collection.generate_slug()
|
collection.generate_slug()
|
||||||
|
|
||||||
# Make sure this user isn't duplicating an existing collection
|
# Make sure this user isn't duplicating an existing collection
|
||||||
existing_collection = request.db.Collection.find_one({
|
existing_collection = request.db.Collection.find_one({
|
||||||
'creator': request.user._id,
|
'creator': request.user.id,
|
||||||
'title': collection.title})
|
'title': collection.title})
|
||||||
|
|
||||||
if existing_collection:
|
if existing_collection:
|
||||||
@ -220,7 +220,7 @@ def media_collect(request, media):
|
|||||||
# Otherwise, use the collection selected from the drop-down
|
# Otherwise, use the collection selected from the drop-down
|
||||||
else:
|
else:
|
||||||
collection = request.db.Collection.find_one({
|
collection = request.db.Collection.find_one({
|
||||||
'_id': request.form.get('collection')})
|
'id': request.form.get('collection')})
|
||||||
collection_item.collection = collection.id
|
collection_item.collection = collection.id
|
||||||
|
|
||||||
# Make sure the user actually selected a collection
|
# 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))
|
location=media.url_for_self(request.urlgen))
|
||||||
|
|
||||||
if ((request.user.is_admin and
|
if ((request.user.is_admin and
|
||||||
request.user._id != media.uploader)):
|
request.user.id != media.uploader)):
|
||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.WARNING,
|
request, messages.WARNING,
|
||||||
_("You are about to delete another user's media. "
|
_("You are about to delete another user's media. "
|
||||||
@ -378,7 +378,7 @@ def collection_item_confirm_remove(request, collection_item):
|
|||||||
collection=collection.slug)
|
collection=collection.slug)
|
||||||
|
|
||||||
if ((request.user.is_admin and
|
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(
|
messages.add_message(
|
||||||
request, messages.WARNING,
|
request, messages.WARNING,
|
||||||
_("You are about to delete an item from another user's collection. "
|
_("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)
|
collection=collection.slug)
|
||||||
|
|
||||||
if ((request.user.is_admin and
|
if ((request.user.is_admin and
|
||||||
request.user._id != collection.creator)):
|
request.user.id != collection.creator)):
|
||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.WARNING,
|
request, messages.WARNING,
|
||||||
_("You are about to delete another user's collection. "
|
_("You are about to delete another user's collection. "
|
||||||
@ -456,7 +456,7 @@ def atom_feed(request):
|
|||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
|
||||||
cursor = request.db.MediaEntry.find({
|
cursor = request.db.MediaEntry.find({
|
||||||
'uploader': user._id,
|
'uploader': user.id,
|
||||||
'state': u'processed'}) \
|
'state': u'processed'}) \
|
||||||
.sort('created', DESCENDING) \
|
.sort('created', DESCENDING) \
|
||||||
.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
||||||
@ -524,7 +524,7 @@ def collection_atom_feed(request):
|
|||||||
'slug': request.matchdict['collection']})
|
'slug': request.matchdict['collection']})
|
||||||
|
|
||||||
cursor = request.db.CollectionItem.find({
|
cursor = request.db.CollectionItem.find({
|
||||||
'collection': collection._id}) \
|
'collection': collection.id}) \
|
||||||
.sort('added', DESCENDING) \
|
.sort('added', DESCENDING) \
|
||||||
.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
|
.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
|
# Make sure we have permission to access this user's panel. Only
|
||||||
# admins and this user herself should be able to do so.
|
# 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):
|
or request.user.is_admin):
|
||||||
# No? Let's simply redirect to this user's homepage then.
|
# No? Let's simply redirect to this user's homepage then.
|
||||||
return redirect(
|
return redirect(
|
||||||
@ -610,16 +610,16 @@ def processing_panel(request):
|
|||||||
|
|
||||||
# Get media entries which are in-processing
|
# Get media entries which are in-processing
|
||||||
processing_entries = request.db.MediaEntry.find(
|
processing_entries = request.db.MediaEntry.find(
|
||||||
{'uploader': user._id,
|
{'uploader': user.id,
|
||||||
'state': u'processing'}).sort('created', DESCENDING)
|
'state': u'processing'}).sort('created', DESCENDING)
|
||||||
|
|
||||||
# Get media entries which have failed to process
|
# Get media entries which have failed to process
|
||||||
failed_entries = request.db.MediaEntry.find(
|
failed_entries = request.db.MediaEntry.find(
|
||||||
{'uploader': user._id,
|
{'uploader': user.id,
|
||||||
'state': u'failed'}).sort('created', DESCENDING)
|
'state': u'failed'}).sort('created', DESCENDING)
|
||||||
|
|
||||||
processed_entries = request.db.MediaEntry.find(
|
processed_entries = request.db.MediaEntry.find(
|
||||||
{'uploader': user._id,
|
{'uploader': user.id,
|
||||||
'state': u'processed'}).sort('created', DESCENDING).limit(10)
|
'state': u'processed'}).sort('created', DESCENDING).limit(10)
|
||||||
|
|
||||||
# Render to response
|
# Render to response
|
||||||
|
Loading…
x
Reference in New Issue
Block a user