Create function to search media by slug.
Searching media by slug is easy on mongo. But doing the joins in sqlalchemy is not as nice. So created a function for doing it. Well, and create the same function for mongo, so that it also works.
This commit is contained in:
@@ -310,3 +310,9 @@ def check_media_slug_used(db, uploader_id, slug, ignore_m_id):
|
||||
existing_user_slug_entries = db.MediaEntry.find(
|
||||
query_dict).count()
|
||||
return existing_user_slug_entries
|
||||
|
||||
|
||||
def media_entries_for_tag_slug(db, tag_slug):
|
||||
return db.MediaEntry.find(
|
||||
{u'state': u'processed',
|
||||
u'tags.slug': tag_slug})
|
||||
|
||||
@@ -294,6 +294,15 @@ def check_media_slug_used(dummy_db, uploader_id, slug, ignore_m_id):
|
||||
return does_exist
|
||||
|
||||
|
||||
def media_entries_for_tag_slug(dummy_db, tag_slug):
|
||||
return MediaEntry.query \
|
||||
.join(MediaEntry.tags_helper) \
|
||||
.join(MediaTag.tag_helper) \
|
||||
.filter(
|
||||
(MediaEntry.state == u'processed')
|
||||
& (Tag.slug == tag_slug))
|
||||
|
||||
|
||||
def clean_orphan_tags():
|
||||
q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
|
||||
for t in q1:
|
||||
|
||||
@@ -21,7 +21,9 @@ except ImportError:
|
||||
|
||||
if use_sql:
|
||||
from mediagoblin.db.sql.fake import ObjectId, InvalidId, DESCENDING
|
||||
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used
|
||||
from mediagoblin.db.sql.util import atomic_update, check_media_slug_used, \
|
||||
media_entries_for_tag_slug
|
||||
else:
|
||||
from mediagoblin.db.mongo.util import \
|
||||
ObjectId, InvalidId, DESCENDING, atomic_update, check_media_slug_used
|
||||
ObjectId, InvalidId, DESCENDING, atomic_update, \
|
||||
check_media_slug_used, media_entries_for_tag_slug
|
||||
|
||||
Reference in New Issue
Block a user