Changeset 41

Show
Ignore:
Timestamp:
01/29/07 00:22:31 (5 years ago)
Author:
tim
Message:

Genshi snippets in feeds seem to render properly at this point.

Location:
trunk/cogplanet
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/cogplanet/admin/controller.py

    r29 r41  
    6767    def entry(self, id): 
    6868        entry = Entry.selectone(Entry.c.id==id) 
    69         print entry.content 
    7069        planet = Planet.selectone() 
    7170        return({'entry':entry, 
  • trunk/cogplanet/model.py

    r29 r41  
    99from BeautifulSoup import BeautifulSoup 
    1010from genshi.input import ParseError 
    11 from genshi.template import MarkupTemplate 
     11from genshi.template import MarkupTemplate, Template 
    1212 
    1313import logging 
    1414log = logging.getLogger("cogplanet.model") 
    1515 
     16class NoopEvalFilter(object): 
     17    """A no-op eval filter for Genshi -- expressions pass through without evaluation""" 
     18     
     19    def __call__(self, stream, context=None): 
     20        for kind, data, pos in stream: 
     21            if kind is Template.EXPR: 
     22                yield data.source 
     23            else: 
     24                yield kind, data, pos 
     25                 
    1626class Planet(ActiveMapper): 
    1727    class mapping: 
     
    6474                entry.original = e['content'][0]['value'] 
    6575            soup = BeautifulSoup("<div>%s</div>" % entry.original) 
    66             original = soup.prettify() 
     76            htmlsoup = soup.prettify() 
    6777 
    6878            try: 
    69                 mt = MarkupTemplate(original) 
     79                mt = MarkupTemplate(htmlsoup) 
     80                for f in mt.filters: 
     81                    if f.im_func.func_name == '_eval': 
     82                        mt.filters.remove(f) 
     83                mt.filters.append(NoopEvalFilter()) 
    7084                stream = mt.generate() 
    7185                rendered = stream.render('xhtml') 
    72                 entry.content = original 
     86                entry.content = htmlsoup 
    7387                entry.parsed = True 
    7488            except ParseError, pe: 
  • trunk/cogplanet/tests/test_controllers.py

    r1 r41  
    11from turbogears import testutil 
    2 from cogplanet.controllers import Root 
     2# from cogplanet.controllers import Root 
    33import cherrypy 
    44 
    5 cherrypy.root = Root() 
     5# cherrypy.root = Root() 
    66 
    7 def test_method(): 
    8     "the index method should return a string called now" 
    9     import types 
    10     result = testutil.call(cherrypy.root.index) 
    11     assert type(result["now"]) == types.StringType 
     7# def test_method(): 
     8#     "the index method should return a string called now" 
     9#     import types 
     10#     result = testutil.call(cherrypy.root.index) 
     11#     assert type(result["now"]) == types.StringType 
    1212 
    13 def test_indextitle(): 
    14     "The mainpage should have the right title" 
    15     testutil.createRequest("/") 
    16     assert "<TITLE>Welcome to TurboGears</TITLE>" in cherrypy.response.body[0] 
     13# def test_indextitle(): 
     14#     "The mainpage should have the right title" 
     15#     testutil.createRequest("/") 
     16#     assert "<TITLE>Welcome to TurboGears</TITLE>" in cherrypy.response.body[0] 
  • trunk/cogplanet/tests/test_model.py

    r39 r41  
    4141    model = Feed 
    4242 
    43     # def test_refresh_invalid_entries(self): 
    44     #         "Invalid feed entries should not halt processing" 
     43    def test_refresh_invalid_entries(self): 
     44            "Invalid feed entries should not halt processing" 
    4545     
    46     #         feed = Feed() 
    47     #         feed.xmlurl = "./cogplanet/tests/invalid_entries.rss" 
    48     #         feed.refresh_entries() 
    49     #         assert len(feed.entries) == 5 
     46            feed = Feed() 
     47            feed.xmlurl = "./cogplanet/tests/invalid_entries.rss" 
     48            feed.refresh_entries() 
     49            assert len(feed.entries) == 10 
    5050 
    5151    def test_utf8_characters_in_feed(self): 
     
    5353        trans = session.create_transaction() 
    5454        feed = Feed() 
    55         # feed.xmlurl = "./cogplanet/tests/utf8_feed.xml" 
    56         feed.xmlurl = "http://feeds.feedburner.com/caskey" 
     55        feed.xmlurl = "./cogplanet/tests/utf8_feed.xml" 
     56        # feed.xmlurl = "http://feeds.feedburner.com/caskey" 
    5757        feed.refresh_entries() 
    5858        trans.commit() 
     
    6666            rendered = MarkupTemplate(entry.content).generate().render('xhtml') 
    6767            print rendered 
     68 
     69    def test_genshi_in_feed(self): 
     70        "Feeds with Genshi/Kid code in the entries should import and display correctly" 
     71        feed = Feed() 
     72        feed.xmlurl = "./cogplanet/tests/genshi_feed.xml" 
     73        feed.refresh_entries()