Changeset 1504

Show
Ignore:
Timestamp:
03/25/08 10:16:18 (2 years ago)
Author:
JensDiemer
Message:

headline_anchor: work-a-round for unicode problems

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/middlewares/headline_anchor.py

    r1503 r1504  
    2727 
    2828HEADLINE = ( 
    29     '<h%(no)s id="%(anchor)s">' 
     29    u'<h%(no)s id="%(anchor)s">' 
    3030    '<a title="Link to this section" href="%(link)s#%(anchor)s" class="anchor">' 
    3131    '%(txt)s</a>' 
     
    3535 
    3636class HeadlineAnchor(object): 
    37     def process_view(self, request, view_func, view_args, view_kwargs): 
     37    def process_response(self, request, response): 
    3838        """ 
    39         Add 
     39        Add anchors to every html headlines. 
    4040        """ 
    41         # start the view 
    42         response = view_func(request, *view_args, **view_kwargs) 
    43  
    4441        # Put only the statistic into HTML pages 
    4542        if not "html" in response._headers["content-type"][1]: 
     
    6057        self.anchor_list = [] 
    6158 
     59        content = response.content 
     60        if not isinstance(content, unicode): 
     61            # FIXME: In my shared webhosting environment is response.content a 
     62            # string and not unicode. Why? 
     63            from django.utils.encoding import force_unicode 
     64            try: 
     65                content = force_unicode(content) 
     66            except: 
     67                return response 
     68 
    6269        # add the anchor with re.sub 
    63         content = response.content 
    6470        new_content = HEADLINE_RE.sub(self.add_anchor, content) 
    6571        response.content = new_content