예제 #1
0
 def hidden_fields(self, *fields):
     output = [literal('<tr><td></td><td colspan="2">')]
     output.append(literal('</td></tr>'))
     for field in fields:
         output.append(
             webhelpers.html.tags.hidden(field, value=self.values[field]))
     return literal('').join(output)
예제 #2
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     code = cgi.escape(request.GET.get('code', ''))
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     if resp:
         content = literal(resp.status)
         code = code or cgi.escape(str(resp.status_int))
     if not code:
         raise Exception('No status code was found')
     c.code = code
     c.message = content
     return render('/derived/error/document.html')
예제 #3
0
    def document(self):
        """Render the error document"""
        request = self._py_object.request
        resp = request.environ.get('pylons.original_response')
        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        c.message = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        c.code = request.GET.get('code', str(resp.status_int))
        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
                 message=content)

        return render("/errors/error.mako.html")
예제 #4
0
파일: error.py 프로젝트: kuba/SIS
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     c.code=cgi.escape(request.GET.get('code', str(resp.status_int)))
     c.message=content
     return render('error.xml')
예제 #5
0
    def document(self):
        """Render the error document - show custom template for 404"""
        self._disable_cache()
        resp = request.environ.get('pylons.original_response')

        # Don't do fancy error documents for JSON
        if resp.headers['Content-Type'] in [
                'text/javascript', 'application/json'
        ]:
            response.headers['Content-Type'] = resp.headers['Content-Type']
            return resp.body

        code = cgi.escape(request.GET.get('code', str(resp.status_int)))
        content = (literal(resp.body)
                   or cgi.escape(request.GET.get('message', '')))

        if code in self.rendered_error_codes:
            c.code = code
            message = content
            message = message.split('</h1>', 1)[-1]
            message = message.split('</body>', 1)[0]
            c.message = message.split('\n', 2)[-1]
            return render('../templates/%s.html' % code)
        else:
            page = error_document_template % \
                dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                     code=code,
                     message=content)
            return page
예제 #6
0
파일: error.py 프로젝트: fdgonthier/kas
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     c.code=cgi.escape(request.GET.get('code', str(resp.status_int)))
     c.message = content
     return render('error/error.mako')
예제 #7
0
    def userInfo(self):
        checkLogIn(session)

        c.site = "Projects"
        c.name = session['user_id']
        c.menu = genMenu(self)

        res = getUserData(c.name)

        c.lineData = [("Username", res[0]), ("Name", res[1]),
                ("Last name", res[2]), ("Email", res[3])]

        c.content = render("/line_by_line.html") + html.literal("<br />")

        c.header = ["All my projects"]

        proj = userProjects(c.name)

        c.rows = []
        for x in proj:
            url_old = urlparse(request.url)
            url = url_old.scheme +'://' + url_old.netloc + getProjectUrl(x[0])
            c.rows.append((link_to(x[0], url),))

        c.style = "width:70%; text-align: left" #XXX: move css to templates

        c.content += render("/table.html")

        return render("/temp.html")
예제 #8
0
파일: error.py 프로젝트: inpho/inphosite
    def document(self, filetype="html"):
        resp = request.environ.get("pylons.original_response")
        code = cgi.escape(request.GET.get("code", ""))
        content = cgi.escape(request.GET.get("message", ""))
        if resp:
            content = content or resp.body or literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception("No status code was found")

        req = request.environ.get("pylons.original_request")
        routing = req.environ.get("pylons.routes_dict")
        if routing:
            c.controller = routing.get("controller", None)
            c.id = routing.get("id", None)
            c.filetype = routing.get("filetype", "html")
            c.action = routing.get("action", "view")
        else:
            c.controller = None
            c.id = None
            c.filetype = "html"
            c.action = "view"

        c.code = code
        c.message = content
        return render("error." + c.filetype)
예제 #9
0
파일: base.py 프로젝트: Ayutac/SAUCE
 def bulk_actions(self):
     ''''Display bootstrap-styled action links respecting the allow_* properties'''
     bulk_actions = self._bulk_actions()
     if bulk_actions:
         return literal(u'<div class="btn-group">' + ''.join(bulk_actions) + '</div>')
     else:
         return u''
