Title: [commits] (bear) [11313] Commiting Markku's patch for bug 6241
Revision
11313
Author
bear
Date
2006-08-02 13:59:27 -0700 (Wed, 02 Aug 2006)

Log Message

Commiting Markku's patch for bug 6241
The patch fixes a number of issues with the feed parcel.
bug 6241 r=morgen

Modified Paths

Diff

Modified: trunk/chandler/projects/Chandler-FeedsPlugin/feeds/blocks.py (11312 => 11313)

--- trunk/chandler/projects/Chandler-FeedsPlugin/feeds/blocks.py	2006-08-02 19:45:39 UTC (rev 11312)
+++ trunk/chandler/projects/Chandler-FeedsPlugin/feeds/blocks.py	2006-08-02 20:59:27 UTC (rev 11313)
@@ -18,8 +18,6 @@
 import osaf.framework.blocks.detail.Detail as Detail
 import application.Globals as Globals
 import osaf.framework.blocks.Block as Block
-from PyICU import ICUtzinfo, DateFormat
-import datetime
 import channels
 from i18n import OSAFMessageFactory as _
 from osaf import messages 
@@ -53,36 +51,71 @@
                 content = displayName
             #desc = desc.replace("<", "&lt;").replace(">", "&gt;")
             HTMLText = HTMLText + u'<p>' + content + u'</p>\n\n'
-            #should find a good way to localize "more..."
-            HTMLText = HTMLText + u'<br><a href="" + unicode(item.link) + \
-                u'">more...</a>'
+            if link:
+                HTMLText = HTMLText + u'<br><a href="" + unicode(item.link) + u'">' + _(u'more...') + u'</a>'
 
             HTMLText = HTMLText + '</body></html>\n'
 
             return HTMLText
 
-class FeedController(Block.Block):
-    def onNewFeedChannelEvent(self, event):
+class AddFeedCollectionEvent(Block.AddToSidebarEvent):
+    def onNewItem (self):
+        def calledInMainThread(channelUUID, success):
+            # This method is called once the feed has been processed.  If all
+            # is okay, success will be True, otherwise False.
+            self.itsView.refresh()
+            channel = self.itsView.findUUID(channelUUID)
+            
+            if not channel.isEstablished and not success:
+                url = ""
+                    _(u"The provided URL seems to be invalid"),
+                    _(u"Enter a URL for the RSS Channel"),
+                    defaultValue = unicode(channel.url))
+                if url != None:
+                    try:
+                        url = ""
+                        channel.displayName = url
+                        channel.url = "" 'type').makeValue(url)
+                        channel.isEstablished = False
+                        channel.isPreviousUpdateSuccessful = True
+                        channel.logItem = None
+                        channel.itsView.commit()
+                        channel.refresh(callback=calledInTwisted) # an async task
+                    except:
+                        application.dialogs.Util.ok(wx.GetApp().mainFrame,
+                                                    _(u"New Channel Error"),
+                                                    _(u"Could not create channel for %(url)s\nCheck the URL and try again.") % {'url': url})
+
+        def calledInTwisted(channelUUID, success):
+            # This callback is what we really pass to twisted, and it will
+            # invoke the calledInMainThread method in -- what else -- the
+            # main thread
+            wx.GetApp().PostAsyncEvent(calledInMainThread, channelUUID, success)
+
+        # get an URL from the user, ...
         import wx
         url = ""
             _(u"New Channel"),
             _(u"Enter a URL for the RSS Channel"),
-            defaultValue = "http://")
-        if url and url != "":
-            try:
-                # create the feed channel
-                channel = channels.newChannelFromURL(view=self.itsView, url=""
-                schema.ns("osaf.app", self).sidebarCollection.add (channel)
-                self.itsView.commit() # To make the channel avail to feedsView
-                channel.refresh() # an async task
+            defaultValue = u"http://")
+        if url == None:
+            return None
+        
+        # ... and then try to create a new channel.
+        try:
+            # create the feed channel
+            channel = channels.newChannelFromURL(view=self.itsView, url=""
+            self.itsView.commit() # To make the channel avail to feedsView
+            channel.refresh(callback=calledInTwisted) # an async task
+        except:
+            application.dialogs.Util.ok(wx.GetApp().mainFrame,
+                _(u"New Channel Error"),
+                _(u"Could not create channel for %(url)s\nCheck the URL and try again.") % {'url': url})
+            return None
+        
+        # return succesfully
+        return channel
 
-                return [channel]
-            except:
-                application.dialogs.Util.ok(wx.GetApp().mainFrame,
-                    _(u"New Channel Error"),
-                    _(u"Could not create channel for %(url)s\nCheck the URL and try again.") % {'url': url})
-                raise
-
 def installParcel(parcel, oldVersion=None):
 
     detail = schema.ns('osaf.framework.blocks.detail', parcel)
@@ -90,26 +123,23 @@
     main   = schema.ns('osaf.views.main', parcel)
     feeds  = schema.ns('feeds', parcel)
 
-    feed_controller = FeedController.update(parcel, "feed_controller")
+    # Create an AddFeedCollectionEvent that adds an RSS collection to the sidebar.
+    addFeedCollectionEvent = AddFeedCollectionEvent.update(
+        parcel, 'addFeedCollectionEvent',
+        blockName = 'addFeedCollectionEvent')
 
-    NewFeedChannelEvent = blocks.BlockEvent.update(
-        parcel, "NewFeedChannelEvent",
-        blockName="NewFeedChannel",
-        dispatchEnum="SendToBlockByReference",
-        destinationBlockReference=feed_controller,
-        commitAfterDispatch=True,
-    )
-
+    # Add a separator to the "Collection" menu ...
     blocks.MenuItem.update(parcel, 'FeedsParcelSeparator',
                            blockName = 'FeedsParcelSeparator',
                            menuItemKind = 'Separator',
                            parentBlock = main.CollectionMenu)
 
+    # ... and, below it, a menu item to subscribe to a RSS feed.
     blocks.MenuItem.update(parcel, "NewFeedChannel",
         blockName = "NewFeedChannelItem",
         title = _(u"New Feed Channel"),
-        event = NewFeedChannelEvent,
-        eventsForNamedLookup = [NewFeedChannelEvent],
+        event = addFeedCollectionEvent,
+        eventsForNamedLookup = [addFeedCollectionEvent],
         parentBlock = main.CollectionMenu,
     )
 

Modified: trunk/chandler/projects/Chandler-FeedsPlugin/feeds/channels.py (11312 => 11313)

--- trunk/chandler/projects/Chandler-FeedsPlugin/feeds/channels.py	2006-08-02 19:45:39 UTC (rev 11312)
+++ trunk/chandler/projects/Chandler-FeedsPlugin/feeds/channels.py	2006-08-02 20:59:27 UTC (rev 11313)
@@ -25,6 +25,9 @@
 from i18n import OSAFMessageFactory as _
 from twisted.web import client
 from twisted.internet import reactor
+from osaf.pim.calendar.TimeZone import formatTime
+from repository.util.URL import URL
+from repository.util.Lob import Lob
 
 logger = logging.getLogger(__name__)
 
@@ -124,7 +127,6 @@
             client.HTTPClientFactory.noPage(self, reason)
 
 
-
 class FeedChannel(pim.ListCollection):
 
     def __init__(self, *args, **kw):
@@ -171,34 +173,52 @@
         schema.Boolean,
         initialValue=False
     )
