Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1126 (closed defect: wontfix)

Opened 12 years ago

Last modified 8 years ago

cannot use genshi template with a widget

Reported by: max Owned by: anonymous
Priority: normal Milestone: 1.5
Component: TG Widgets Version: 1.0b1
Severity: normal Keywords: genshi widget template plugin
Cc:

Description

I've declared a widget that uses Genshi for templating:

class SimpleDataGrid(widgets.DataGrid):
    template = 'genshi:spaca.templates.simplegrid'
    javascript = [widgets.mochikit, widgets.JSLink('spaca', 'spa_summary.js')]

At render time TurboGears produces an exception:

File 'D:\\Projects\\Spaca\\spaca\\templates\\related_something.py', line 86 in _pull
File 'c:\\python24\\lib\\site-packages\\TurboGears-1.0b1-py2.4.egg\\turbogears\\widgets\\meta.py', line 107 in lockwidget
  output = self.__class__.display(self, *args, **kw)
File 'c:\\python24\\lib\\site-packages\\TurboGears-1.0b1-py2.4.egg\\turbogears\\widgets\\base.py', line 226 in display
  return view.engines.get('kid').transform(params, self.template_c)
File 'c:\\python24\\lib\\site-packages\\TurboKid-0.9.8-py2.4.egg\\turbokid\\kidsupport.py', line 162 in transform
  tclass = self.load_template(template)
File 'c:\\python24\\lib\\site-packages\\TurboKid-0.9.8-py2.4.egg\\turbokid\\kidsupport.py', line 68 in load_template
  "%s.kid" % basename)
File 'c:\\python24\\lib\\site-packages\\setuptools-0.6c3-py2.4.egg\\pkg_resources.py', line 799 in resource_filename
  return get_provider(package_or_requirement).get_resource_filename(
File 'c:\\python24\\lib\\site-packages\\setuptools-0.6c3-py2.4.egg\\pkg_resources.py', line 119 in get_provider
  __import__(moduleOrReq)
exceptions.ImportError: ('No module named genshi:spaca.templates', <function _wrapper at 0x01A36FB0>)

Change History

comment:1 Changed 12 years ago by alberto

  • Status changed from new to closed
  • Resolution set to wontfix

This is a feature targeted at 1.1. It's currently only implemented in trunk, not in 1.0b1.

If you're using trunk already please reopen.

A note to our Trac admins: A new version category for trunk would eb a good idea :)

comment:2 Changed 12 years ago by jeffk

  • Status changed from closed to reopened
  • Component changed from unassigned to genshi
  • Version changed from 1.0b1 to trunk
  • Milestone set to 1.1
  • Keywords genshi added
  • Resolution wontfix deleted

(reopening, retargeting version per request, ready to use genshi templates with widgets against trunk)

Using a quickstarted identity app 'tgtest', quickstarted with TurboGears trunk, I'd like to start with a simple user widget, with tests.

Added files:

tgtest\widgets\__init__.py
               widgets.py

tgtest\widgets\templates\__init__.py
                         user.html

tgtest\tests\test_widgets.py

Added file contents:

tgtest\widgets\__init__.py:

from widgets import *

tgtest\widgets\widgets.py:

from turbogears.widgets import Widget


class UserWidget(Widget):
    template        = 'genshi:tgtest.widgets.templates.user'
    params          = ['user']

user_widget = UserWidget()

tgtest\widgets\widgets\templates\__init__.py: (blank)

tgtest\widgets\widgets\templates\user.html:

<li xmlns="http://www.w3.org/1999/xhtml"
    xmlns:py="http://genshi.edgewall.org/"
    xmlns:xi="http://www.w3.org/2001/XInclude">${user.display_name}</li>

tgtest\tests\test_widgets.py:

from turbogears import testutil, database
from tgtest.model import User
from tgtest.widgets import UserWidget


class TestUserWidget(testutil.DBTest):
    def get_model(self):
        return User

    def setUp(self):
        "Intialise test database with one User"
        testutil.DBTest.setUp(self)
        User(user_name = 'testuser',
             email_address = 'test.user@acme.com',
             display_name = 'Test User',
             password = 'wordpass')

    def test_creation(self):
        "setUp should create user"
        user = User.get(1)
        assert user.display_name == 'Test User'
        widget = UserWidget(user)

    def test_render(self):
        "render widget using setUp created user"
        user = User.get(1)
        assert user.display_name == 'Test User'
        widget = UserWidget(user)
        rendered = widget.render()
        print rendered
        assert 'Test User</li>' in rendered

As the project was quickstarted against trunk, genshi templates are already the default.

$ egrep -r --include=*.cfg 'genshi|kid|widgets' .
./tgtest/config/app.cfg:tg.defaultview = "genshi"
./tgtest/config/app.cfg:# The following genshi settings determine the settings used by the genshi serializer.
./tgtest/config/app.cfg:# genshi.outputformat="html"
./tgtest/config/app.cfg:# referenced by the templates?  Note that genshi's default is "ascii".
./tgtest/config/app.cfg:# genshi.assume_encoding="utf-8"
./tgtest/config/app.cfg:# genshi.encoding="utf-8"
./tgtest/config/app.cfg:# tg.include_widgets = []

The following AttributeError? is raised:

$ nosetests
.............E
======================================================================
ERROR: render widget using setUp created user
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/software/tgtest/tgtest/tests/test_widgets.py", line 29, in test_render
    rendered = widget.render()
  File "/software/svn/turbogears11/turbogears/widgets/base.py", line 320, in render
    template = self.template_c,
  File "/usr/lib/python2.4/site-packages/TurboKid-0.9.9-py2.4.egg/turbokid/kidsupport.py", line 158, in render
    tclass = self.load_template(template)
  File "/usr/lib/python2.4/site-packages/TurboKid-0.9.9-py2.4.egg/turbokid/kidsupport.py", line 77, in load_template
    divider = classname.rfind(".")
AttributeError: 'MarkupTemplate' object has no attribute 'rfind'

----------------------------------------------------------------------
Ran 14 tests in 3.799s

FAILED (errors=1)

comment:3 Changed 12 years ago by alberto

The widgets' support for genshi in the trunk is probably broken in other parts too because it was an experiment which later lead to ToscaWidgets?. I'll probably revert changes on the trunk widgets to sync them with 1.0's. TW are going to replace 1.0 widgets in 2.0 so you're probably better off using them instead if you need genshi widgets.

I'll probably tag the trunk as 1.1 because it is going to suffer major overhaul soon when work on 2.0 begins. It'll probably remain in a unusable state for a while until major functionality is ported from 1.1.

1.1 Should remain fully compatible with 1.0 and serve as a stepping stone to 2.0.

I wouldn't recommend running off the trunk ATM.

Alberto

comment:4 Changed 12 years ago by alberto

  • Milestone changed from 1.1 to __unclassified__

Batch moved into unclassified from 1.1 to properly track progress on the later

comment:5 Changed 11 years ago by Chris Arndt

  • Status changed from reopened to closed
  • Resolution set to wontfix
  • Version changed from trunk to 1.0b1
  • Component changed from genshi to Widgets

TG widgets only support Kid templates. ToscaWidgets supports multiple template engines.

comment:6 Changed 8 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.5

TG 1.5 widgets now also support Genshi templates. If it's not working there, please reopen.

Note: See TracTickets for help on using tickets.