예제 #10
0
파일: error.py 프로젝트: ot4me/mematool
  def document(self):
    """Render the error document"""
    '''
          resp = request.environ.get('pylons.original_response')

    content = ''
    try:
      content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
    except:
      pass

    c.heading = content

    return render('/unauthorized.mako')
    '''
    request = self._py_object.request
    resp = request.environ.get('pylons.original_response')

    try:
        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))

        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
                 message=content)
    except:
      # resp can be None !
      # @TODO do log what happened here ... not normal
      redirect(url(controller='profile', action='index'))
      pass

    return page
예제 #11
0
파일: adapter.py 프로젝트: jean/NuPlone
    def show(self):
        """ Removes all status messages (including HTML) and returns them 
            for display.
        """
        context = self.context
        annotations = IAnnotations(context)
        msgs = annotations.get(STATUSMESSAGEKEY,
                                context.cookies.get(STATUSMESSAGEKEY))
        msgs = msgs and adapter._decodeCookieValue(msgs) or []

        html_msgs = annotations.get(HTMLMESSAGEKEY,
                                context.cookies.get(HTMLMESSAGEKEY))
        html_msgs = html_msgs and adapter._decodeCookieValue(html_msgs) or []

        for msg in html_msgs:
            msg.message = literal(sanitize(msg.message, cleaner=msgcleaner, wrap=None))

        value = msgs + html_msgs
        
        # clear the existing cookie entries, except on responses that don't
        # actually render in the browser (really, these shouldn't render
        # anything so we shouldn't get to this message, but some templates
        # are sloppy).
        if self.context.response.getStatus() not in (301, 302, 304):
            context.cookies[STATUSMESSAGEKEY] = None
            context.response.expireCookie(STATUSMESSAGEKEY, path='/')
            annotations[STATUSMESSAGEKEY] = None

            context.cookies[HTMLMESSAGEKEY] = None
            context.response.expireCookie(HTMLMESSAGEKEY, path='/')
            annotations[HTMLMESSAGEKEY] = None
        
        return value
예제 #12
0
    def test_it(self):
        from webhelpers.html.builder import literal
        project = testing.DummyResource(project_name=u'test-project')
        request = testing.DummyRequest()
        result = self._callFUT(request, project)

        self.assertEqual(result, literal(u'<a href="http://example.com/projects/test-project">test-project</a>'))
예제 #13
0
 def test_many(self):
     from webhelpers.html.builder import literal
     result = self._callFUT([("/", "HOME"), "Projects"])
     self.assertEqual(result, literal(u'<ul class="breadcrumb">'
         '<li><a href="/">HOME</a><span class="divider">/</span></li>'
         '<li class="active">Projects</li>'
         '</ul>'))
예제 #14
0
    def userInfo(self):
        checkLogIn(session)

        c.site = "Projects"
        c.name = session['user_id']
        c.menu = genMenu(self)

        res = getUserData(c.name)

        c.lineData = [("Username", res[0]), ("Name", res[1]),
                      ("Last name", res[2]), ("Email", res[3])]

        c.content = render("/line_by_line.html") + html.literal("<br />")

        c.header = ["All my projects"]

        proj = userProjects(c.name)

        c.rows = []
        for x in proj:
            url_old = urlparse(request.url)
            url = url_old.scheme + '://' + url_old.netloc + getProjectUrl(x[0])
            c.rows.append((link_to(x[0], url), ))

        c.style = "width:70%; text-align: left"  #XXX: move css to templates

        c.content += render("/table.html")

        return render("/temp.html")
예제 #15
0
    def show(self):
        """ Removes all status messages (including HTML) and returns them 
            for display.
        """
        context = self.context
        annotations = IAnnotations(context)
        msgs = annotations.get(STATUSMESSAGEKEY,
                               context.cookies.get(STATUSMESSAGEKEY))
        msgs = msgs and adapter._decodeCookieValue(msgs) or []

        html_msgs = annotations.get(HTMLMESSAGEKEY,
                                    context.cookies.get(HTMLMESSAGEKEY))
        html_msgs = html_msgs and adapter._decodeCookieValue(html_msgs) or []

        for msg in html_msgs:
            msg.message = literal(
                sanitize(msg.message, cleaner=msgcleaner, wrap=None))

        value = msgs + html_msgs

        # clear the existing cookie entries, except on responses that don't
        # actually render in the browser (really, these shouldn't render
        # anything so we shouldn't get to this message, but some templates
        # are sloppy).
        if self.context.response.getStatus() not in (301, 302, 304):
            context.cookies[STATUSMESSAGEKEY] = None
            context.response.expireCookie(STATUSMESSAGEKEY, path='/')
            annotations[STATUSMESSAGEKEY] = None

            context.cookies[HTMLMESSAGEKEY] = None
            context.response.expireCookie(HTMLMESSAGEKEY, path='/')
            annotations[HTMLMESSAGEKEY] = None

        return value