+    
+    isEstablished = schema.One(
+        schema.Boolean,
+        displayName=u"Channel has been established",
+        initialValue=False
+    )
 
+    isPreviousUpdateSuccessful = schema.One(
+        schema.Boolean,
+        displayName=u"Previous update was successful",
+        initialValue=True
+    )
+    
+    logItem = schema.One(
+        initialValue=None
+    )
+
     schema.addClouds(
         sharing = schema.Cloud(author, copyright, link, url)
     )
 
     who = schema.Descriptor(redirectTo="author")
-    about = schema.Descriptor(redirectTo="about")
 
 
-    def refresh(self):
+    def refresh(self, callback=None):
 
         # Make sure we have the feedsView copy of the channel item
         feedsView = getFeedsView(self.itsView.repository)
         feedsView.refresh()
         item = feedsView.findUUID(self.itsUUID)
+        
+        return item.download().addCallback(item.feedFetchSuccess, callback).addErrback(
+            item.feedFetchFailed, callback)
 
-        return item.download().addCallback(item.feedFetchSuccess).addErrback(
-            item.feedFetchFailed)
 
-
     def download(self):
         url = ""
-        etag = getattr(self, 'etag', None)
+        etag = str(getattr(self, 'etag', None))
         lastModified = getattr(self, 'lastModified', None)
         if lastModified:
             lastModified = lastModified.strftime("%a, %d %b %Y %H:%M:%S %Z")
 
         (scheme, host, port, path) = client._parse(url)
+        scheme = str(scheme)
+        host = str(host)
+        path = str(path)
         factory = ConditionalHTTPClientFactory(url=""
             lastModified=lastModified, etag=etag)
         reactor.connectTCP(host, port, factory)
@@ -207,7 +227,7 @@
 
 
 
-    def feedFetchSuccess(self, info):
+    def feedFetchSuccess(self, info, callback=None):
 
         (data, status, headers) = info
 
@@ -239,12 +259,20 @@
         count = self.parse(data)
         if count:
             logger.info("...added %d FeedItems" % count)
-
+            
+        self.isEstablished = True
+        self.isPreviousUpdateSuccessful = True
+        self.logItem = None
+        
         self.itsView.commit()
+        
+        if callback:
+            callback(self.itsUUID, True)
+            
         return FETCH_UPDATED
 
 
-    def feedFetchFailed(self, failure):
+    def feedFetchFailed(self, failure, callback=None):
 
         # getattr returns a unicode object which needs to be converted to
         # bytes for logging
@@ -257,6 +285,26 @@
         logger.error("Failed to update channel: %s; Reason: %s",
             channel, failure.getErrorMessage())
 
+        if self.isEstablished:
+            if self.isPreviousUpdateSuccessful:
+                self.isPreviousUpdateSuccessful = False
+                item = FeedItem(itsView=self.itsView)
+                item.displayName = _(u"Feed channel is unreachable")
+                item.author = _(u"Chandler Feeds Parcel")
+                item.category = _(u"Internal")
+                item.date = datetime.datetime.now(ICUtzinfo.default)
+                item.content = view.createLob(_(u"This feed channel is currently unreachable"))
+                self.addFeedItem(item)
+                self.logItem = item
+                self.itsView.commit()
+            else:
+                if self.logItem:
+                    self.logItem.content = view.createLob(u"This feed channel has been unreachable from " + unicode(formatTime(self.logItem.date)) + u" to " + unicode(formatTime(datetime.datetime.now(ICUtzinfo.default))))
+                    self.itsView.commit()
+
+        if callback:
+            callback(self.itsUUID, False)
+            
         return FETCH_FAILED
 
 
@@ -405,7 +453,8 @@
 
     link = schema.One(
         schema.URL,
-        initialValue="", # Needed because of the _compareLink( ) method
+        initialValue=None
+        #initialValue=URL(u""), # Needed because of the _compareLink( ) method
     )
 
     category = schema.One(




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to