changeset 2669:7798855349f6

Improved Metadata view
author Ajitesh Gupta <ajgupta93@gmail.com>
date Sat, 19 Jul 2014 14:38:21 +0530
parents f649d7a3b3cd
children 54aaba93f5de
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/templates/meta.html MoinMoin/templates/utils.html MoinMoin/themes/__init__.py MoinMoin/themes/basic/templates/meta.html
diffstat 6 files changed, 106 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sat Jul 19 14:38:21 2014 +0530
@@ -551,7 +551,7 @@
                            contenttype=item.contenttype,
                            first_rev_id=first_rev,
                            last_rev_id=last_rev,
-                           meta_rendered=Markup(item._render_meta()),
+                           meta=item._meta_info(),
                            show_revision=show_revision,
                            show_navigation=show_navigation,
     )
--- a/MoinMoin/items/__init__.py	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/items/__init__.py	Sat Jul 19 14:38:21 2014 +0530
@@ -376,8 +376,8 @@
     def contenttype(self):
         return self.content.contenttype if self.content else None
 
-    def _render_meta(self):
-        return "<pre>{0}</pre>".format(escape(self.meta_dict_to_text(self.meta, use_filter=False)))
+    def _meta_info(self):
+        return self.meta_to_dict(self.meta, use_filter=False)
 
     def meta_filter(self, meta):
         """ kill metadata entries that we set automatically when saving """
@@ -397,6 +397,13 @@
             meta.pop(key, None)
         return meta
 
+    def meta_to_dict(self, meta, use_filter=True):
+        """ convert meta data from storage object to python dict """
+        meta = dict(meta)
+        if use_filter:
+            meta = self.meta_filter(meta)
+        return meta
+
     def meta_text_to_dict(self, text):
         """ convert meta data from a text fragment to a dict """
         meta = json.loads(text)
@@ -404,9 +411,7 @@
 
     def meta_dict_to_text(self, meta, use_filter=True):
         """ convert meta data from a dict to a text fragment """
-        meta = dict(meta)
-        if use_filter:
-            meta = self.meta_filter(meta)
+        meta = self.meta_to_dict(meta, use_filter)
         return json.dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
 
     def prepare_meta_for_modify(self, meta):
--- a/MoinMoin/templates/meta.html	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/templates/meta.html	Sat Jul 19 14:38:21 2014 +0530
@@ -1,4 +1,5 @@
 {% extends theme("show.html") %}
+{% import "utils.html" as utils with context %}
 
 {% set title = _("Metadata of '%(item_name)s'", item_name=item_name) %}
 
@@ -11,9 +12,9 @@
     {{ title }}
     {% if show_revision %}({{ _("Revision") }} {{ rev.revid | shorten_id }}){% endif %}
 </h1>
-{% if meta_rendered %}
+{% if meta %}
 <div id="moin-content-meta">
-    {{ meta_rendered }}
+    {{ utils.meta_info(meta) }}
 </div>
 {% endif %}
 {% endblock %}
--- a/MoinMoin/templates/utils.html	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/templates/utils.html	Sat Jul 19 14:38:21 2014 +0530
@@ -101,3 +101,83 @@
             {{ forms.render_errors(form) }}
     {{ gen.form.close() }}
 {% endmacro %}
+
+{% macro meta_info(meta) %}
+<!-- Bootstrap classes list-group and list-group-item used to display the metadata info in an unordered list -->
+    <ul class="list-group">
+        <li class="list-group-item">Action: {{ meta['action'] }}</li>
+        <li class="list-group-item">Address: {{ meta['address'] }}</li>
+        <li class="list-group-item">Comment: '{{ meta['comment'] }}'</li>
+        <li class="list-group-item">Content Type: {{ meta['contenttype']|shorten_ctype }} [{{ meta['contenttype'] }}]</li>
+        <li class="list-group-item">Data ID: {{ meta['dataid'] }}</li>
+        <li class="list-group-item">External Links:
+        {% if meta['externallinks'] %}
+            {% for item in meta['externallinks'] %}
+                <a href="{{ item|safe }}">
+                    {{ item }}
+                </a>,
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Item ID: {{ meta['itemid'] }}</li>
+        <li class="list-group-item">Item Links:
+        {% if meta['itemlinks'] %}
+            {% for item in meta['itemlinks'] %}
+                <a href="{{ url_for('frontend.show_item', item_name=item) }}" {% if not theme_supp.item_exists(item) %}class="moin-nonexistent"{% endif %}>
+                    {{ item }}
+                </a>,
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Item Transclusions:
+        {% if meta['itemtransclusions'] %}
+            {% for item in meta['itemtransclusions'] %}
+                <a href="{{ url_for('frontend.show_item', item_name=item) }}" {% if not theme_supp.item_exists(item) %}class="moin-nonexistent"{% endif %}>
+                {{ item }}
+                </a>,
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Item Type: {{ meta['itemtype'] }}</li>
+        <li class="list-group-item">Modified Time: {{ meta['mtime']|datetimeformat }}</li>
+        <li class="list-group-item">Name:
+        {% if meta['name'] %}
+            {% for name in meta['name'] %}
+                {{ name }}
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Old Name:
+        {% if meta['name_old'] %}
+            {% for name in meta['name_old'] %}
+                {{ name }}
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Namespace: '{{ meta['namespace'] }}'</li>
+        <li class="list-group-item">Revision ID: {{ meta['revid'] }}</li>
+        <li class="list-group-item">SHA1: {{ meta['sha1'] }}</li>
+        <li class="list-group-item">Size: {{ meta['size']|filesizeformat }}</li>
+        <li class="list-group-item">Summary: '{{ meta['summary'] }}'</li>
+        <li class="list-group-item">Tags:
+        {% if meta['tags'] %}
+            {% for tag in meta['tags'] %}
+                {{ tag }}
+            {% endfor %}
+        {% else %}
+            (None)
+        {% endif %}
+        </li>
+        <li class="list-group-item">Wiki Name: {{ meta['wikiname'] }}</li>
+    </ul>
+{% endmacro %}
--- a/MoinMoin/themes/__init__.py	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/themes/__init__.py	Sat Jul 19 14:38:21 2014 +0530
@@ -475,6 +475,15 @@
                 namespace_root_mapping.append((namespace or '~', fq_namespace.get_root_fqname()))
         return namespace_root_mapping
 
+    def item_exists(self, itemname):
+        """
+        Check whether the item pointed to by the given itemname exists or not
+
+        :rtype: boolean
+        :returns: whether item pointed to by the link exists or not
+        """
+        return self.storage.has_item(itemname)
+
 
 def get_editor_info(meta, external=False):
     addr = meta.get(ADDRESS)
--- a/MoinMoin/themes/basic/templates/meta.html	Sat Jul 19 14:30:01 2014 +0530
+++ b/MoinMoin/themes/basic/templates/meta.html	Sat Jul 19 14:38:21 2014 +0530
@@ -1,4 +1,5 @@
 {% extends theme("layout.html") %}
+{% import "utils.html" as utils with context %}
 {% import theme("itemviews.html") as itemviews with context %}
 
 {% set title = _("Metadata of '%(item_name)s'", item_name=item_name) %}
@@ -16,9 +17,9 @@
     {{ title }}
     {% if show_revision %}({{ _("Revision") }} {{ rev.revid | shorten_id }}){% endif %}
 </h2>
-{% if meta_rendered %}
+{% if meta %}
 <div id="moin-content-meta">
-    {{ meta_rendered }}
+    {{ utils.meta_info(meta) }}
 </div>
 {% endif %}
 {% endblock %}