예제 #16
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     code = cgi.escape(request.GET.get('code', ''))
     content = cgi.escape(request.GET.get('message', ''))
     if request.environ.get('REQUEST_URI', '').startswith('/api'):
         response.headers['Content-Type'] = resp.headers['Content-Type']
         return resp.body or literal(resp.status)
     if resp:
         content = literal(resp.status)
         code = code or cgi.escape(str(resp.status_int))
     if not code:
         raise Exception(_('No status code found'))
     c.code = code
     c.message = content
     return self.render('/general/error.html')
예제 #17
0
 def document(self):
     """Render the error document"""
     icode = 404
     code= "404"
     status = "Not Found"
     resp = request.environ.get('pylons.original_response')
     if resp and resp.body:
         content = literal(resp.body)
     else:
         content = request.GET.get('message', '')
         if content:
             content = cgi.escape(content)
     if resp and resp.status_int: 
         icode = resp.status_int
         code = str(resp.status_int)
     elif request.GET.get('code', ''):
         code = request.GET.get('code')
         if code:
             code = cgi.escape(code)
         else:
             code = 404
     if resp and resp.status: 
         status = resp.status
     c.message = request.GET.get('message', '')
     if c.message:
         c.message = cgi.escape(c.message)
     else:
         c.message = content
     accept_list = None
     if 'HTTP_ACCEPT' in request.environ:
         try:
             accept_list = conneg_parse(request.environ['HTTP_ACCEPT'])
         except:
             accept_list= [MT("text", "plain")]
     if not accept_list:
         accept_list= [MT("text", "plain")]
     mimetype = accept_list.pop(0)
     while(mimetype):
         if str(mimetype).lower() in ["text/html", "text/xhtml"]:
             #page = error_document_template % \
             #dict(prefix=request.environ.get('SCRIPT_NAME', ''),
             #    code=code,
             #    message=content)
             #return page
             #c.status = status.replace(c.code, '').strip()
             return render('/error.html')
         elif str(mimetype).lower() in ["text/plain", "application/json"]:
             response.content_type = 'text/plain; charset="UTF-8"'
             response.status_int = icode
             response.status = status
             return content
         try:
             mimetype = accept_list.pop(0)
         except IndexError:
             mimetype = None
     #Whoops nothing satisfies - return text/plain
     response.content_type = 'text/plain; charset="UTF-8"'
     response.status_int = resp.status_int
     response.status = resp.status
     return content
예제 #18
0
    def document(self):
        """Render the error document - show custom template for 404"""
        self._disable_cache()
        resp = request.environ.get('pylons.original_response')

        # Don't do fancy error documents for JSON
        if resp.headers['Content-Type'] in ['text/javascript', 'application/json', 'text/csv']:
            response.headers['Content-Type'] = resp.headers['Content-Type']
            return resp.body

        code = cgi.escape(request.GET.get('code', str(resp.status_int)))
        content = (literal(resp.body) or
                   cgi.escape(request.GET.get('message', '')))

        if code in self.rendered_error_codes:
            c.code = code
            message = content
            message = message.split('</h1>', 1)[-1]
            message = message.split('</body>', 1)[0]
            c.message = message.split('\n', 2)[-1]
            return render('../templates/%s.html' % code)
        else:
            page = error_document_template % \
                dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                     code=code,
                     message=content)
            return page
예제 #19
0
 def url(self, name, value=None, id=None, **attrs):
     kw = {'type': 'text', 'maxlength': 150, 'class_': 'url'}
     kw.update(attrs)
     value = self.value(name, value)
     if value and value.startswith('http://'):
         value = value[len('http://'):]
     return literal(u'http://') + tags.text(name, value, id, **kw)
