silence warnings by porting to cw 3.9
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 16 Jul 2010 12:44:03 +0200
changeset 208 178d57399aaa
parent 207 cdce4addac55
child 209 b4827131db9a
silence warnings by porting to cw 3.9
data/external_resources
entities.py
hooks.py
test/unittest_blog.py
uiprops.py
views/boxes.py
views/primary.py
views/secondary.py
--- a/data/external_resources	Wed May 19 19:11:42 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-BLOG_ICON = DATADIR/icon_blog.gif
--- a/entities.py	Wed May 19 19:11:42 2010 +0200
+++ b/entities.py	Fri Jul 16 12:44:03 2010 +0200
@@ -10,26 +10,25 @@
 from logilab.common.date import todate
 
 from cubicweb.entities import AnyEntity, fetch_config
-from cubicweb.interfaces import (ICalendarViews, ICalendarable,
-                                 ISiocItem, ISiocContainer, IPrevNext)
-
+from cubicweb.view import EntityAdapter
+from cubicweb.selectors import is_instance
 
-class Blog(AnyEntity):
-    """customized class for Blog entities"""
-
-    __regid__ = 'Blog'
-    __implements__ = AnyEntity.__implements__ + (ISiocContainer,)
+class BlogIFeedAdapter(EntityAdapter):
+    __regid__ = 'IFeed'
+    __select__ = EntityAdapter.__select__ & is_instance('Blog')
 
     def rss_feed_url(self):
-        if self.rss_url:
-            return self.rss_url
+        if self.entity.rss_url:
+            return self.entity.rss_url
         rql = ('Any E ORDERBY D DESC '
                'WHERE E is BlogEntry, E entry_of X, X eid %s, E creation_date D'
                )
         return self._cw.build_url(rql=rql % self.eid, vid='rss',
                               vtitle=self.dc_title())
 
-    # isioc interface ##########################################################
+class BlogISiocContainerAdapter(EntityAdapter):
+    __regid__ = 'ISiocContainer'
+    __select__ = EntityAdapter.__select__ & is_instance('Blog')
 
     def isioc_type(self):
         return 'Weblog'
@@ -42,8 +41,6 @@
     """customized class for BlogEntry entities"""
     __regid__ = 'BlogEntry'
     fetch_attrs, fetch_order = fetch_config(['creation_date', 'title'], order='DESC')
-    __implements__ = AnyEntity.__implements__ + (
-        ICalendarViews, ICalendarable, ISiocItem, IPrevNext)
 
     def dc_title(self):
         return self.title
@@ -58,19 +55,26 @@
     def parent(self):
         return self.entry_of and self.entry_of[0] or None
 
-    # calendar interfaces ######################################################
+class BlogEntryICalendarableAdapter(EntityAdapter):
+    __regid__ = 'ICalendarable'
+    __select__ = EntityAdapter.__select__ & is_instance('BlogEntry')
 
     @property
     def start(self):
-        return self.creation_date
+        return self.entity.creation_date
 
     @property
     def stop(self):
-        return self.creation_date
+        return self.entity.creation_date
+
+
+class BlogEntryICalendarViewsAdapter(EntityAdapter):
+    __regid__ = 'ICalendarViews'
+    __select__ = EntityAdapter.__select__ & is_instance('BlogEntry')
 
     def matching_dates(self, begin, end):
         """calendar views interface"""
-        mydate = self.creation_date
+        mydate = self.entity.creation_date
         if not mydate:
             return []
         mydate = todate(mydate)
@@ -78,18 +82,16 @@
             return [mydate]
         return []
 
-    def postinfo_description(self):
-        _ = self._cw._
-        descr = u'%s %s' % (_('posted on'), self._cw.format_date(self.creation_date))
-        return descr
 
-    # isioc interface ##########################################################
+class BlogEntryISiocItemAdapter(EntityAdapter):
+    __regid__ = 'ISiocItem'
+    __select__ = EntityAdapter.__select__ & is_instance('BlogEntry')
 
     def isioc_content(self):
-        return self.content
+        return self.entity.content
 
     def isioc_container(self):
-        return self.parent()
+        return self.entity.parent()
 
     def isioc_type(self):
         return 'BlogPost'
@@ -102,23 +104,27 @@
         # XXX link to tags, folders?
         return []
 
