changeset 518:0398d1eb14c1

small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
author Akash Sinha <akash2607@gmail.com>
date Fri, 19 Aug 2011 02:26:23 +0530
parents e6f12800e78c
children 373b67e26138
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/templates/index.html
diffstat 3 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Thu Aug 18 23:26:13 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Fri Aug 19 02:26:23 2011 +0530
@@ -323,6 +323,7 @@
     audio_items = Boolean.using(label=L_('audio'), optional=True, default=1)
     video_items = Boolean.using(label=L_('video'), optional=True, default=1)
     other_items = Boolean.using(label=L_('other'), optional=True, default=1)
+    unknown_items = Boolean.using(label=L_('unknown'), optional=True, default=1)
     submit = String.using(default=L_('Filter'), optional=True)
 
 
--- a/MoinMoin/items/__init__.py	Thu Aug 18 23:26:13 2011 +0530
+++ b/MoinMoin/items/__init__.py	Fri Aug 19 02:26:23 2011 +0530
@@ -602,20 +602,35 @@
         else:
             selected_contenttypes = all_contenttypes
 
+        unknown_item_group = "unknown items"
         if startswith:
             startswith = (u'%s' % startswith, u'%s' % startswith.swapcase())
-            index = [(fullname, relname, contenttype)
-                     for fullname, relname, contenttype in index
-                     if u'/' not in relname
-                     and relname.startswith(startswith)
-                     and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
-                     # If an item's contenttype not present in the default contenttype list,
-                     # then it will be shown without going through any filter.
+            if not selected_groups or  unknown_item_group in selected_groups:
+                index = [(fullname, relname, contenttype)
+                         for fullname, relname, contenttype in index
+                         if u'/' not in relname
+                         and relname.startswith(startswith)
+                         and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
+                         # If an item's contenttype not present in the default contenttype list,
+                         # then it will be shown without going through any filter.
+            else:
+                index = [(fullname, relname, contenttype)
+                         for fullname, relname, contenttype in index
+                         if u'/' not in relname
+                         and relname.startswith(startswith)
+                         and (contenttype in selected_contenttypes)]
+
         else:
-            index = [(fullname, relname, contenttype)
-                     for fullname, relname, contenttype in index
-                     if u'/' not in relname
-                     and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
+            if not selected_groups or unknown_item_group in selected_groups:
+                index = [(fullname, relname, contenttype)
+                         for fullname, relname, contenttype in index
+                         if u'/' not in relname
+                         and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
+            else:
+                index = [(fullname, relname, contenttype)
+                         for fullname, relname, contenttype in index
+                         if u'/' not in relname
+                         and contenttype in selected_contenttypes]
 
         return index
 
--- a/MoinMoin/templates/index.html	Thu Aug 18 23:26:13 2011 +0530
+++ b/MoinMoin/templates/index.html	Fri Aug 19 02:26:23 2011 +0530
@@ -12,6 +12,7 @@
     <div class="moin-select-contenttypes">
         <div class="moin-contenttypes-wrapper">
             <div class="ct-hide">{{ _("Filter by content type") }}</div>
+            {% set unknown_items_label = _("items having unknown mime types") %}
             {{ gen.form.open(form, method="post", action=url_for('frontend.index', item_name=item_name)) }}
             <ul>
                 {{ forms.render_filter_field(gen, form['markup_text_items'], 'checkbox', contenttype_groups['markup text items']) }}
@@ -20,6 +21,7 @@
                 {{ forms.render_filter_field(gen, form['audio_items'], 'checkbox', contenttype_groups['audio items']) }}
                 {{ forms.render_filter_field(gen, form['video_items'], 'checkbox', contenttype_groups['video items']) }}
                 {{ forms.render_filter_field(gen, form['other_items'], 'checkbox', contenttype_groups['other items']) }}
+                {{ forms.render_filter_field(gen, form['unknown_items'], 'checkbox', unknown_items_label) }}
                 {{ gen.input(form['submit'], type='submit') }}
             </ul>
             {{ gen.form.close() }}