changeset 1088:fee472613dfa beta

made simple global rss and atom feed
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Feb 2011 17:49:52 +0100
parents 51076a2a2b64
children 8af52e1224ff
files rhodecode/config/routing.py rhodecode/controllers/feed.py rhodecode/controllers/journal.py rhodecode/model/db.py rhodecode/public/css/style.css
diffstat 5 files changed, 105 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Sat Feb 26 16:04:38 2011 +0100
+++ b/rhodecode/config/routing.py	Sat Feb 26 17:49:52 2011 +0100
@@ -148,8 +148,10 @@
 
     #USER JOURNAL
     routes_map.connect('journal', '/_admin/journal', controller='journal',)
-    routes_map.connect('public_journal', '/_admin/public_journal', controller='journal',
-                       action="public_journal")
+    routes_map.connect('public_journal', '/_admin/public_journal', controller='journal', action="public_journal")
+    routes_map.connect('public_journal_rss', '/_admin/public_journal_rss', controller='journal', action="public_journal_rss")
+    routes_map.connect('public_journal_atom', '/_admin/public_journal_atom', controller='journal', action="public_journal_atom")
+
     routes_map.connect('toggle_following', '/_admin/toggle_following', controller='journal',
                 action='toggle_following', conditions=dict(method=["POST"]))
 
--- a/rhodecode/controllers/feed.py	Sat Feb 26 16:04:38 2011 +0100
+++ b/rhodecode/controllers/feed.py	Sat Feb 26 17:49:52 2011 +0100
@@ -46,7 +46,7 @@
         super(FeedController, self).__before__()
         #common values for feeds
         self.description = _('Changes on %s repository')
-        self.title = "%s feed"
+        self.title = self.title = _('%s %s feed') % (c.rhodecode_name, '%s')
         self.language = 'en-us'
         self.ttl = "5"
         self.feed_nr = 10
--- a/rhodecode/controllers/journal.py	Sat Feb 26 16:04:38 2011 +0100
+++ b/rhodecode/controllers/journal.py	Sat Feb 26 17:49:52 2011 +0100
@@ -32,11 +32,13 @@
 from itertools import groupby
 
 from paste.httpexceptions import HTTPInternalServerError
-from pylons import request, tmpl_context as c
+from pylons import request, tmpl_context as c, response, url
+from pylons.i18n.translation import _
+from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
 
+import rhodecode.lib.helpers as h
 from rhodecode.lib.auth import LoginRequired, NotAnonymous
 from rhodecode.lib.base import BaseController, render
-from rhodecode.lib.helpers import get_token
 from rhodecode.model.db import UserLog, UserFollowing
 
 log = logging.getLogger(__name__)
@@ -47,6 +49,10 @@
     @LoginRequired()
     def __before__(self):
         super(JournalController, self).__before__()
+        self.title = _('%s public journal %s feed') % (c.rhodecode_name, '%s')
+        self.language = 'en-us'
+        self.ttl = "5"
+        self.feed_nr = 20
 
     @NotAnonymous()
     def index(self):
@@ -113,7 +119,7 @@
     @NotAnonymous()
     def toggle_following(self):
         cur_token = request.POST.get('auth_token')
-        token = get_token()
+        token = h.get_token()
         if cur_token == token:
 
             user_id = request.POST.get('follows_user_id')
@@ -160,3 +166,79 @@
         if request.params.get('partial'):
             return c.journal_data
         return render('journal/public_journal.html')
+
+
+
+    def public_journal_atom(self):
+        """
+        Produce an atom-1.0 feed via feedgenerator module
+        """
+        c.following = self.sa.query(UserFollowing)\
+            .filter(UserFollowing.user_id == c.rhodecode_user.user_id)\
+            .options(joinedload(UserFollowing.follows_repository))\
+            .all()
+
+        journal = self._get_journal_data(c.following)
+
+        feed = Atom1Feed(title=self.title % 'atom',
+                         link=url('public_journal_atom', qualified=True),
+                         description=_('Public journal'),
+                         language=self.language,
+                         ttl=self.ttl)
+
+        for entry in journal[:self.feed_nr]:
+            #tmpl = h.action_parser(entry)[0]
+            action, action_extra = h.action_parser(entry, feed=True)
+            title = "%s - %s %s" % (entry.user.short_contact, action,
+                                 entry.repository.repo_name)
+            desc = action_extra()
+            feed.add_item(title=title,
+                          pubdate=entry.action_date,
+                          link=url('', qualified=True),
+                          author_email=entry.user.email,
+                          author_name=entry.user.full_contact,
+                          description=desc)
+
+        response.content_type = feed.mime_type
+        return feed.writeString('utf-8')
+
+    def public_journal_rss(self):
+        """
+        Produce an rss2 feed via feedgenerator module
+        """
+        c.following = self.sa.query(UserFollowing)\
+            .filter(UserFollowing.user_id == c.rhodecode_user.user_id)\
+            .options(joinedload(UserFollowing.follows_repository))\
+            .all()
+
+        journal = self._get_journal_data(c.following)
+
+        feed = Rss201rev2Feed(title=self.title % 'rss',
+                         link=url('public_journal_rss', qualified=True),
+                         description=_('Public journal'),
+                         language=self.language,
+                         ttl=self.ttl)
+
+        for entry in journal[:self.feed_nr]:
+            #tmpl = h.action_parser(entry)[0]
+            action, action_extra = h.action_parser(entry, feed=True)
+            title = "%s - %s %s" % (entry.user.short_contact, action,
+                                 entry.repository.repo_name)
+            desc = action_extra()
+            feed.add_item(title=title,
+                          pubdate=entry.action_date,
+                          link=url('', qualified=True),
+                          author_email=entry.user.email,
+                          author_name=entry.user.full_contact,
+                          description=desc)
+
+        response.content_type = feed.mime_type
+        return feed.writeString('utf-8')
+
+
+
+
+
+
+
+
--- a/rhodecode/model/db.py	Sat Feb 26 16:04:38 2011 +0100
+++ b/rhodecode/model/db.py	Sat Feb 26 17:49:52 2011 +0100
@@ -98,6 +98,11 @@
         return '%s %s <%s>' % (self.name, self.lastname, self.email)
 
     @property
+    def short_contact(self):
+        return '%s %s' % (self.name, self.lastname)
+
+
+    @property
     def is_admin(self):
         return self.admin
 
--- a/rhodecode/public/css/style.css	Sat Feb 26 16:04:38 2011 +0100
+++ b/rhodecode/public/css/style.css	Sat Feb 26 17:49:52 2011 +0100
@@ -605,16 +605,16 @@
 }
 
 #content div.box div.title ul.links li a {
-height:1%;
-display:block;
-float:left;
-border-left:1px solid #316293;
-color:#fff;
-font-size:11px;
-font-weight:700;
-text-decoration:none;
-margin:0;
-padding:13px 16px 12px;
+    border-left: 1px solid #316293;
+    color: #FFFFFF;
+    display: block;
+    float: left;
+    font-size: 13px;
+    font-weight: 700;
+    height: 1%;
+    margin: 0;
+    padding: 11px 22px 12px;
+    text-decoration: none;
 }
 
 #content div.box h1,#content div.box h2,#content div.box h3,#content div.box h4,#content div.box h5,#content div.box h6 {