コード例 #1
0
ファイル: __init__.py プロジェクト: ManchesterIO/mollyproject
def sanitise_html(dirty_html, opener=None, device=None):
    html = etree.fromstring("<div>%s</div>" % dirty_html,
                            parser = etree.HTMLParser())
    html = transform(html, 'external_media/html_sanitiser.xslt')

    # serialize and remove the div tag
    return etree.tostring(html, method='html')[5:-6]
コード例 #2
0
ファイル: __init__.py プロジェクト: nicosiseng/mollyproject
def sanitise_html(dirty_html, opener=None, device=None):
    html = etree.fromstring("<div>%s</div>" % dirty_html,
                            parser=etree.HTMLParser())
    html = transform(html, 'external_media/html_sanitiser.xslt')

    # serialize and remove the div tag
    return etree.tostring(html, method='html')[5:-6]
コード例 #3
0
    def initial_context(self, request, id):
        url = self.build_url('direct/eval-evaluation/%s' % id)
        data = request.raw_post_data if request.method == 'POST' else None
        with make_sakai_request(SAKAI_TIMEOUT):
            response = request.urlopen(url, data)
        evaluation = etree.parse(response,
                                 parser=etree.HTMLParser(recover=False))
        evaluation = transform(evaluation, 'sakai/evaluation/detail.xslt',
                               {'id': id})

        # The evaluations tool doesn't give us a non-OK status if we need to authenticate. Instead,
        # we need to check for the login box (handily picked out by the XSL stylesheet).
        if evaluation.find('.//require_auth').text == 'true':
            raise OAuthHTTPError(
                urllib2.HTTPError(url, 403, _('Authentication required'), {},
                                  StringIO()))

        context = {
            'evaluation': evaluation,
            'id': id,
            'url': url,
            'response_url': response.geturl(),
        }
        add_children_to_context(evaluation, context)
        return context
コード例 #4
0
 def initial_context(self, request):
     summary = self.get_sakai_resource(
         'direct/eval-evaluation/1/summary',
         format='xml',
         parser=etree.HTMLParser(recover=False))
     summary = transform(summary, 'sakai/evaluation/summary.xslt',
                         {'id': id})
     evaluations = []
     for node in summary.findall('evaluation'):
         if not node.find('title').text is None:
             evaluations.append({
                 'title':
                 node.find('title').text,
                 'site':
                 node.find('site').text,
                 'start':
                 node.find('start').text,
                 'end':
                 node.find('end').text,
                 'status':
                 node.find('status').text,
                 'id':
                 urlparse.parse_qs(
                     urlparse.urlparse(
                         node.find('url').text).query)['evaluationId'][0]
                 if node.find('url') is not None else None,
             })
     return {
         'evaluations': evaluations,
     }
コード例 #5
0
def sanitise_html(dirty_html, opener=None, device=None):
    html = etree.fromstring("<div>%s</div>" % dirty_html, parser = etree.HTMLParser())
    html = transform(html, 'external_media/html_sanitiser.xslt')
    
    #if True or device:
    #    for element in html.findall(".//img[@externalmedia]"):
    #        print element

    return etree.tostring(html, method='html')[5:-6] # serialize and remove the div tag
コード例 #6
0
def sanitize_html(value, args=''):
    document = etree.fromstring(u'<body>%s</body>' % value, parser = etree.HTMLParser())

    args = args.split(',') + [None, None]
    id_prefix, class_prefix = args[0] or 'sani', args[1] or 'sani'

    document = transform(document, 'utils/sanitize_html.xslt', {
        'id_prefix': id_prefix,
        'class_prefix': class_prefix,
    })
    return SafeUnicode(etree.tostring(document)[6:-7])
コード例 #7
0
def sanitize_html(value, args=''):
    document = etree.fromstring(u'<body>%s</body>' % value,
                                parser=etree.HTMLParser())

    args = args.split(',') + [None, None]
    id_prefix, class_prefix = args[0] or 'sani', args[1] or 'sani'

    document = transform(document, 'utils/sanitize_html.xslt', {
        'id_prefix': id_prefix,
        'class_prefix': class_prefix,
    })
    return SafeUnicode(etree.tostring(document)[6:-7])
コード例 #8
0
ファイル: views.py プロジェクト: alexliyu/mollyproject
 def initial_context(self, request):
     summary = self.get_sakai_resource('direct/eval-evaluation/1/summary',
             format='xml', parser=etree.HTMLParser(recover=False))
     summary = transform(summary, 'sakai/evaluation/summary.xslt', {'id': id})
     evaluations = []
     for node in summary.findall('evaluation'):
         if not node.find('title').text is None:
             evaluations.append({
                 'title': node.find('title').text,
                 'site': node.find('site').text,
                 'start': node.find('start').text,
                 'end': node.find('end').text,
                 'status': node.find('status').text,
                 'id': urlparse.parse_qs(urlparse.urlparse(node.find('url').text).query)['evaluationId'][0] if node.find('url') is not None else None,
             })
     return {
         'evaluations': evaluations,
     }
コード例 #9
0
ファイル: views.py プロジェクト: bloomonkey/mollyproject
    def initial_context(self, request, id):
        url = self.build_url('direct/eval-evaluation/%s' % id)
        data = request.raw_post_data if request.method == 'POST' else None
        response = request.urlopen(url, data)
        evaluation = etree.parse(response, parser = etree.HTMLParser(recover=False))
        evaluation = transform(evaluation, 'sakai/evaluation/detail.xslt', {'id': id})

        # The evaluations tool doesn't give us a non-OK status if we need to authenticate. Instead,
        # we need to check for the login box (handily picked out by the XSL stylesheet).
        if evaluation.find('.//require_auth').text == 'true':
            raise OAuthHTTPError(urllib2.HTTPError(url, 403, 'Authentication required', {}, StringIO.StringIO()))

        context = {
            'evaluation': evaluation,
            'id': id,
            'url': url,
            'response_url': response.geturl(),
        }
        add_children_to_context(evaluation, context)
        return context
コード例 #10
0
ファイル: views.py プロジェクト: nicosiseng/mollyproject
class EvaluationIndexView(SakaiView):
    force_auth = True

    @BreadcrumbFactory
    def breadcrumb(self, request, context):
        return Breadcrumb(
            self.conf.local_name,
            lazy_parent('index'),
            'Surveys',
            lazy_reverse('evaluation-index'),
        )

    def initial_context(self, request):
        try:
            url = self.build_url('direct/eval-evaluation/1/summary')
            summary = etree.parse(request.opener.open(url), parser = etree.HTMLParser(recover=False))
        except urllib2.HTTPError, e:
            if e.code == 404:
                raise Http404
            elif e.code == 403:
                raise PermissionDenied
            else:
                raise

        summary = transform(summary, 'sakai/evaluation/summary.xslt', {'id': id})

        evaluations = []
        for node in summary.findall('evaluation'):
            evaluations.append({
                'title': node.find('title').text,
                'site': node.find('site').text,
                'start': node.find('start').text,
                'end': node.find('end').text,
                'status': node.find('status').text,
                'id': urlparse.parse_qs(urlparse.urlparse(node.find('url').text).query)['evaluationId'][0] if node.find('url') is not None else None,
            })

        return {
            'evaluations': evaluations,
            'submitted': request.GET.get('submitted') == 'true',
        }