web/views/basecontrollers.py
branchstable
changeset 1838 d4cbcc15c01c
parent 1798 cc86fe8efaaa
child 1839 2cdd0d1d3888
equal deleted inserted replaced
1837:67fcc174d299 1838:d4cbcc15c01c
    16 from logilab.common.decorators import cached
    16 from logilab.common.decorators import cached
    17 
    17 
    18 from cubicweb import NoSelectableObject, ValidationError, ObjectNotFound, typed_eid
    18 from cubicweb import NoSelectableObject, ValidationError, ObjectNotFound, typed_eid
    19 from cubicweb.utils import strptime
    19 from cubicweb.utils import strptime
    20 from cubicweb.selectors import yes, match_user_groups
    20 from cubicweb.selectors import yes, match_user_groups
    21 from cubicweb.view import STRICT_DOCTYPE
    21 from cubicweb.view import STRICT_DOCTYPE, STRICT_DOCTYPE_NOEXT
    22 from cubicweb.common.mail import format_mail
    22 from cubicweb.common.mail import format_mail
    23 from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, json_dumps
    23 from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, json_dumps
    24 from cubicweb.web.formrenderers import FormRenderer
    24 from cubicweb.web.formrenderers import FormRenderer
    25 from cubicweb.web.controller import Controller
    25 from cubicweb.web.controller import Controller
    26 from cubicweb.web.views import vid_from_rset
    26 from cubicweb.web.views import vid_from_rset
    30     HAS_SEARCH_RESTRICTION = True
    30     HAS_SEARCH_RESTRICTION = True
    31 except ImportError: # gae
    31 except ImportError: # gae
    32     HAS_SEARCH_RESTRICTION = False
    32     HAS_SEARCH_RESTRICTION = False
    33 
    33 
    34 
    34 
    35 def xhtml_wrap(source):
    35 def xhtml_wrap(self, source):
    36     head = u'<?xml version="1.0"?>\n' + STRICT_DOCTYPE
    36     # XXX factor out, watch view.py ~ Maintemplate.doctype
       
    37     if self.req.xhtml_browser():
       
    38         dt = STRICT_DOCTYPE
       
    39     dt = STRICT_DOCTYPE_NOEXT
       
    40     head = u'<?xml version="1.0"?>\n' + dt
    37     return head + u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">%s</div>' % source.strip()
    41     return head + u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">%s</div>' % source.strip()
    38 
    42 
    39 def jsonize(func):
    43 def jsonize(func):
    40     """decorator to sets correct content_type and calls `simplejson.dumps` on
    44     """decorator to sets correct content_type and calls `simplejson.dumps` on
    41     results
    45     results
    49 def xhtmlize(func):
    53 def xhtmlize(func):
    50     """decorator to sets correct content_type and calls `xmlize` on results"""
    54     """decorator to sets correct content_type and calls `xmlize` on results"""
    51     def wrapper(self, *args, **kwargs):
    55     def wrapper(self, *args, **kwargs):
    52         self.req.set_content_type(self.req.html_content_type())
    56         self.req.set_content_type(self.req.html_content_type())
    53         result = func(self, *args, **kwargs)
    57         result = func(self, *args, **kwargs)
    54         return xhtml_wrap(result)
    58         return xhtml_wrap(self, result)
    55     wrapper.__name__ = func.__name__
    59     wrapper.__name__ = func.__name__
    56     return wrapper
    60     return wrapper
    57 
    61 
    58 def check_pageid(func):
    62 def check_pageid(func):
    59     """decorator which checks the given pageid is found in the
    63     """decorator which checks the given pageid is found in the