Commits

Reimar Bauer committed a1b5dc3 Draft

plugins which add new contenttypes should extend the contentype list by CONTENTTYPE module parameter. The contenttype definition of twikidraw is moved to https://bitbucket.org/ReimarBauer/experimental_moin_plugin_twikidraw/changeset/2446736f3ee63fdb0a89ce07764f16d87635e00b

Comments (0)

Files changed (6)

MoinMoin/apps/frontend/views.py

 
 contenttype_groups = []
 contenttype_group_descriptions = {}
-for gname, contenttypes in CONTENTTYPE_GROUPS:
+for gname in CONTENTTYPE_GROUPS:
     contenttype_groups.append(gname)
-    contenttype_group_descriptions[gname] = ', '.join([ctlabel for ctname, ctlabel in contenttypes])
-contenttype_groups.append('unknown items')
+    contenttype_group_descriptions[gname] = ', '.join([ctlabel for ctname, ctlabel in CONTENTTYPE_GROUPS[gname]])
 
 ContenttypeGroup = MultiSelect.of(Enum.using(valid_values=contenttype_groups).with_properties(descriptions=contenttype_group_descriptions)).using(optional=True)
 

MoinMoin/constants/contenttypes.py

 """
 MoinMoin - contenttype related constants
 """
+from ordereddict import OrderedDict
 
 # Charset - we support only 'utf-8'. While older encodings might work,
 # we don't have the resources to test them, and there is no real
 
 # structure for contenttype groups
 # XXX needs to become dynamic 
-CONTENTTYPE_GROUPS = [
-    ('markup text items', [
+CONTENTTYPE_GROUPS = {
+    'markup text items': [
         ('text/x.moin.wiki;charset=utf-8', 'Wiki (MoinMoin)'),
         ('text/x.moin.creole;charset=utf-8', 'Wiki (Creole)'),
         ('text/x-mediawiki;charset=utf-8', 'Wiki (MediaWiki)'),
         ('text/x-rst;charset=utf-8', 'ReST'),
         ('application/docbook+xml;charset=utf-8', 'DocBook'),
         ('text/html;charset=utf-8', 'HTML'),
-    ]),
-    ('other text items', [
+    ],
+    'other text items': [
         ('text/plain;charset=utf-8', 'plain text'),
         ('text/x-diff;charset=utf-8', 'diff/patch'),
         ('text/x-python;charset=utf-8', 'python code'),
         ('text/csv;charset=utf-8', 'csv'),
         ('text/x-irclog;charset=utf-8', 'IRC log'),
-    ]),
-    ('image items', [
+    ],
+    'image items': [
         ('image/jpeg', 'JPEG'),
         ('image/png', 'PNG'),
         ('image/svg+xml', 'SVG'),
-    ]),
-    ('audio items', [
+    ],
+    'audio items': [
         ('audio/wave', 'WAV'),
         ('audio/ogg', 'OGG'),
         ('audio/mpeg', 'MP3'),
         ('audio/webm', 'WebM'),
-    ]),
-    ('video items', [
+    ],
+    'video items': [
         ('video/ogg', 'OGG'),
         ('video/webm', 'WebM'),
         ('video/mp4', 'MP4'),
-    ]),
-    ('drawing items', [
-        ('application/x-twikidraw', 'TDRAW'),
+    ],
+    'drawing items': [
         ('application/x-anywikidraw', 'ADRAW'),
         ('application/x-svgdraw', 'SVGDRAW'),
-    ]),
-    ('other items', [
+    ],
+    'other items': [
         ('application/pdf', 'PDF'),
         ('application/zip', 'ZIP'),
         ('application/x-tar', 'TAR'),
         ('application/x-gtar', 'TGZ'),
         ('application/octet-stream', 'binary file'),
-    ]),
-]
+    ],
+}
+
+# TODO sorting can be better
+CONTENTTYPE_GROUPS = OrderedDict(sorted(CONTENTTYPE_GROUPS.items(),
+                                        key=lambda t: len(t[0]) + len(t[1]),
+                                        reverse=True))

MoinMoin/items/__init__.py

 
         def build_contenttypes(groups):
             ctypes = [[ctype for ctype, clabel in contenttypes]
-                      for gname, contenttypes in CONTENTTYPE_GROUPS
+                      for gname, contenttypes in CONTENTTYPE_GROUPS.items()
                       if gname in groups]
             ctypes_chain = itertools.chain(*ctypes)
             contenttypes = list(ctypes_chain)
             return contenttypes
 
         if selected_groups is not None:
-            all_groups = [gname for gname, contenttypes in CONTENTTYPE_GROUPS]
+            all_groups = CONTENTTYPE_GROUPS.keys()
             selected_contenttypes = build_contenttypes(selected_groups)
             filtered_index = [e for e in index
                               if e.meta[CONTENTTYPE] in selected_contenttypes]

MoinMoin/templates/modify_select_contenttype.html

 {{ _("Please select the contenttype of the new %(itemtype)s item.", itemtype=itemtype) }}
 </p>
 <table id="moin-create-table" class="zebra">
-    {% for gname, contenttypes in contenttype_groups %}
+    {% for gname in contenttype_groups %}
     <tr>
         <th>{{ gname }}</th>
     </tr>
     <tr>
         <td> |&nbsp
-        {% for ctname, ctlabel in contenttypes %}
+        {% for ctname, ctlabel in  contenttype_groups[gname] %}
             <a href="{{ url_for('frontend.modify_item', item_name=item_name, itemtype=itemtype, contenttype=ctname) }}">{{ ctlabel }}</a> &nbsp|&nbsp
         {% endfor %}
         </td>
         'whoosh>=2.4.0', # needed for indexed search
         'sphinx>=1.1', # needed to build the docs
         'pdfminer', # pdf -> text/plain conversion
+        'ordereddict>=1.1', # A drop-in substitute for Py2.7's new collections.OrderedDict that works in Python 2.4-2.6.
         'XStatic>=0.0.2', # support for static file pypi packages
         'XStatic-CKEditor>=3.6.1.2',
         'XStatic-jQuery-File-Upload>=4.4.2',
 from MoinMoin.config.default import DefaultConfig
 from MoinMoin.storage import create_simple_mapping
 from MoinMoin.util.interwiki import InterWikiMap
+from MoinMoin.config import CONTENTTYPE_GROUPS
 
 
 class Config(DefaultConfig):
                     js_scripts[key] += mod.JS_SCRIPTS[key]
             except AttributeError:
                 pass
+            # plugin adds a new contenttype tp a new or existing group
+            try:
+                gname, contenttype = mod.CONTENTTYPE.items()[0]
+                if gname in CONTENTTYPE_GROUPS:
+                    CONTENTTYPE_GROUPS[gname] = CONTENTTYPE_GROUPS[gname] + contenttype
+                else:
+                    CONTENTTYPE_GROUPS[gname] = contenttype
+            except AttributeError:
+                pass
+            
 
 MOINCFG = Config # Flask only likes uppercase stuff
 # Flask settings - see the flask documentation about their meaning