예제 #20
0
파일: error.py 프로젝트: PublicaMundi/ckan
 def document(self):
     """Render the error document"""
     original_request = request.environ.get('pylons.original_request')
     original_response = request.environ.get('pylons.original_response')
     # When a request (e.g. from a web-bot) is direct, not a redirect
     # from a page. #1176
     if not original_response:
         return 'There is no error.'
     # Bypass error template for API operations.
     if (original_request and
             (original_request.path.startswith('/api') or
              original_request.path.startswith('/fanstatic'))):
         return original_response.body
     # If the charset has been lost on the middleware stack, use the
     # default one (utf-8)
     if not original_response.charset and original_response.default_charset:
         original_response.charset = original_response.default_charset
     # Otherwise, decorate original response with error template.
     content = literal(original_response.unicode_body) or \
         cgi.escape(request.GET.get('message', ''))
     prefix = request.environ.get('SCRIPT_NAME', ''),
     code = cgi.escape(request.GET.get('code',
                       str(original_response.status_int))),
     extra_vars = {'code': code, 'content': content, 'prefix': prefix}
     return render('error_document_template.html', extra_vars=extra_vars)
예제 #21
0
 def submit(self,
            name='submit',
            value='Submit',
            id=None,
            cols=10,
            inner_cols=None,
            cancel=True,
            **attrs):
     """
     Outputs submit button.
     """
     id = id or name
     attrs = css_add_class(attrs, 'button')
     attrs = css_add_class(attrs, 'radius')
     if inner_cols:
         attrs = css_add_class(attrs, 'small-%d' % inner_cols)
     result = tags.submit(name, self.value(name, value), id, **attrs)
     if cancel and self.form.came_from:
         cancel_attrs = attrs.copy()
         cancel_attrs = css_add_class(cancel_attrs, 'secondary')
         result += literal(' ') + HTML.a(
             'Cancel', href=self.form.came_from, **cancel_attrs)
     if cols:
         return self.column(name, result, cols, inner_cols, errors=False)
     else:
         return result
예제 #22
0
 def url(self, name, value=None, id=None, **attrs):
     kw = {'type': 'text', 'maxlength': 150, 'class_': 'url'}
     kw.update(attrs)
     value = self.value(name, value)
     if value and value.startswith('http://'):
         value = value[len('http://'):]
     return literal(u'http://') + tags.text(name, value, id, **kw)
예제 #23
0
 def document(self):
     """Render the error document"""
     original_request = request.environ.get('pylons.original_request')
     original_response = request.environ.get('pylons.original_response')
     # When a request (e.g. from a web-bot) is direct, not a redirect
     # from a page. #1176
     if not original_response:
         return 'There is no error.'
     # Bypass error template for API operations.
     if (original_request
             and (original_request.path.startswith('/api')
                  or original_request.path.startswith('/fanstatic'))):
         return original_response.body
     # If the charset has been lost on the middleware stack, use the
     # default one (utf-8)
     if not original_response.charset and original_response.default_charset:
         original_response.charset = original_response.default_charset
     # Otherwise, decorate original response with error template.
     content = literal(original_response.unicode_body) or \
         cgi.escape(request.GET.get('message', ''))
     prefix = request.environ.get('SCRIPT_NAME', ''),
     code = cgi.escape(
         request.GET.get('code', str(original_response.status_int))),
     extra_vars = {'code': code, 'content': content, 'prefix': prefix}
     return render('error_document_template.html', extra_vars=extra_vars)
예제 #24
0
파일: error.py 프로젝트: chispita/aqua
    def document(self):
        function ='document'
        log.debug(function)

        """Render the error document"""
        resp = request.environ.get('pylons.original_response')
        log.debug('%s resp:%s' % (function, str(resp.status_int)))

        try:
            c.error_number = resp.status_int
            sentto = lca_info['webmaster_email']

            resp = request.environ.get('pylons.original_response')
            c.error_code = cgi.escape(request.GET.get('code', ''))
            content = cgi.escape(request.GET.get('message', ''))
            if resp:
                c.error_message  = literal(resp.status)

            email(sentto, render('error/error_email.mako'))
            return render('/error/%s.mako'%resp.status_int)
        except:

            email(sentto, render('error/error_email.mako'))
            return render('/error/500.mako')

            '''
예제 #25
0
 def custom_actions(self, obj):
     ''''Display bootstrap-styled action fields respecting the allow_* properties'''
     result = []
     count = 0
     try:
         result.append(u'<a href="' + obj.url +
                       '" class="btn btn-mini" title="Show">'
                       u'<i class="icon-eye-open"></i></a>')
         count += 1
     except:
         pass
     try:
         primary_fields = self.table_filler.__provider__.get_primary_fields(
             self.table_filler.__entity__)
         pklist = u'/'.join(
             map(lambda x: unicode(getattr(obj, x)), primary_fields))
         result.append(u'<a href="' + pklist +
                       '/edit" class="btn btn-mini" title="Edit">'
                       u'<i class="icon-pencil"></i></a>')
     except:
         pass
     if self.allow_delete:
         result.append(
             u'<a class="btn btn-mini btn-danger" href="./%d/delete" title="Delete">'
             u'  <i class="icon-remove icon-white"></i>'
             u'</a>' % (obj.id))
     return literal('<div class="btn-group" style="width: %dpx;">' %
                    (len(result) * 30) + ''.join(result) + '</div>')
