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:
parent
d8409c26a0
commit
07163593ee
@ -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
|
||||
|
@ -14,7 +14,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from mediagoblin.db.util import DESCENDING
|
||||
from mediagoblin.db.util import media_entries_for_tag_slug, DESCENDING
|
||||
|
||||
from mediagoblin.tools.pagination import Pagination
|
||||
from mediagoblin.tools.response import render_to_response
|
||||
@ -48,9 +48,7 @@ def tag_listing(request, page):
|
||||
"""'Gallery'/listing for this tag slug"""
|
||||
tag_slug = request.matchdict[u'tag']
|
||||
|
||||
cursor = request.db.MediaEntry.find(
|
||||
{u'state': u'processed',
|
||||
u'tags.slug': tag_slug})
|
||||
cursor = media_entries_for_tag_slug(request.db, tag_slug)
|
||||
cursor = cursor.sort('created', DESCENDING)
|
||||
|
||||
pagination = Pagination(page, cursor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user