changeset 1208:92d8f0777a9a

Improve handling of other data types in atom feed, also remove anchor tags from line numbers
author Shitiz Garg <mail@dragooon.net>
date Fri, 06 Jan 2012 14:29:18 +0530
parents af3fdd4c34e2
children c0eaed311e0e
files MoinMoin/apps/feed/views.py MoinMoin/items/__init__.py MoinMoin/templates/atom.html MoinMoin/templates/diff_text_atom.html
diffstat 4 files changed, 76 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/feed/views.py	Fri Jan 06 09:48:15 2012 +0530
+++ b/MoinMoin/apps/feed/views.py	Fri Jan 06 14:29:18 2012 +0530
@@ -78,7 +78,7 @@
                     content = hl_item._render_data_diff_atom(previous_rev, this_rev)
                 else:
                     # full html rendering for new items
-                    content = render_template('atom.html', get='first_revision', content=Markup(hl_item._render_data()), revision=this_revid)
+                    content = render_template('atom.html', get='first_revision', rev=this_rev, content=Markup(hl_item._render_data()), revision=this_revid)
                 content_type = 'html'
             except Exception as e:
                 logging.exception("content rendering crashed")
@@ -95,6 +95,8 @@
                 feed_title = "{0} - {1}".format(author.get(NAME, ''), rev_comment)
             else:
                 feed_title = "{0}".format(author.get(NAME, ''))