예제 #26
0
    def document(self, filetype='html'):
        resp = request.environ.get('pylons.original_response')
        code = cgi.escape(request.GET.get('code', ''))
        content = cgi.escape(request.GET.get('message', ''))
        if resp:
            content = literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception('No status code was found')
        
        req = request.environ.get('pylons.original_request')
        routing = req.environ.get('pylons.routes_dict')
        if routing:
            c.controller = routing.get('controller', None)
            c.id = routing.get('id', None)
            c.filetype = routing.get('filetype', 'html')
            c.action = routing.get('action', 'view')
        else:
            c.controller = None
            c.id = None
            c.filetype = 'html'
            c.action = 'view'

        c.code = code
        c.message = content
        return render('error.' + c.filetype)
예제 #27
0
    def document(self, filetype='html'):
        resp = request.environ.get('pylons.original_response')
        code = cgi.escape(request.GET.get('code', ''))
        content = cgi.escape(request.GET.get('message', ''))
        if resp:
            content = content or resp.body or literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception('No status code was found')
        
        req = request.environ.get('pylons.original_request')
        routing = req.environ.get('pylons.routes_dict')
        if routing:
            c.controller = routing.get('controller', None)
            c.id = routing.get('id', None)
            c.filetype = routing.get('filetype', 'html')
            c.action = routing.get('action', 'view')
        else:
            c.controller = None
            c.id = None
            c.filetype = 'html'
            c.action = 'view'

        c.code = code
        c.message = content
        return render('error.' + c.filetype)
예제 #28
0
    def document(self):
        """Render the error document"""

        resp = request.environ.get("pylons.original_response")
        c.message = literal(resp.status)

        return render("/error.html")
예제 #29
0
def get_i18n_text(text_id):
    from pylons import tmpl_context as c
    text_obj = LanguageText.get(text_id, c.lang)
    if text_obj is None:
        text_obj = LanguageText.get(text_id, 'en')
    if text_obj is None:
        return ''
    return literal(text_obj.text)
예제 #30
0
파일: base.py 프로젝트: Ayutac/SAUCE
 def actions(self, obj):
     ''''Display bootstrap-styled action links respecting the allow_* properties'''
     actions = self._actions(obj)
     if actions:
         return literal(u'<div class="btn-group" style="width: %dpx;">'
             % (len(actions) * 30) + ''.join(actions) + u'</div>')
     else:
         return u''
예제 #31
0
파일: error.py 프로젝트: kodewulf/entourage
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message'))
     page = error_document_template % \
         dict(prefix=request.environ.get('SCRIPT_NAME', ''),
              code=cgi.escape(request.GET.get('code', str(resp.status_int))),
              message=content)
     return page
예제 #32
0
 def documentOld(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     page = error_document_template % \
         dict(prefix=request.environ.get('SCRIPT_NAME', ''),
              code=cgi.escape(request.GET.get('code', str(resp.status_int))),
              message=content)
     return page
예제 #33
0
파일: error.py 프로젝트: Pylons/kai
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     if not resp:
         abort(404)
     c.prefix = request.environ.get('SCRIPT_NAME', '')
     c.code = str(request.params.get('code', resp.status_int))
     c.message = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     return render('error.mako')
예제 #34
0
파일: error.py 프로젝트: AKSW/LODStats_WWW
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.status) or cgi.escape(request.GET.get('message', ''))
     c.prefix = request.environ.get('SCRIPT_NAME', '')
     c.code = cgi.escape(request.GET.get('code', str(resp.status_int)))
     c.message = content
     return render('/error.html')