-    # IPrevNext interface #####################################################
-    def _sibling_entry(self, order, operator):
-        if self.entry_of:
-            rql = ('Any B ORDERBY B %s LIMIT 1 '
-                   'WHERE B is BlogEntry, B entry_of BL, BL eid %%(blog)s, '
-                   'B eid %s %%(eid)s')
-            rset = self._cw.execute(rql % (order, operator),
-                                    {'blog': self.entry_of[0].eid, 'eid': self.eid})
-        else:
-            rql = ('Any B ORDERBY B %s LIMIT 1 '
-                   'WHERE B is BlogEntry, B eid %s %%(eid)s')
-            rset = self._cw.execute(rql % (order, operator), {'eid': self.eid})
-        if rset:
-            return rset.get_entity(0,0)
+class BlogEntryIPrevNextAdapter(EntityAdapter):
+    __regid__ = 'IPrevNext'
+    __select__ = EntityAdapter.__select__ & is_instance('BlogEntry')
 
     def next_entity(self):
         return self._sibling_entry('ASC', '>')
 
     def previous_entity(self):
         return self._sibling_entry('DESC', '<')
+
+    def _sibling_entry(self, order, operator):
+        if self.entity.entry_of:
+            rql = ('Any B ORDERBY B %s LIMIT 1 '
+                   'WHERE B is BlogEntry, B entry_of BL, BL eid %%(blog)s, '
+                   'B eid %s %%(eid)s')
+            rset = self._cw.execute(rql % (order, operator),
+                                    {'blog': self.entity.entry_of[0].eid, 'eid': self.entity.eid})
+        else:
+            rql = ('Any B ORDERBY B %s LIMIT 1 '
+                   'WHERE B is BlogEntry, B eid %s %%(eid)s')
+            rset = self._cw.execute(rql % (order, operator), {'eid': self.entity.eid})
+        if rset:
+            return rset.get_entity(0,0)
+
--- a/hooks.py	Wed May 19 19:11:42 2010 +0200
+++ b/hooks.py	Fri Jul 16 12:44:03 2010 +0200
@@ -1,9 +1,9 @@
-from cubicweb.selectors import implements, is_in_state
+from cubicweb.selectors import is_instance, is_in_state
 from cubicweb.sobjects.notification import NotificationView, StatusChangeMixIn
 
 class BlogEntryPublishedView(StatusChangeMixIn, NotificationView):
     """get notified from published blogs"""
-    __select__ = implements('BlogEntry',) & is_in_state('published')
+    __select__ = is_instance('BlogEntry',) & is_in_state('published')
     content_attr = 'content'
 
     def subject(self):
--- a/test/unittest_blog.py	Wed May 19 19:11:42 2010 +0200
+++ b/test/unittest_blog.py	Fri Jul 16 12:44:03 2010 +0200
@@ -18,12 +18,12 @@
         self.assertEquals(len(MAILBOX), 0)
         self.commit()
         self.assertEquals(len(MAILBOX), 0)
-        blog_entry_1.fire_transition('publish')
+        blog_entry_1.cw_adapt_to('IWorkflowable').fire_transition('publish')
         self.commit()
         self.assertEquals(len(MAILBOX), 1)
         mail = MAILBOX[0]
         self.assertEquals(mail.subject, '[data] hop')
-        blog_entry_2.fire_transition('publish')
+        blog_entry_2.cw_adapt_to('IWorkflowable').fire_transition('publish')
         self.commit()
         self.assertEquals(len(MAILBOX), 2)
         mail = MAILBOX[1]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uiprops.py	Fri Jul 16 12:44:03 2010 +0200
@@ -0,0 +1,1 @@
+BLOG_ICON = data('icon_blog.gif')
--- a/views/boxes.py	Wed May 19 19:11:42 2010 +0200
+++ b/views/boxes.py	Fri Jul 16 12:44:03 2010 +0200
@@ -9,7 +9,7 @@
 
 from logilab.mtconverter import xml_escape
 
-from cubicweb.selectors import one_line_rset, implements
+from cubicweb.selectors import one_line_rset, is_instance
 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget
 from cubicweb.web.views import boxes
 
@@ -77,7 +77,7 @@
         if self.display_see_more_link:
             url = self._cw.build_url('view', rql=rql, page_size=10)
             box.append(BoxLink(url,  u'[%s]' % self._cw._(u'see more')))
-        rss_icon = self._cw.external_resource('RSS_LOGO_16')
+        rss_icon = self._cw.uiprops['RSS_LOGO_16']
         # FIXME - could use rss_url defined as a property if available
         rss_label = u'%s <img src="%s" alt="%s"/>' % (
             self._cw._(u'subscribe'), rss_icon, self._cw._('rss icon'))
@@ -89,7 +89,7 @@
 class LatestBlogsBlogBox(LatestBlogsBox):
     """display a box with latest blogs and rss, filtered for a particular blog
     """
