Anonymous avatar Anonymous committed 2629922

Added list by tag

Comments (0)

Files changed (5)

skypieamc/config/routing.py

 
     # CUSTOM ROUTES HERE
 
+    map.connect('tagged_files', '/file/list/{tagid}',
+                controller='file', action='list')
     map.connect('/{controller}/{action}')
     map.connect('/{controller}/{action}/{id}')
+    map.connect('root', '/', controller='file', action='list');
 
     return map

skypieamc/controllers/file.py

 from formencode.validators import FieldStorageUploadConverter, \
                                   FancyValidator, String
 from mimetypes import guess_type
-from sqlalchemy import desc
+from sqlalchemy import desc, and_
 from webhelpers import paginate
 
 from skypieamc import model
     def __before__(self):
         c.tags = meta.Session.query(model.Tag).all()
 
-    def list(self):
+    def list(self, tagid=None):
         files = meta.Session.query(model.File).\
             order_by(desc(model.File.uploaded))
+        if tagid:
+            files = files.filter(
+                and_(model.file_tag_table.c.fileid == model.File.id,
+                     model.file_tag_table.c.tagid == tagid)
+            )
         c.paginator = paginate.Page(
             files,
             page=request.params.get('page', 1),

skypieamc/public/css/list.css

   font-size: 85%;
 }
 
+#file-list td.file-info dd .tags{
+  display: inline;
+  background: url('/images/icon_tag_green-small.png') no-repeat left;
+}
+
+#file-list td.file-info dd .tags .text {
+  position: relative;
+  left: 16px;
+}
+
 #file-list td.file-info dd img {
   position: relative;
   top: 3px;

skypieamc/templates/base.mako

             %>
             ${h.link_to(
                 tag.name.encode('utf-8'),
-                h.url_for(controller='file', action='list'),
+                h.url_for('tagged_files', tagid=tag.id),
                 class_=font_size
               )}
           %endfor

skypieamc/templates/derived/file/list.mako

       Uploaded: ${mfile.uploaded.strftime('%Y/%m/%d')}
       | Size: ${h.readable_filesize(mfile.size)}
       | ${mfile.download_count} Downloads
+      %if len(mfile.tags) > 0:
+        <%
+          mfile.tags.sort(
+            lambda t1, t2: cmp(t1.file_count, t2.file_count),
+            reverse=True
+          )
+        %>
+        | <div class="tags"><span class="text">
+          %for tag in mfile.tags[:5]:
+            ${h.link_to(
+                tag.name.encode('utf-8'),
+                h.url_for('tagged_files', tagid=tag.id)
+              )}
+          %endfor
+        </span></div>
+      %endif
     </dd>
   </dl>
 </%def>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.