예제 #35
0
 def sendOutput(self):
     html = literal("""\
     <div id="%(grid_id)s_holder" class="jqgrid_holder" style="%(holder_css)s">
         <div id="%(grid_id)s-errors" style="display: none;"></div>
         <table id="%(grid_id)s" cellpadding="0" cellspacing="0"></table>
         <div id="%(grid_pager_id)s"></div>
     </div>
     """)
     
     return html % {'grid_id': self.config['grid_id'], 'grid_pager_id': self.config['pager_id'], 'holder_css': ''}
예제 #36
0
    def display_field_by_name(self, idx, ignore_errors=False):
        field = self.fields[idx]
        ctx = self.context_for(field)
        if idx == 'assigned_to':
            self._add_current_value_to_user_field(field, ctx.get('value'))
        elif idx == 'custom_fields':
            field._custom_fields_values = ctx.get('value') or {}
            for cf in c.app.globals.custom_fields:
                if cf and cf.type == 'user':
                    val = ctx.get('value')
                    user = val.get(cf.name) if val else None
                    for f in field.fields:
                        if f.name == cf.name:
                            self._add_current_value_to_user_field(f, user)

        display = field.display(**ctx)
        if ctx['errors'] and field.show_errors and not ignore_errors:
            display += literal("<div class='error'>") + ctx['errors'] + literal("</div>")
        return display
예제 #37
0
 def document(self):
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     template = '<html><head><title>Error %(code)s</title></head><body><h1>Error %(code)s</h1><p>%(message)s</p></body></html>'
     template = template % dict(
         code=cgi.escape(request.GET.get('code', str(resp.status_int))), 
         message=content
         )
     return template
예제 #38
0
 def document(self):
     """
     Renders the error document.
     """
     resp = request.environ.get('pylons.original_response')
     c.message = literal(resp.body) or cgi.escape(
         request.GET.get('message', ''))
     c.code = cgi.escape(request.GET.get('code', str(resp.status_int)))
     response.headers = resp.headers
     return render('/error.mako')
예제 #39
0
    def display_field_by_name(self, idx, ignore_errors=False):
        field = self.fields[idx]
        ctx = self.context_for(field)
        if idx == 'assigned_to':
            self._add_current_value_to_user_field(field, ctx.get('value'))
        elif idx == 'custom_fields':
            field._custom_fields_values = ctx.get('value') or {}
            for cf in c.app.globals.custom_fields:
                if cf and cf.type == 'user':
                    val = ctx.get('value')
                    user = val.get(cf.name) if val else None
                    for f in field.fields:
                        if f.name == cf.name:
                            self._add_current_value_to_user_field(f, user)

        display = field.display(**ctx)
        if ctx['errors'] and field.show_errors and not ignore_errors:
            display += literal("<div class='error'>") + ctx['errors'] + literal("</div>")
        return display
예제 #40
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get("pylons.original_response")
     content = literal(resp.body) or cgi.escape(request.GET.get("message", ""))
     page = error_document_template % dict(
         prefix=request.environ.get("SCRIPT_NAME", ""),
         code=cgi.escape(request.GET.get("code", str(resp.status_int))),
         message=content,
     )
     return page
예제 #41
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     page = error_document_template % \
         dict(prefix=request.environ.get('SCRIPT_NAME', ''),
              code=cgi.escape(request.GET.get('code', str(resp.status_int))),
              message=content)
     import json
     return json.dumps({'OK':False, 'message':request.environ['pylons.controller.exception'].message})
예제 #42
0
파일: error.py 프로젝트: geonetix/eencms
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or \
         cgi.escape(request.GET.get('message', ''))
     page = error_document_template % \
         {'prefix': request.environ.get('SCRIPT_NAME', ''),
          'code': cgi.escape(request.GET.get('code', str(resp.status_int))),
          'message': content}
     return page
예제 #43
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     c.code = cgi.escape(request.GET.get('code', ''))
     c.content = cgi.escape(request.GET.get('message', ''))
     if resp:
         c.code = c.code or cgi.escape(str(resp.status_int))
         c.content = literal(resp.status)
     if not c.code:
         raise Exception('No status code found')
     return render('/error.htm')
예제 #44
0
파일: helpers.py 프로젝트: micheg/mediadrop
def doc_link(page=None, anchor="", text=N_("Help"), **kwargs):
    """Return a link (anchor element) to the documentation on the project site.

    XXX: Target attribute is not XHTML compliant.
    """
    attrs = {"href": "http://mediadrop.net/docs/user/%s.html#%s" % (page, anchor), "target": "_blank"}
    if kwargs:
        attrs.update(kwargs)
    attrs_string = " ".join(['%s="%s"' % (key, attrs[key]) for key in attrs])
    out = "<a %s>%s</a>" % (attrs_string, _(text))
    return literal(out)
