예제 #1
0
 def get_full_path(self, url=None):
     url = url or self.url
     qs = self.environ.get('QUERY_STRING', '')
     if url == self.path and qs:
         return url + '?' + iri_to_uri(qs)
     else:
         return url
예제 #2
0
 def get_full_path(self, url=None):
     url = url or self.url
     qs = self.environ.get('QUERY_STRING', '')
     if url == self.path and qs:
         return url + '?' + iri_to_uri(qs)
     else:
         return url
예제 #3
0
 def build_absolute_uri(self, location=None):
     """
     Builds an absolute URI from the location and the variables available in
     this request. If no location is specified, the absolute URI is built on
     ``request.get_full_path()``.
     """
     if not location:
         location = self.get_full_path()
     if not absolute_http_url_re.match(location):
         current_uri = '%s://%s%s' % (self.is_secure and 'https' or 'http',
                                      self.get_host(), self.path)
         location = urljoin(current_uri, location)
     return iri_to_uri(location)
예제 #4
0
 def build_absolute_uri(self, location=None):
     """
     Builds an absolute URI from the location and the variables available in
     this request. If no location is specified, the absolute URI is built on
     ``request.get_full_path()``.
     """
     if not location:
         location = self.get_full_path()
     if not absolute_http_url_re.match(location):
         current_uri = '%s://%s%s' % (self.is_secure and 'https'
                                      or 'http', self.get_host(), self.path)
         location = urljoin(current_uri, location)
     return iri_to_uri(location)
예제 #5
0
def page_links(request, asbuttons=False, ul=None):
    '''Utility for displaying page navigation links.'''
    ul = ul if ul is not None else html.Widget('ul')
    view = request.view
    Page = view.Page
    if Page:
        # We are on a page application view
        if view.mapper == Page:
            page = request.instance
            if page:
                route = Route(page.url)
                urlargs = dict(request.GET.items())
                try:
                    path = route.url(**urlargs)
                except:
                    path = '/'
                a = html.anchor_or_button('exit',
                                          href=path,
                                          icon='exit-page-edit',
                                          asbutton=asbuttons)
                ul.add(a)
        else:
            page = request.page
            page_request = request.for_model(Page)
            if page_request is not None:
                if page:
                    kwargs = {NEXT_KEY: request.path}
                    include = ('change',)
                else:
                    kwargs = {'url': request.view.path}
                    include = ('add',)
                for link in views.application_views_links(
                                    page_request,
                                    instance=page,
                                    include=include,
                                    asbuttons=asbuttons):
                    kwargs.update(request.urlargs)
                    href = link.attrs['href']
                    link.attrs['href'] = iri_to_uri(href, kwargs)
                    ul.add(link)
    return ul
예제 #6
0
 def to_url(self, value):
     return iri_to_uri(value)
예제 #7
0
파일: site.py 프로젝트: pombredanne/djpcms
    def handle_error(self, request, response):
        '''Render an error into text or Html depending on *content_type*.
This function can be overwritten by user implementation.'''
        exc_info = request.exc_info
        settings = request.settings
        status = 500
        if exc_info and exc_info[0] is not None:
            status = getattr(exc_info[1], 'status', status)
        else:
            exc_info = None
        # 302 is a special case, we redirect
        content_type = request.content_type
        if status in REDIRECT_CODES:
            location = dict(exc_info[1].headers)['location']
            if request.is_xhr:
                content = ajax.jredirect(request.environ, location)
            else:
                content_type = None
                response.headers['Location'] = iri_to_uri(location)
                content = ''
        else:
            err_cls = '%s%s' % (classes.error, status)
            err_title = '%s %s' % (status, error_title(status))
            if content_type == 'text/plain':
                content = err_title
                if settings.DEBUG:
                    content += '\n\n' + html_trace(exc_info, plain=True)
            else:
                inner = Widget('div', cn=(classes.error, err_cls))
                if settings.DEBUG:
                    inner.addClass('debug')
                    inner.add(Widget('h2', err_title))
                    inner.add(Widget('a', request.path, href=request.path))
                    inner.add(html_trace(exc_info))
                else:
                    func_name = 'render_error_%s' % status
                    if hasattr(self, func_name):
                        text = getattr(self, func_name)(request, status)
                    else:
                        text = error_title
                    inner.add(text)
                if request.is_xhr:
                    content = ajax.jservererror(request.environ,
                                                inner.render(request))
                else:
                    try:
                        layout = request.view.root.get_page_layout(err_cls,
                                                                   classes.error,
                                                                   'default')
                        outer = layout()
                        content = outer.render(request,
                                               context={'content': inner})
                    except:
                        logger.error('Could not render %s error on %s layout',
                                     status, layout, exc_info=True)
                        content = inner.render(request)
        if is_renderer(content):
            response.status_code = 200
            response.content_type = content.content_type()
            content = content.render(request)
        else:
            response.content_type = content_type
            response.status_code = status
        if status == 500:
            logger.critical('Interval server error', exc_info=exc_info)
        return content
예제 #8
0
 def to_url(self, value):
     return iri_to_uri(value)
예제 #9
0
파일: site.py 프로젝트: pombredanne/djpcms
    def handle_error(self, request, response):
        '''Render an error into text or Html depending on *content_type*.
This function can be overwritten by user implementation.'''
        exc_info = request.exc_info
        settings = request.settings
        status = 500
        if exc_info and exc_info[0] is not None:
            status = getattr(exc_info[1], 'status', status)
        else:
            exc_info = None
        # 302 is a special case, we redirect
        content_type = request.content_type
        if status in REDIRECT_CODES:
            location = dict(exc_info[1].headers)['location']
            if request.is_xhr:
                content = ajax.jredirect(request.environ, location)
            else:
                content_type = None
                response.headers['Location'] = iri_to_uri(location)
                content = ''
        else:
            err_cls = '%s%s' % (classes.error, status)
            err_title = '%s %s' % (status, error_title(status))
            if content_type == 'text/plain':
                content = err_title
                if settings.DEBUG:
                    content += '\n\n' + html_trace(exc_info, plain=True)
            else:
                inner = Widget('div', cn=(classes.error, err_cls))
                if settings.DEBUG:
                    inner.addClass('debug')
                    inner.add(Widget('h2', err_title))
                    inner.add(Widget('a', request.path, href=request.path))
                    inner.add(html_trace(exc_info))
                else:
                    func_name = 'render_error_%s' % status
                    if hasattr(self, func_name):
                        text = getattr(self, func_name)(request, status)
                    else:
                        text = error_title
                    inner.add(text)
                if request.is_xhr:
                    content = ajax.jservererror(request.environ,
                                                inner.render(request))
                else:
                    try:
                        layout = request.view.root.get_page_layout(
                            err_cls, classes.error, 'default')
                        outer = layout()
                        content = outer.render(request,
                                               context={'content': inner})
                    except:
                        logger.error('Could not render %s error on %s layout',
                                     status,
                                     layout,
                                     exc_info=True)
                        content = inner.render(request)
        if is_renderer(content):
            response.status_code = 200
            response.content_type = content.content_type()
            content = content.render(request)
        else:
            response.content_type = content_type
            response.status_code = status
        if status == 500:
            logger.critical('Interval server error', exc_info=exc_info)
        return content