+            if not item_name:
+                feed_title = "{0} - {1}".format(name, feed_title)
             feed.add(title=feed_title, title_type='text',
                      summary=content, summary_type=content_type,
                      author=author,
--- a/MoinMoin/items/__init__.py	Fri Jan 06 09:48:15 2012 +0530
+++ b/MoinMoin/items/__init__.py	Fri Jan 06 14:29:18 2012 +0530
@@ -736,7 +736,12 @@
 
     _render_data_diff_text = _render_data_diff
     _render_data_diff_raw = _render_data_diff
-    _render_data_diff_atom = _render_data_diff
+    
+    def _render_data_diff_atom(self, oldrev, newrev):
+        url = url_for('frontend.get_item', _external=True, item_name=self.name, rev=newrev.revid)
+        return render_template('atom.html', url=url, 
+                               oldrev=oldrev, newrev=newrev, get='binary',
+                               content=Markup(self._render_data()))
 
     def _convert(self, doc):
         return _("Impossible to convert the data to the contenttype: %(contenttype)s",
@@ -924,7 +929,9 @@
 
 class Image(Binary):
     """ Base class for image/* """
-
+    def _render_data_diff(self, oldrev, newrev):
+        print 'test'
+        print self._internal_representation()
 item_registry.register(Image._factory, Type('image/*'))
 
 
--- a/MoinMoin/templates/atom.html	Fri Jan 06 09:48:15 2012 +0530
+++ b/MoinMoin/templates/atom.html	Fri Jan 06 14:29:18 2012 +0530
@@ -1,10 +1,60 @@
+{% import "utils.html" as utils %}
+{% macro show_meta(rev) %}
+    <div class="moin-diff-info moin-diff-info-rev-id">
+        <span class="moin-diff-info-caption">{{ _('Revision') }}:</span>
+        <span class="moin-diff-info-value">{{ rev.meta['revid'] | shorten_id }}</span>
+    </div>
+    <div class="moin-diff-info moin-diff-info-rev-size">
+        <span class="moin-diff-info-caption">{{ _('Size') }}:</span>
+        <span class="moin-diff-info-value">{{ rev.meta['size'] }}</span>
+    </div>
+    <div class="moin-diff-info moin-diff-info-rev-comment">
+        <span class="moin-diff-info-caption">{{ _('Comment') }}:</span>
+        <span class="moin-diff-info-value">{{ rev.meta['comment'] }}</span>
+    </div>
+{% endmacro %}
+
+{% macro safe_style() %}
+    <style type="text/css">
+        img {
+            max-width: 100%;
+        }
+        td {
+            padding-right: 10px;
+        }
+        table {
+            width: 100%;
+        }
+    </style>
+{% endmacro %}
+
 {%- if get == 'xml' -%}
     <?xml-stylesheet type="text/xsl" href="{{ theme_static('atom.xslt') }}"?>
 {%- elif get == 'comment_cont_merge' -%}
     <p style="font-size: 14px">...{{ comment }}</p> <br /> {{ content }}
 {%- elif get == 'first_revision' -%}
-    <div class="moin-diff-info moin-diff-info-rev-id">
-        <span class="moin-diff-info-caption"><strong>Revision: {{ revision | shorten_id }}</strong> - <i>{{ _('First revision') }}</i></span>
-    </div><br />
+    <table class="moin-diff" cellpadding="10" width="100%">
+        <tr>
+            <td class="moin-diff-header" style="width: 100%;">
+                <strong>{{ show_meta(rev) }}</strong>
+            </td>
+        </tr>
+    </table>
+    <br />
     {{ content }}
+    <strong>{{ safe_style() }}</strong>
+{%- elif get == 'binary' -%}
+    <table class="moin-diff" cellpadding="10" width="100%">
+        <tr>
+            <td class="moin-diff-header" style="width: 50%;">
+                <strong>{{ show_meta(oldrev) }}</strong>
+            </td>
+            <td class="moin-diff-header" style="width: 50%;">
+                <strong>{{ show_meta(newrev) }}</strong>
+            </td>
+        </tr>
+    </table>
+    <br />
+    {{ content }}
+    {{ safe_style() }}
 {%- endif -%}
\ No newline at end of file
--- a/MoinMoin/templates/diff_text_atom.html	Fri Jan 06 09:48:15 2012 +0530
+++ b/MoinMoin/templates/diff_text_atom.html	Fri Jan 06 14:29:18 2012 +0530
@@ -2,9 +2,17 @@
 
 {% macro show_meta(rev) %}
     <div class="moin-diff-info moin-diff-info-rev-id">
-        <span class="moin-diff-info-caption">Revision:</span>
+        <span class="moin-diff-info-caption">{{ _('Revision') }}:</span>
         <span class="moin-diff-info-value">{{ rev.meta['revid'] | shorten_id }}</span>
     </div>
+    <div class="moin-diff-info moin-diff-info-rev-size">
+        <span class="moin-diff-info-caption">{{ _('Size') }}:</span>
+        <span class="moin-diff-info-value">{{ rev.meta['size'] }}</span>
+    </div>
+    <div class="moin-diff-info moin-diff-info-rev-comment">
+        <span class="moin-diff-info-caption">{{ _('Comment') }}:</span>
+        <span class="moin-diff-info-value">{{ rev.meta['comment'] }}</span>
+    </div>
 {% endmacro %}
 <table class="moin-diff" style="width: 100%;">
     <tr>
@@ -20,9 +28,9 @@
         </td>    </tr>
     {% for llineno, lcontent, rlineno, rcontent in diffs %}
         <tr>
-            <td style="vertical-align: top;"><a href="#{{ llineno }}">{{ llineno }}:</a></td>
+            <td style="vertical-align: top;">{{ llineno }}:</td>
             <td class="moin-diff-removed" style="vertical-align: top; background-color:#ff9; word-wrap: break-word;"><blockquote>{{ lcontent }}</blockquote></td>
-            <td style="vertical-align: top;"><a href="#{{ rlineno }}">{{ rlineno }}:</a></td>
+            <td style="vertical-align: top;">{{ rlineno }}:</td>
             <td class="moin-diff-added" style="vertical-align: top; background-color: #cfc; word-wrap: break-word;"><blockquote>{{ rcontent }}</blockquote></td>
         </tr>
     {% endfor %}