예제 #45
0
    def colour(self, name, value=None, id=None, **attrs):
        kw = {'maxlength': 50, 'size': 20, 'class_': 'colour'}
        kw.update(attrs)
        kw['size'] = min((kw['maxlength'], kw['size']))

        id = id or name

        value = self.value(name, value)
        if value and value[0] == '#':
            value = value[1:]

        return literal('#') + tags.text(name, value, id, **kw)
예제 #46
0
    def document(self):
        """Render the error document"""
        resp = request.environ.get('pylons.original_response')

        #content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        #page = error_document_template % \
        #    dict(prefix=request.environ.get('SCRIPT_NAME', ''),
        #         code=cgi.escape(request.GET.get('code', str(resp.status_int))),
        #         message=content)
        
        response.content_type = 'application/json'
        return json.dumps({'error':literal(resp.body)})
예제 #47
0
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     code = cgi.escape(request.GET.get('code', ''))
     content = cgi.escape(request.GET.get('message', ''))
     if resp:
         content = literal(resp.status)
         code = code or cgi.escape(str(resp.status_int))
     if not code:
         raise Exception('No status code was found')
     c.code = code
     c.message = content
     return render('/derived/error/document.html')
예제 #48
0
 def document(self):
     self._setup_template_variables()
     """Render the error document"""
     original_request = request.environ.get('pylons.original_request')
     original_response = request.environ.get('pylons.original_response')
     # When a request (e.g. from a web-bot) is direct, not a redirect
     # from a page. #1176
     if not original_response:
         return 'There is no error.'
     # Bypass error template for API operations.
     if original_request and original_request.path.startswith('/api'):
         return original_response.body
     # Otherwise, decorate original response with error template.
     log.fatal("error-response: %s" %
               literal(original_response.unicode_body))
     log.fatal("cgi-escape: %s" %
               cgi.escape(request.GET.get('message', '')))
     c.content = literal(original_response.unicode_body) or cgi.escape(
         request.GET.get('message', ''))
     c.prefix = request.environ.get('SCRIPT_NAME', ''),
     c.code = cgi.escape(
         request.GET.get('code', str(original_response.status_int))),
     return render('error_document_template.html')
예제 #49
0
 def document(self):
     """Render the error document"""
     original_request = request.environ.get('pylons.original_request')
     original_response = request.environ.get('pylons.original_response')
     # Bypass error template for API operations.
     if original_request and original_request.path.startswith('/api'):
         return original_response.body
     # Otherwise, decorate original response with error template.
     c.content = literal(original_response.unicode_body) or cgi.escape(
         request.GET.get('message', ''))
     c.prefix = request.environ.get('SCRIPT_NAME', ''),
     c.code = cgi.escape(
         request.GET.get('code', str(original_response.status_int))),
     return render('error_document_template.html')
예제 #50
0
def doc_link(page=None, anchor='', text=N_('Help'), **kwargs):
    """Return a link (anchor element) to the documentation on the project site.

    XXX: Target attribute is not XHTML compliant.
    """
    attrs = {
        'href': 'http://mediadrop.video/docs/user/%s.html#%s' % (page, anchor),
        'target': '_blank',
    }
    if kwargs:
        attrs.update(kwargs)
    attrs_string = ' '.join(['%s="%s"' % (key, attrs[key]) for key in attrs])
    out = '<a %s>%s</a>' % (attrs_string, _(text))
    return literal(out)
예제 #51
0
    def document(self):
        """Render the error document"""
        config.setup_internal(model, c, session, request)
        # create recaptcha html
        self._new_captcha()
        self._load_metadata()

        resp = request.environ.get('pylons.original_response')
        c.error_message = "Page error dude, have fun"
        if resp is not None:
            c.code = cgi.escape(request.GET.get('code', str(resp.status_int)))
            c.error_message = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        c.page_error = True
        c.valid = False

        return render_mako('/pastebin/index.html')
예제 #52
0
    def _site_logo(self, hostname, default=None):

        if "avoindata" in hostname:
            hostname = "avoindata"
        elif "opendata" in hostname:
            hostname = "opendata"

        lang = helpers.lang() if helpers.lang() else "default"
        dict_key = hostname + "_" + lang

        logo = self.logos.get(dict_key, self.logos.get('default', None))

        if logo:
            return literal('<img src="%s" class="site-logo" />' % helpers.url_for_static("/images/logo/%s" % logo))
        else:
            return self._short_domain(hostname, default)