-    __select__ = LatestBlogsBox.__select__ & one_line_rset() & implements('Blog')
+    __select__ = LatestBlogsBox.__select__ & one_line_rset() & is_instance('Blog')
     title = _('latest_blogs_blog_box')
     display_see_more_link = False
 
--- a/views/primary.py	Wed May 19 19:11:42 2010 +0200
+++ b/views/primary.py	Fri Jul 16 12:44:03 2010 +0200
@@ -9,7 +9,7 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb.utils import UStringIO
-from cubicweb.selectors import implements
+from cubicweb.selectors import is_instance
 from cubicweb.web import uicfg, component
 from cubicweb.web.views import primary, workflow
 
@@ -31,7 +31,7 @@
 
 
 class BlogPrimaryView(primary.PrimaryView):
-    __select__ = implements('Blog')
+    __select__ = is_instance('Blog')
 
     def render_entity_relations(self, entity):
         super(BlogPrimaryView, self).render_entity_relations(entity)
@@ -48,14 +48,14 @@
 
 class SubscribeToBlogComponent(component.EntityVComponent):
     __regid__ = 'blogsubscribe'
-    __select__ = component.EntityVComponent.__select__ & implements('Blog')
+    __select__ = component.EntityVComponent.__select__ & is_instance('Blog')
     context = 'ctxtoolbar'
 
     def cell_call(self, row, col, view):
         entity = self.cw_rset.get_entity(row, col)
         self.w('<a href="%s"><img src="%s" alt="%s"/></a>' % (
-            xml_escape(entity.rss_feed_url()),
-            self._cw.external_resource('RSS_LOGO_16'),
+            xml_escape(entity.cw_adapt_to('IFeed').rss_feed_url()),
+            self._cw.uiprops['RSS_LOGO_16'],
             self._cw._(u'subscribe to this blog')))
 
 def render_blogentry_title(req, w, entity):
@@ -73,7 +73,7 @@
     w(u'</div></div>')
 
 class BlogEntryPrimaryView(primary.PrimaryView):
-    __select__ = implements('BlogEntry')
+    __select__ = is_instance('BlogEntry')
     show_attr_label = False
 
     def render_entity_relations(self, entity):
@@ -92,7 +92,7 @@
 
 # don't show workflow history for blog entry
 class BlogEntryWFHistoryVComponent(workflow.WFHistoryVComponent):
-    __select__ = workflow.WFHistoryVComponent.__select__ & implements('BlogEntry')
+    __select__ = workflow.WFHistoryVComponent.__select__ & is_instance('BlogEntry')
 
     def cell_call(self, row, col, view=None):
         pass
--- a/views/secondary.py	Wed May 19 19:11:42 2010 +0200
+++ b/views/secondary.py	Fri Jul 16 12:44:03 2010 +0200
@@ -13,7 +13,7 @@
 
 from cubicweb.schema import display_name
 from cubicweb.view import EntityView, StartupView
-from cubicweb.selectors import paginated_rset, sorted_rset, implements
+from cubicweb.selectors import paginated_rset, sorted_rset, is_instance
 from cubicweb.web.views import baseviews, calendar, navigation
 
 from cubes.blog.views.primary import render_blogentry_title
@@ -75,7 +75,7 @@
 
 
 class BlogEntrySameETypeListView(baseviews.SameETypeListView):
-    __select__ = baseviews.SameETypeListView.__select__ & implements('BlogEntry')
+    __select__ = baseviews.SameETypeListView.__select__ & is_instance('BlogEntry')
     countrql = ('Any COUNT(B) WHERE B is BlogEntry, '
                 'B creation_date >= %(firstday)s, B creation_date <= %(lastday)s')
     item_vid = 'blog'
@@ -126,7 +126,7 @@
 
 class BlogEntryBlogView(EntityView):
     __regid__ = 'blog'
-    __select__ = implements('BlogEntry')
+    __select__ = is_instance('BlogEntry')
 
     def cell_call(self, row, col, **kwargs):
         entity = self.cw_rset.get_entity(row, col)
@@ -144,7 +144,7 @@
 
 class BlogEntryPostMetaData(EntityView):
     __regid__ = 'post-reldata'
-    __select__ = implements('BlogEntry')
+    __select__ = is_instance('BlogEntry')
 
     def cell_call(self, row, col):
         entity = self.cw_rset.get_entity(row, col)
@@ -177,7 +177,7 @@
 
 
 class BlogNavigation(navigation.PageNavigation):
-    __select__ = paginated_rset() & sorted_rset() & implements('BlogEntry')
+    __select__ = paginated_rset() & sorted_rset() & is_instance('BlogEntry')
 
     def index_display(self, start, stop):
         return u'%s' % (int(start / self.page_size)+1)