diff --git a/.hgtags b/.hgtags index 46ef47deb5f33cc40184e721a8d351f1b2598217_LmhndGFncw==..082c8235ed099ad5bc662d1881a44799accadbce_LmhndGFncw== 100644 --- a/.hgtags +++ b/.hgtags @@ -21,3 +21,5 @@ 9d6d4fa876edd538bfe9778875418b6776ad3ba6 cubicweb-comment-debian-version-1.7.0-1 0881586faa619b901390771a691106a926e62d11 cubicweb-comment-version-1.7.1 4b66ebd9ddf69f877b51fc858a8aaa2d363e3701 cubicweb-comment-debian-version-1.7.1-1 +46cc97b563324a908ba029661355663738e900b3 cubicweb-comment-version-1.7.2 +a63fa00a1cca5a0f27bb0a57182473a5aabcc604 cubicweb-comment-debian-version-1.7.2-1 diff --git a/MANIFEST.in b/MANIFEST.in index 46ef47deb5f33cc40184e721a8d351f1b2598217_TUFOSUZFU1QuaW4=..082c8235ed099ad5bc662d1881a44799accadbce_TUFOSUZFU1QuaW4= 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,2 @@ include *.py -recursive-include data external_resources *.js *.css *.gif *.png -recursive-include i18n *.pot *.po recursive-include migration *.py @@ -4,1 +2,3 @@ recursive-include migration *.py +recursive-include data *.js *.css *.gif *.png +recursive-include i18n *.po diff --git a/README b/README index 46ef47deb5f33cc40184e721a8d351f1b2598217_UkVBRE1F..082c8235ed099ad5bc662d1881a44799accadbce_UkVBRE1F 100644 --- a/README +++ b/README @@ -3,6 +3,33 @@ The `comment` cube provides threadable comments feature. +It is a CubicWeb component. CubicWeb is a semantic web application +framework, see http://www.cubicweb.org + + +Install +------- + +Auto-install from sources prefered with *pip/Distribute*:: + + pip install cubicweb-comment + +If you have troubles, use *easy_install/setuptools* and eggs:: + + easy_install cubicweb-comment + +You can install the package manually from the uncompressed +`tarball <http://www.cubicweb.org/project/cubicweb-comment>`_:: + + python setup.py install # auto-install dependencies + +If you don't want the dependancies to be installed automaticly, you +can force the setup to use the standard library *distutils*:: + + NO_SETUPTOOLS=1 python setup.py install + +More details at http://www.cubicweb.org/doc/en/admin/setup + Usage ----- @@ -26,3 +53,9 @@ Once this relation is defined, you can post comments and view threadable comments automatically on blog entry's primary view. + +Documentation +------------- + +Look in the ``doc/`` subdirectory or read +http://www.cubicweb.org/doc/en/ diff --git a/__pkginfo__.py b/__pkginfo__.py index 46ef47deb5f33cc40184e721a8d351f1b2598217_X19wa2dpbmZvX18ucHk=..082c8235ed099ad5bc662d1881a44799accadbce_X19wa2dpbmZvX18ucHk= 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -4,7 +4,7 @@ modname = 'comment' distname = "cubicweb-%s" % modname -numversion = (1, 7, 1) +numversion = (1, 7, 2) version = '.'.join(str(num) for num in numversion) license = 'LGPL' @@ -19,7 +19,7 @@ 'Programming Language :: JavaScript', ] -__depends__ = {'cubicweb': '>= 3.9.0'} +__depends__ = {'cubicweb': '>= 3.10.0'} # packaging ### diff --git a/data/cubes.comment.js b/data/cubes.comment.js index 46ef47deb5f33cc40184e721a8d351f1b2598217_ZGF0YS9jdWJlcy5jb21tZW50Lmpz..082c8235ed099ad5bc662d1881a44799accadbce_ZGF0YS9jdWJlcy5jb21tZW50Lmpz 100644 --- a/data/cubes.comment.js +++ b/data/cubes.comment.js @@ -21,7 +21,7 @@ var ul = null; if (!commentNode.length) { // we are adding a comment to the top level entity - commentNode = $('#commentsectionComponent'); + commentNode = $('#commentsection' + eid); klass = 'comment'; } else { klass = 'section'; diff --git a/debian/changelog b/debian/changelog index 46ef47deb5f33cc40184e721a8d351f1b2598217_ZGViaWFuL2NoYW5nZWxvZw==..082c8235ed099ad5bc662d1881a44799accadbce_ZGViaWFuL2NoYW5nZWxvZw== 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cubicweb-comment (1.7.2-1) unstable; urgency=low + + * new upstream release + + -- Sylvain Thénault <sylvain.thenault@logilab.fr> Mon, 17 Jan 2011 14:33:11 +0100 + cubicweb-comment (1.7.1-1) unstable; urgency=low * new upstream release diff --git a/debian/control b/debian/control index 46ef47deb5f33cc40184e721a8d351f1b2598217_ZGViaWFuL2NvbnRyb2w=..082c8235ed099ad5bc662d1881a44799accadbce_ZGViaWFuL2NvbnRyb2w= 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Package: cubicweb-comment Architecture: all -Depends: cubicweb-common (>= 3.9.0) +Depends: cubicweb-common (>= 3.10.0) Description: comment component for the CubicWeb framework This CubicWeb component provides threadable comments. . diff --git a/setup.py b/setup.py index 46ef47deb5f33cc40184e721a8d351f1b2598217_c2V0dXAucHk=..082c8235ed099ad5bc662d1881a44799accadbce_c2V0dXAucHk= 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/env python -# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152 +# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611 +# # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr @@ -3,6 +4,22 @@ # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr - +# +# This file is part of CubicWeb tag cube. +# +# CubicWeb is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 2.1 of the License, or (at your option) +# any later version. +# +# CubicWeb is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. +"""Generic Setup script, takes package info from __pkginfo__.py file +""" __docformat__ = "restructuredtext en" import os @@ -12,6 +29,6 @@ try: if os.environ.get('NO_SETUPTOOLS'): - raise ImportError() + raise ImportError() # do as there is no setuptools from setuptools import setup from setuptools.command import install_lib @@ -16,6 +33,6 @@ from setuptools import setup from setuptools.command import install_lib - USE_SETUPTOOLS = 1 + USE_SETUPTOOLS = True except ImportError: from distutils.core import setup from distutils.command import install_lib @@ -19,5 +36,6 @@ except ImportError: from distutils.core import setup from distutils.command import install_lib - USE_SETUPTOOLS = 0 + USE_SETUPTOOLS = False +from distutils.command import install_data @@ -23,4 +41,2 @@ - -sys.modules.pop('__pkginfo__', None) # import required features @@ -26,20 +42,8 @@ # import required features -from __pkginfo__ import modname, version, license, description, \ - web, author, author_email -# import optional features -import __pkginfo__ -distname = getattr(__pkginfo__, 'distname', modname) -scripts = getattr(__pkginfo__, 'scripts', []) -data_files = getattr(__pkginfo__, 'data_files', None) -include_dirs = getattr(__pkginfo__, 'include_dirs', []) -ext_modules = getattr(__pkginfo__, 'ext_modules', None) -dependency_links = getattr(__pkginfo__, 'dependency_links', []) - -STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') - -IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') +from __pkginfo__ import modname, version, license, description, web, \ + author, author_email if exists('README'): long_description = file('README').read() else: long_description = '' @@ -41,6 +45,9 @@ if exists('README'): long_description = file('README').read() else: long_description = '' + +# import optional features +import __pkginfo__ if USE_SETUPTOOLS: @@ -46,7 +53,7 @@ if USE_SETUPTOOLS: - requires = {} - for entry in ("__depends__", "__recommends__"): - requires.update(getattr(__pkginfo__, entry, {})) - install_requires = [("%s %s" % (d, v and v or "")).strip() + requires = {} + for entry in ("__depends__",): # "__recommends__"): + requires.update(getattr(__pkginfo__, entry, {})) + install_requires = [("%s %s" % (d, v and v or "")).strip() for d, v in requires.iteritems()] else: @@ -51,6 +58,16 @@ for d, v in requires.iteritems()] else: - install_requires = [] + install_requires = [] + +distname = getattr(__pkginfo__, 'distname', modname) +scripts = getattr(__pkginfo__, 'scripts', ()) +include_dirs = getattr(__pkginfo__, 'include_dirs', ()) +data_files = getattr(__pkginfo__, 'data_files', None) +ext_modules = getattr(__pkginfo__, 'ext_modules', None) +dependency_links = getattr(__pkginfo__, 'dependency_links', ()) + +BASE_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') +IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') def ensure_scripts(linux_scripts): @@ -54,7 +71,8 @@ def ensure_scripts(linux_scripts): - """Creates the proper script names required for each platform + """ + Creates the proper script names required for each platform (taken from 4Suite) """ from distutils import util @@ -64,19 +82,4 @@ scripts_ = linux_scripts return scripts_ -def get_packages(directory, prefix): - """return a list of subpackages for the given directory""" - result = [] - for package in os.listdir(directory): - absfile = join(directory, package) - if isdir(absfile): - if exists(join(absfile, '__init__.py')) or \ - package in ('test', 'tests'): - if prefix: - result.append('%s.%s' % (prefix, package)) - else: - result.append(package) - result += get_packages(absfile, result[-1]) - return result - def export(from_dir, to_dir, @@ -82,5 +85,5 @@ def export(from_dir, to_dir, - blacklist=STD_BLACKLIST, + blacklist=BASE_BLACKLIST, ignore_ext=IGNORED_EXTENSIONS, verbose=True): """make a mirror of from_dir in to_dir, omitting directories and files @@ -134,6 +137,35 @@ dest = join(self.install_dir, base, directory) export(directory, dest, verbose=False) +# re-enable copying data files in sys.prefix +old_install_data = install_data.install_data +if USE_SETUPTOOLS: + # overwrite InstallData to use sys.prefix instead of the egg directory + class MyInstallData(old_install_data): + """A class that manages data files installation""" + def run(self): + _old_install_dir = self.install_dir + if self.install_dir.endswith('egg'): + self.install_dir = sys.prefix + old_install_data.run(self) + self.install_dir = _old_install_dir + try: + import setuptools.command.easy_install # only if easy_install avaible + # monkey patch: Crack SandboxViolation verification + from setuptools.sandbox import DirectorySandbox as DS + old_ok = DS._ok + def _ok(self, path): + """Return True if ``path`` can be written during installation.""" + out = old_ok(self, path) # here for side effect from setuptools + realpath = os.path.normcase(os.path.realpath(path)) + allowed_path = os.path.normcase(sys.prefix) + if realpath.startswith(allowed_path): + out = True + return out + DS._ok = _ok + except ImportError: + pass + def install(**kwargs): """setup entry point""" if USE_SETUPTOOLS: @@ -142,6 +174,7 @@ # install-layout option was introduced in 2.5.3-1~exp1 elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: sys.argv.remove('--install-layout=deb') - if USE_SETUPTOOLS and install_requires: + cmdclass = {'install_lib': MyInstallLib} + if USE_SETUPTOOLS: kwargs['install_requires'] = install_requires kwargs['dependency_links'] = dependency_links @@ -146,5 +179,8 @@ kwargs['install_requires'] = install_requires kwargs['dependency_links'] = dependency_links + kwargs['zip_safe'] = False + cmdclass['install_data'] = MyInstallData + return setup(name = distname, version = version, license = license, @@ -156,7 +192,7 @@ scripts = ensure_scripts(scripts), data_files = data_files, ext_modules = ext_modules, - cmdclass = {'install_lib': MyInstallLib}, + cmdclass = cmdclass, **kwargs ) diff --git a/test/unittest_comment.py b/test/unittest_comment.py index 46ef47deb5f33cc40184e721a8d351f1b2598217_dGVzdC91bml0dGVzdF9jb21tZW50LnB5..082c8235ed099ad5bc662d1881a44799accadbce_dGVzdC91bml0dGVzdF9jb21tZW50LnB5 100644 --- a/test/unittest_comment.py +++ b/test/unittest_comment.py @@ -13,7 +13,7 @@ self.b = req.create_entity('BlogEntry', title=u"yo", content=u"qu\'il est beau") def test_schema(self): - self.assertEquals(self.schema['comments'].rdef('Comment', 'BlogEntry').composite, + self.assertEqual(self.schema['comments'].rdef('Comment', 'BlogEntry').composite, 'object') def test_possible_views(self): @@ -31,7 +31,7 @@ self.create_user('user') # will commit rset = req.execute('Any X WHERE X is BlogEntry') actions = self.pactions(req, rset) - self.failUnless(('reply_comment', views.AddCommentAction) in actions) - self.failIf(('edit_comment', views.EditCommentAction) in actions) + self.assertTrue(('reply_comment', views.AddCommentAction) in actions) + self.assertFalse(('edit_comment', views.EditCommentAction) in actions) rset = req.execute('Any X WHERE X is Comment') actions = self.pactions(req, rset) @@ -36,8 +36,8 @@ rset = req.execute('Any X WHERE X is Comment') actions = self.pactions(req, rset) - self.failUnless(('reply_comment', views.ReplyCommentAction) in actions) - self.failUnless(('edit_comment', views.EditCommentAction) in actions) + self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions) + self.assertTrue(('edit_comment', views.EditCommentAction) in actions) cnx = self.login('user') req = self.request() rset = req.execute('Any X WHERE X is Comment') actions = self.pactions(req, rset) @@ -40,9 +40,9 @@ cnx = self.login('user') req = self.request() rset = req.execute('Any X WHERE X is Comment') actions = self.pactions(req, rset) - self.failUnless(('reply_comment', views.ReplyCommentAction) in actions) - self.failIf(('edit_comment', views.EditCommentAction) in actions) + self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions) + self.assertFalse(('edit_comment', views.EditCommentAction) in actions) rset = self.execute('INSERT Comment X: X content "ho bah non!", X comments B WHERE B is Comment') cnx.commit() actions = self.pactions(req, rset) @@ -46,9 +46,9 @@ rset = self.execute('INSERT Comment X: X content "ho bah non!", X comments B WHERE B is Comment') cnx.commit() actions = self.pactions(req, rset) - self.failUnless(('reply_comment', views.ReplyCommentAction) in actions) - self.failUnless(('edit_comment', views.EditCommentAction) in actions) + self.assertTrue(('reply_comment', views.ReplyCommentAction) in actions) + self.assertTrue(('edit_comment', views.EditCommentAction) in actions) cnx.rollback() cnx = self.login('anon') req = self.request() rset = req.execute('Any X WHERE X is Comment') @@ -51,8 +51,8 @@ cnx.rollback() cnx = self.login('anon') req = self.request() rset = req.execute('Any X WHERE X is Comment') - self.failUnlessEqual(self.pactions(req, rset), []) + self.assertEqual(self.pactions(req, rset), []) cnx.rollback() def test_nonregr_possible_actions(self): @@ -61,12 +61,12 @@ req.create_entity('Comment', content=u"Yooo!", comments=self.b) # now two comments are commenting the blog rset = self.b.related('comments', 'object') - self.assertEquals(len(rset), 2) - self.failUnless(self.vreg['actions'].select('reply_comment', req, rset=rset, row=0)) - self.failUnless(self.vreg['actions'].select('reply_comment', req, rset=rset, row=1)) + self.assertEqual(len(rset), 2) + self.assertTrue(self.vreg['actions'].select('reply_comment', req, rset=rset, row=0)) + self.assertTrue(self.vreg['actions'].select('reply_comment', req, rset=rset, row=1)) def test_add_related_actions(self): req = self.request() req.create_entity('Comment', content=u"bouh!", comments=self.b) self.create_user('user') # will comit rset = req.execute('Any X WHERE X is Comment') @@ -67,9 +67,9 @@ def test_add_related_actions(self): req = self.request() req.create_entity('Comment', content=u"bouh!", comments=self.b) self.create_user('user') # will comit rset = req.execute('Any X WHERE X is Comment') - self.failUnlessEqual(self.pactions_by_cats(req, rset), []) + self.assertEqual(self.pactions_by_cats(req, rset), []) cnx = self.login('user') rset = req.execute('Any X WHERE X is Comment') @@ -74,6 +74,6 @@ cnx = self.login('user') rset = req.execute('Any X WHERE X is Comment') - self.failUnlessEqual(self.pactions_by_cats(req, rset), []) + self.assertEqual(self.pactions_by_cats(req, rset), []) cnx.rollback() cnx = self.login('anon') rset = req.execute('Any X WHERE X is Comment') @@ -77,7 +77,7 @@ cnx.rollback() cnx = self.login('anon') rset = req.execute('Any X WHERE X is Comment') - self.failUnlessEqual(self.pactions_by_cats(req, rset), []) + self.assertEqual(self.pactions_by_cats(req, rset), []) cnx.rollback() def test_path(self): @@ -86,10 +86,10 @@ itreec1 = c1.cw_adapt_to('ITree') c11 = req.create_entity('Comment', content=u"duh?", comments=c1) itreec11 = c11.cw_adapt_to('ITree') - self.assertEquals(itreec1.path(), [self.b.eid, c1.eid]) - self.assertEquals(itreec1.root().eid, self.b.eid) - self.assertEquals(itreec11.path(), [self.b.eid, c1.eid, c11.eid]) - self.assertEquals(itreec11.root().eid, self.b.eid) + self.assertEqual(itreec1.path(), [self.b.eid, c1.eid]) + self.assertEqual(itreec1.root().eid, self.b.eid) + self.assertEqual(itreec11.path(), [self.b.eid, c1.eid, c11.eid]) + self.assertEqual(itreec11.root().eid, self.b.eid) def test_comments_ascending_order(self): req = self.request() @@ -97,5 +97,5 @@ c11 = req.create_entity('Comment', content=u"one-one", comments=c1) c12 = req.create_entity('Comment', content=u"one-two", comments=c1) c2 = req.create_entity('Comment', content=u"two", comments=self.b) - self.assertEquals([c.eid for c in self.b.reverse_comments], + self.assertEqual([c.eid for c in self.b.reverse_comments], [c1.eid, c2.eid]) @@ -101,5 +101,5 @@ [c1.eid, c2.eid]) - self.assertEquals([c.eid for c in c1.cw_adapt_to('ITree').children()], + self.assertEqual([c.eid for c in c1.cw_adapt_to('ITree').children()], [c11.eid, c12.eid]) def test_subcomments_count(self): @@ -108,7 +108,7 @@ c11 = req.create_entity('Comment', content=u"one-one", comments=c1) c12 = req.create_entity('Comment', content=u"one-two", comments=c1) c21 = req.create_entity('Comment', content=u"two-one", comments=c12) - self.assertEquals(c1.subcomments_count(), 3) + self.assertEqual(c1.subcomments_count(), 3) def test_fullthreadtext_views(self): req = self.request() @@ -120,7 +120,7 @@ content = c2.view('fullthreadtext') # remove date content = re.sub('..../../.. ..:..', '', content) - self.assertTextEquals(content, + self.assertMultiLineEqual(content, """\ > On - admin wrote : > bouh! @@ -132,9 +132,9 @@ i18n_by_author_field: admin url: http://testing.fr/cubicweb/blogentry/%s""" % self.b.eid) # fullthreadtext_descending view - self.assertTextEquals(re.sub('..../../.. ..:..', '', c.view('fullthreadtext_descending')), + self.assertMultiLineEqual(re.sub('..../../.. ..:..', '', c.view('fullthreadtext_descending')), '''On - admin wrote : bouh! > On - admin wrote : > some long **HTML** text which _should not_ fit on 80 characters, so i\'ll add > some extra xxxxxxx. Yeah ! @@ -136,9 +136,8 @@ '''On - admin wrote : bouh! > On - admin wrote : > some long **HTML** text which _should not_ fit on 80 characters, so i\'ll add > some extra xxxxxxx. Yeah ! - ''') diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py index 46ef47deb5f33cc40184e721a8d351f1b2598217_dGVzdC91bml0dGVzdF9ob29rcy5weQ==..082c8235ed099ad5bc662d1881a44799accadbce_dGVzdC91bml0dGVzdF9ob29rcy5weQ== 100644 --- a/test/unittest_hooks.py +++ b/test/unittest_hooks.py @@ -14,10 +14,10 @@ v = self.vreg['views'].select('notif_after_add_relation_comments', req, rset=c.cw_rset, row=0) content = v.render(row=0) - self.assertTextEquals(content, + self.assertMultiLineEqual(content, '''Yo ! i18n_by_author_field: admin url: http://testing.fr/cubicweb/blogentry/%s''' % c.comments[0].eid) @@ -18,10 +18,10 @@ '''Yo ! i18n_by_author_field: admin url: http://testing.fr/cubicweb/blogentry/%s''' % c.comments[0].eid) - self.assertEquals(v.subject(), 'new comment for blogentry une news !') + self.assertEqual(v.subject(), 'new comment for blogentry une news !') if __name__ == '__main__': diff --git a/views.py b/views.py index 46ef47deb5f33cc40184e721a8d351f1b2598217_dmlld3MucHk=..082c8235ed099ad5bc662d1881a44799accadbce_dmlld3MucHk= 100644 --- a/views.py +++ b/views.py @@ -212,7 +212,7 @@ def propose_to_login(self): self.w(u'<div class="warning">%s ' % self._cw._('You are not authenticated. Your comment will be anonymous if you do not <a onclick="showLoginBox()">login</a>.')) if 'registration' in self._cw.vreg.config.cubes(): - self.w(self.cw._(u' If you have no account, you may want to <a href="%s">create one</a>.') + self.w(self._cw._(u' If you have no account, you may want to <a href="%s">create one</a>.') % self._cw.build_url('register')) self.w(u'</div>') @@ -244,10 +244,10 @@ mainform=False)) form.add_subform(fvreg.select('edition', self._cw, entity=newcomment, mainform=False)) - self.w(u'<div id="comment%sSlot">%s</div>' % ( - commented.eid, form.render(formvalues=formvalues, - main_form_title=u'', - display_label=False))) + self.w(u'<div id="comment%sSlot">' % commented.eid) + form.render(w=self.w, formvalues=formvalues, + main_form_title=u'', display_label=False) + self.w(u'</div>') class InlineAddCommentFormView(InlineEditCommentFormView): @@ -273,8 +273,8 @@ # contextual components ######################################################## -class CommentSectionVComponent(component.EntityVComponent): +class CommentSectionVComponent(component.EntityCtxComponent): """a component to display a <div> html section including comments related to an object """ __regid__ = 'commentsection' @@ -277,9 +277,9 @@ """a component to display a <div> html section including comments related to an object """ __regid__ = 'commentsection' - __select__ = ((component.EntityVComponent.__select__ | match_kwargs('entity')) + __select__ = (component.EntityCtxComponent.__select__ & relation_possible('comments', 'object', 'Comment')) context = 'navcontentbottom' @@ -282,7 +282,7 @@ & relation_possible('comments', 'object', 'Comment')) context = 'navcontentbottom' - def entity_call(self, entity, view=None): + def render_body(self, w): req = self._cw req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') ) @@ -287,5 +287,6 @@ req = self._cw req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') ) + entity = self.entity addcomment = self._cw.vreg['actions'].select_or_none( 'reply_comment', req, entity=entity, rset=entity.cw_rset, row=entity.cw_row, col=entity.cw_col) @@ -298,6 +299,4 @@ rset = None if not (rset or addcomment): return - self.w(u'<div id="%s" class="%s" cubicweb:rooteid="%s">' % ( - self.div_id(), self.div_class(), entity.eid)) if rset.rowcount: @@ -303,4 +302,4 @@ if rset.rowcount: - self.w(u'<h4>%s</h4>' % (req._('Comment_plural'))) - self.w(u'<ul class="comment">') + w(u'<h4>%s</h4>' % (req._('Comment_plural'))) + w(u'<ul class="comment">') for i in xrange(rset.rowcount): @@ -306,5 +305,4 @@ for i in xrange(rset.rowcount): - self.wview('tree', rset, row=i) - self.w(u'</ul>') - self.w(u'</div>') + self.view('tree', rset, row=i, w=w) + w(u'</ul>') if addcomment is not None: @@ -310,5 +308,5 @@ if addcomment is not None: - self.w(u'<div id="comment%sHolder"></div>' % entity.eid) + w(u'<div id="comment%sHolder"></div>' % entity.eid) params = self.cw_extra_kwargs.copy() params.pop('view', None) params.pop('context', None) @@ -318,6 +316,6 @@ params['etype'] = entity.__regid__ url = req.ajax_replace_url( 'comment%sHolder' % entity.eid, vid='addcommentform', **params) - self.w(u' (<a href="%s">%s</a>)' % (xml_escape(url), req._(addcomment.title))) + w(u' (<a href="%s">%s</a>)' % (xml_escape(url), req._(addcomment.title))) @@ -322,4 +320,4 @@ -class UserLatestCommentsSection(component.EntityVComponent): +class UserLatestCommentsSection(component.EntityCtxComponent): """a section to display latest comments by a user""" @@ -325,4 +323,4 @@ """a section to display latest comments by a user""" - __select__ = component.EntityVComponent.__select__ & is_instance('CWUser') + __select__ = component.EntityCtxComponent.__select__ & is_instance('CWUser') __regid__ = 'latestcomments' @@ -327,9 +325,8 @@ __regid__ = 'latestcomments' - def cell_call(self, row, col, view=None): - user = self.cw_rset.get_entity(row, col) + def render_body(self, w): maxrelated = self._cw.property_value('navigation.related-limit') + 1 rset = self._cw.execute( 'Any C,CD,C,CCF ORDERBY CD DESC LIMIT %s WHERE C is Comment, ' 'C creation_date CD, C content CC, C content_format CCF, ' 'C created_by U, U eid %%(u)s' % maxrelated, @@ -331,7 +328,7 @@ maxrelated = self._cw.property_value('navigation.related-limit') + 1 rset = self._cw.execute( 'Any C,CD,C,CCF ORDERBY CD DESC LIMIT %s WHERE C is Comment, ' 'C creation_date CD, C content CC, C content_format CCF, ' 'C created_by U, U eid %%(u)s' % maxrelated, - {'u': user.eid}) + {'u': self.entity.eid}) if rset: @@ -337,13 +334,13 @@ if rset: - self.w(u'<div class="section">') - self.w(u'<h4>%s</h4>\n' % self._cw._('Latest comments').capitalize()) - self.wview('table', rset, - headers=[_('about'), _('on date'), - _('comment content')], - cellvids={0: 'commentroot', - 2: 'commentsummary', - }) - self.w(u'</div>') + w(u'<div class="section">') + w(u'<h4>%s</h4>\n' % self._cw._('Latest comments').capitalize()) + self.view('table', rset, w=w, + headers=[_('about'), _('on date'), + _('comment content')], + cellvids={0: 'commentroot', + 2: 'commentsummary', + }) + w(u'</div>') # adapters #####################################################################