예제 #53
0
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     # Gotcha :
     #   When tested for test_account, sign-in after sign-in the
     #   request `message` seems to be absent. Something to do with
     #   multigate ???
     content = literal(resp.body)
     if not content:
         content = request.GET.get('message') or ''
         content = cgi.escape(content)
     #page = error_document_template % \
     #    dict(prefix=request.environ.get('SCRIPT_NAME', ''),
     #         code=cgi.escape(request.GET.get('code', str(resp.status_int))),
     #         message=content)
     #return page
     return content
    def callbacks(self):
        action_str = self.action_map.get(self.action, self.action)
        if self.feed:
            action = action_str[0].replace('[', '').replace(']', '')
        else:
            action = action_str[0]\
                .replace('[', '<span class="journal_highlight">')\
                .replace(']', '</span>')

        action_params_func = _no_params_func
        if callable(action_str[1]):
            action_params_func = action_str[1]

        # returned callbacks we need to call to get
        return [
            lambda: literal(action), action_params_func,
            self.action_parser_icon]
예제 #55
0
파일: error.py 프로젝트: samyisok/orphereus
    def document(self):
        """Render the error document"""
        resp = request.environ.get('pylons.original_response')
        message = literal(resp.status) or cgi.escape(
            request.GET.get('message'))
        params = dict(
            prefix=request.environ.get('SCRIPT_NAME', ''),
            code=cgi.escape(request.GET.get('code', str(resp.status_int))),
            message=message,
            errorPic="%serror.png" % g.OPT.staticPathWeb,
        )
        """
        params = dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.params.get('code', '')),
                 message=cgi.escape(request.params.get('message', '')),
                 errorPic="%serror.png" % g.OPT.staticPathWeb,
                 )
        """
        #page = error_document_template % params
        #return page
        out = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Orphereus: misfunction. %(code)s</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <meta name="robots" content="noarchive" />
        <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    </head>
    <body style='background-color: #eb6d00;'>
    <div style="text-align:center;">
        <img src='%(errorPic)s' alt = 'Orphie-kun' style="border: 2px solid #820000;"/>
        <h1 style='color: #ffffff;'>I'm awfully sorry, my dear user.</h1>
        <h2 style='color: #ffffff;'>I'm feeling</h2>
        <h1 style="color: #820000; background-color: #FADDDD;">%(message)s
        <br/>
        <a href="http://trac.anoma.ch">Visit Bugtracker</a></h1>
        <br/>
        %(prefix)s
    </div>
    </body>
</html>
"""
        out = out % params
        return out
예제 #56
0
def wrap_long_words(string, _encode_entities=True):
    """Inject <wbr> periodically to let the browser wrap the string.

    The <wbr /> tag is widely deployed and included in HTML5,
    but it isn't XHTML-compliant. See this for more info:
    http://dev.w3.org/html5/spec/text-level-semantics.html#the-wbr-element

    :type string: unicode
    :rtype: literal
    """
    if _encode_entities:
        string = encode_entities(string)
    def inject_wbr(match):
        groups = match.groups()
        return u'%s<wbr />%s' % (groups[0], groups[-1])
    string = long_words.sub(inject_wbr, string)
    string = u'.<wbr />'.join(string.split('.'))
    return literal(string)
예제 #57
0
    def document(self):
        """Render the error document"""
        resp = request.environ.get('pylons.original_response')
        if resp is not None:
            unicode_body = str2unicode(resp.body)
            content = literal(unicode_body)
        else:
            message = request.GET.get('message',
                                      request.POST.get('message', ''))
            content = cgi.escape(message)

        code = request.GET.get(
            'code', request.POST.get('code', unicode(resp.status_int)))

        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(code),
                 message=content)
        return page
예제 #58
0
    def document(self):
        """Render the error document"""
        resp = request.environ.get('pylons.original_response')
        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
                 message=content)
        if request.environ.has_key('pylons.controller.exception'):
            import json
            try:
                response.headers.update(request.environ['pylons.controller.exception'].headers)
            except:
                pass

            return json.dumps({'OK':False, 'message':str(request.environ['pylons.controller.exception'].message)})
        else:
            response.headers['Content-Type'] = 'text/html; charset=utf-8'
            return page