Added post_entry at /api/submit
[mediagoblin.git] / mediagoblin / listings / views.py
index ca8e8229788908746657359dd4f2f563f027984e..a8824390be5417760dda0a50717e9497326afe62 100644 (file)
@@ -1,5 +1,5 @@
 # GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors.  See AUTHORS.
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
@@ -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
@@ -29,11 +29,16 @@ def _get_tag_name_from_entries(media_entries, tag_slug):
     """
     # ... this is slightly hacky looking :\
     tag_name = tag_slug
-    if media_entries.count():
-        for tag in media_entries[0]['tags']:
+
+    for entry in media_entries:
+        for tag in entry.tags:
             if tag['slug'] == tag_slug:
-                tag_name == tag['name']
+                tag_name = tag['name']
                 break
+        break
+    # TODO: Remove after SQL-switch, it's mongo specific
+    if hasattr(media_entries, "rewind"):
+        media_entries.rewind()
 
     return tag_name
 
@@ -43,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)
@@ -71,9 +74,7 @@ def tag_atom_feed(request):
     """
     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)
     cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
 
@@ -91,7 +92,7 @@ def tag_atom_feed(request):
             'type': 'text/html'}])
     for entry in cursor:
         feed.add(entry.get('title'),
-            entry.get('description_html'),
+            entry.description_html,
             id=entry.url_for_self(request.urlgen,qualified=True),
             content_type='html',
             author={'name': entry.get_uploader.username,