Exemplo n.º 1
0
def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe(html)
Exemplo n.º 2
0
def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe('<div class="rich-text">' + html + '</div>')
Exemplo n.º 3
0
def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe('<div class="rich-text">' + html + '</div>')
Exemplo n.º 4
0
    def get_html(news_stories, additional_link_params, header_html, extra_html,
                 footer_html):
        html = "<html><head></head><body>" + header_html
        html = html + "<ul>"
        for news_story in news_stories.order_by('-story_date'):
            url = 'https://loop.lib.uchicago.edu' + news_story.url_path.replace(
                '/loop', '',
                1) + '?' + urllib.parse.urlencode(additional_link_params)
            html = html + "<li><a href='" + url + "'>"
            html = html + news_story.title
            html = html + "</a></li>"
        html = html + "</ul>"
        html = html + extra_html
        html = html + footer_html
        html = html + "</body></html>"

        # rough pass to clean strangely nested elements.
        soup = BeautifulSoup(html, "lxml")

        # do more cleanup work.
        html = clean_html(str(soup))

        # get the real links for things like documents and internal pages.
        html = expand_db_html(html)

        return html
Exemplo n.º 5
0
def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ""

    return mark_safe(html)
Exemplo n.º 6
0
def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET

    # The passed HTML may be a string or bytes, depending on what is calling
    # this method. For example, Django response.content is always bytes. We
    # always want this content to be a string for our purposes.
    html_as_text = force_text(html, encoding=encoding)

    # This call invokes Wagail-specific logic that converts references to
    # Wagtail pages, documents, and images to their proper link URLs.
    expanded_html = expand_db_html(html_as_text)

    soup = BeautifulSoup(expanded_html, 'html.parser')
    link_tags = get_link_tags(soup)
    for tag in link_tags:
        original_link = str(tag)
        link_with_markup = add_link_markup(tag)
        if link_with_markup:
            expanded_html = expanded_html.replace(
                original_link,
                link_with_markup
            )

    return expanded_html
Exemplo n.º 7
0
def raw(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe(html)
Exemplo n.º 8
0
 def render(self, name, value, attrs=None):
     if value is None:
         translated_value = None
     else:
         translated_value = expand_db_html(value, for_editor=True)
     return super(HalloRichTextArea, self).render(name, translated_value,
                                                  attrs)
Exemplo n.º 9
0
 def render(self, name, value, *args, **kwargs):
     if value is None:
         translated_value = None
     elif wagtail_version == 2:
         translated_value = self.converter.from_database_format(value)
     else:
         translated_value = expand_db_html(value, for_editor=True)
     return super().render(name, translated_value, *args, **kwargs)
Exemplo n.º 10
0
 def render(self, name, value, attrs=None):
     if value is None:
         translated_value = None
     else:
         if WAGTAIL_VERSION >= '2.0':
             translated_value = self.converter.from_database_format(value)
         else:
             translated_value = expand_db_html(value, for_editor=True)
     return super(TinyMCERichTextArea, self).render(name, translated_value, attrs)
Exemplo n.º 11
0
Arquivo: models.py Projeto: pdflu/CPDB
    def extended_body(self):
        body = json.loads(self.serializable_data()['body'])

        for row in body:
            if row['type'] == 'row_section':
                for paragraph in row['value']:
                    paragraph['value'] = expand_db_html(paragraph['value'])

        return body
Exemplo n.º 12
0
def simplerichtext(value):
    if isinstance(value, RichText):
        # passing a RichText value through the |richtext filter should have no effect
        return value
    elif value is None:
        html = ''
    else:
        html = expand_db_html(value)

    return mark_safe(html)
Exemplo n.º 13
0
def richtext(value):
    if isinstance(value, RichText):
        # passing a RichText value through the |richtext filter should have no effect
        return value
    elif value is None:
        html = ''
    else:
        html = expand_db_html(value)

    return mark_safe('<div class="rich-text">' + html + '</div>')
Exemplo n.º 14
0
def simplerichtext(value):
    """
    Simple richtext filter to avoid the wrapping <div class='richtext'></div> markup
    """
    if isinstance(value, SimpleRichText):
        html = value
    elif value is None:
        html = ""
    else:
        html = expand_db_html(value)

    return mark_safe(html)
Exemplo n.º 15
0
def simplerichtext(value):
    """
    Simple richtext filter to avoid the wrapping <div class='richtext'></div> markup
    """
    if isinstance(value, SimpleRichText):
        html = value
    elif value is None:
        html = ''
    else:
        html = expand_db_html(value)

    return mark_safe(html)
Exemplo n.º 16
0
 def test_expand_db_html_with_embed(self, oembed):
     oembed.return_value = {
         "title": "test title",
         "author_name": "test author name",
         "provider_name": "test provider name",
         "type": "test type",
         "thumbnail_url": "test thumbnail url",
         "width": "test width",
         "height": "test height",
         "html": "test html",
     }
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn("test html", result)
Exemplo n.º 17
0
def parse_links(value):
    if isinstance(value, RichText):
        soup = BeautifulSoup(expand_db_html(value.source), 'html.parser')
    else:
        soup = BeautifulSoup(expand_db_html(value), 'html.parser')

    # This removes style tags <style>
    for s in soup('style'):
        s.decompose()

    # This removes all inline style attr's
    for tag in soup.recursiveChildGenerator():
        try:
            del tag['style']
        except TypeError:
            # 'NavigableString' object has does not have attr's
            pass

    # This adds the link markup
    link_tags = get_link_tags(soup)
    add_link_markup(link_tags)

    return soup
Exemplo n.º 18
0
 def test_expand_db_html_with_embed(self, oembed):
     oembed.return_value = {
         'title': 'test title',
         'author_name': 'test author name',
         'provider_name': 'test provider name',
         'type': 'test type',
         'thumbnail_url': 'test thumbnail url',
         'width': 'test width',
         'height': 'test height',
         'html': 'test html'
     }
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
Exemplo n.º 19
0
def parse_links(value):
    if isinstance(value, RichText):
        soup = BeautifulSoup(expand_db_html(value.source), 'html.parser')
    else:
        soup = BeautifulSoup(expand_db_html(value), 'html.parser')

    # This removes style tags <style>
    for s in soup('style'):
        s.decompose()

    # This removes all inline style attr's
    for tag in soup.recursiveChildGenerator():
        try:
            del tag['style']
        except:
            # 'NavigableString' object has does not have attr's
            pass

    # This adds the link markup
    link_tags = get_link_tags(soup)
    add_link_markup(link_tags)

    return soup
Exemplo n.º 20
0
 def test_expand_db_html_with_embed(self, oembed):
     oembed.return_value = {
         'title': 'test title',
         'author_name': 'test author name',
         'provider_name': 'test provider name',
         'type': 'test type',
         'thumbnail_url': 'test thumbnail url',
         'width': 'test width',
         'height': 'test height',
         'html': 'test html'
     }
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
Exemplo n.º 21
0
def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET
    html = html.decode(encoding)
    html = expand_db_html(html)
    soup = BeautifulSoup(html, 'html.parser')
    link_tags = get_link_tags(soup)
    for tag in link_tags:
        original_link = str(tag)
        link_with_markup = add_link_markup(tag)
        if link_with_markup:
            html = html.replace(original_link, link_with_markup)

    return html.encode(encoding)
Exemplo n.º 22
0
def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET
    html = html.decode(encoding)
    html = expand_db_html(html)
    soup = BeautifulSoup(html, 'html.parser')
    link_tags = get_link_tags(soup)
    for tag in link_tags:
        original_link = str(tag)
        link_with_markup = add_link_markup(tag)
        if link_with_markup:
            html = html.replace(original_link, link_with_markup)

    return html.encode(encoding)
Exemplo n.º 23
0
 def accessible_links(html):
     """
     Makes footer links with surrounding text accessible
     to screen readers by adding an aria-label attribute
     containing the full text of the footer item to the link.
     """
     soup = BeautifulSoup(expand_db_html(html), 'html.parser')
     for p in soup.find_all('p'):
         if p.find_all('a'):
             for child in p.children:
                 if child.name == 'a':
                     if child.string != p.text:
                         child['aria-label'] = p.text
                 else:
                     if child.name != 'span':
                         child = child.wrap(soup.new_tag('span'))
                     child['aria-hidden'] = 'true'
     return text_type(soup).replace(u'\xa0', ' ')
Exemplo n.º 24
0
def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET

    # The passed HTML may be a string or bytes, depending on what is calling
    # this method. For example, Django response.content is always bytes. We
    # always want this content to be a string for our purposes.
    html_as_text = force_text(html, encoding=encoding)

    # This call invokes Wagail-specific logic that converts references to
    # Wagtail pages, documents, and images to their proper link URLs.
    expanded_html = expand_db_html(html_as_text)

    link_tags = get_link_tags(expanded_html)
    for tag in link_tags:
        tag_with_markup = add_link_markup(tag)
        if tag_with_markup:
            expanded_html = expanded_html.replace(tag, tag_with_markup)

    return expanded_html
Exemplo n.º 25
0
    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        if use_feed_image:
            feed_image = item.feed_image
            if feed_image:
                image_complete_url = urljoin(
                    self.get_site_url(), feed_image.file.url
                )
            else:
                image_complete_url = ""

        content_field = getattr(item, self.item_content_field)
        try:
            content = expand_db_html(content_field)
        except:
            content = content_field.__html__()

        soup = BeautifulSoup(content, 'html.parser')
        # Remove style attribute to remove large botton padding
        for div in soup.find_all("div", {'class': 'responsive-object'}):
            del div['style']
        # Add site url to image source
        for img_tag in soup.findAll('img'):
            if img_tag.has_attr('src'):
                img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        fields_to_add = {
            'content': soup.prettify(formatter="html"),
        }

        if use_feed_image:
            fields_to_add['image'] = image_complete_url
        else:
            fields_to_add['image'] = ""

        return fields_to_add
Exemplo n.º 26
0
    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        feed_image = item.feed_image
        if feed_image:
            filter, _ = Filter.objects.get_or_create(spec='width-1200')
            img = feed_image.get_rendition(filter)

            image_complete_url = urljoin(self.get_site_url(), img.url)

        content = expand_db_html(getattr(item, self.item_content_field))
        soup = BeautifulSoup(content, 'html.parser')
        for img_tag in soup.findAll('img'):
            img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        return {
            'image': image_complete_url if feed_image else "",
            'content': soup.prettify(formatter="html")
        }
Exemplo n.º 27
0
    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        if use_feed_image:
            feed_image = item.feed_image
            if feed_image:
                image_complete_url = urljoin(self.get_site_url(),
                                             feed_image.file.url)
            else:
                image_complete_url = ""

        content_field = getattr(item, self.item_content_field)
        try:
            content = expand_db_html(content_field)
        except:
            content = content_field.__html__()

        soup = BeautifulSoup(content, 'html.parser')
        # Remove style attribute to remove large botton padding
        for div in soup.find_all("div", {'class': 'responsive-object'}):
            del div['style']
        # Add site url to image source
        for img_tag in soup.findAll('img'):
            if img_tag.has_attr('src'):
                img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        fields_to_add = {
            'content': soup.prettify(formatter="html"),
        }

        if use_feed_image:
            fields_to_add['image'] = image_complete_url
        else:
            fields_to_add['image'] = ""

        return fields_to_add
Exemplo n.º 28
0
    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        feed_image = item.feed_image
        if feed_image:
            filter, _ = Filter.objects.get_or_create(spec='width-1200')
            img = feed_image.get_rendition(filter)

            image_complete_url = urljoin(self.get_site_url(), img.url)

        content = expand_db_html(getattr(item, self.item_content_field))
        soup = BeautifulSoup(content, 'html.parser')
        for img_tag in soup.findAll('img'):
            img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        return {
            'image': image_complete_url if feed_image else "",
            'content': soup.prettify(formatter="html")
        }
Exemplo n.º 29
0
    def get_html(news_stories, additional_link_params, header_html, extra_html, footer_html):
        html = "<html><head></head><body>" + header_html
        html = html + "<ul>"
        for news_story in news_stories.order_by('-story_date'):
            url = 'https://loop.lib.uchicago.edu' + news_story.url_path.replace('/loop', '', 1) + '?' + urllib.parse.urlencode(additional_link_params)
            html = html + "<li><a href='" + url + "'>"
            html = html + news_story.title 
            html = html + "</a></li>"
        html = html + "</ul>"
        html = html + extra_html
        html = html + footer_html
        html = html + "</body></html>"

        # rough pass to clean strangely nested elements.
        soup = BeautifulSoup(html, "lxml")

        # do more cleanup work. 
        html = clean_html(str(soup))

        # get the real links for things like documents and internal pages. 
        html = expand_db_html(html)

        return html
Exemplo n.º 30
0
 def __str__(self):
     return mark_safe(expand_db_html(self.source))
Exemplo n.º 31
0
def external_links_filter(value):
    if isinstance(value, RichText):
        return parse_links(
            BeautifulSoup(expand_db_html(value.source), 'html.parser'))
    return value
Exemplo n.º 32
0
 def item_description(self, item):
     return expand_db_html(item.body)
Exemplo n.º 33
0
def richtext(value):
    return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
Exemplo n.º 34
0
 def test_expand_db_html_no_linktype(self):
     html = '<a id="1">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a id="1">foo</a>')
Exemplo n.º 35
0
 def item_content(self, item):
     return expand_db_html(item.body)
Exemplo n.º 36
0
 def test_expand_db_html_no_linktype(self):
     html = '<a id="1">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a id="1">foo</a>')
Exemplo n.º 37
0
 def render(self, name, value, attrs=None):
     if value is None:
         translated_value = None
     else:
         translated_value = expand_db_html(value, for_editor=True)
     return super(HalloRichTextArea, self).render(name, translated_value, attrs)
Exemplo n.º 38
0
def richtext(value):
    return mark_safe('<div class="rich-text">' + expand_db_html(value) +
                     '</div>')
Exemplo n.º 39
0
def richtext(value):
    return mark_safe(expand_db_html(value))
Exemplo n.º 40
0
 def __html__(self):
     return expand_db_html(self.source)
 def test_expand_db_html_with_embed(self, get_embed):
     from wagtail.wagtailembeds.models import Embed
     get_embed.return_value = Embed(html='test html')
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
Exemplo n.º 42
0
 def render_basic(self, value):
     return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
Exemplo n.º 43
0
 def test_expand_db_html_with_embed(self, get_embed):
     from wagtail.wagtailembeds.models import Embed
     get_embed.return_value = Embed(html='test html')
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
Exemplo n.º 44
0
 def test_expand_db_html_with_linktype(self):
     html = '<a id="1" linktype="document">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a>foo</a>')
Exemplo n.º 45
0
 def test_expand_db_html_with_linktype(self):
     html = '<a id="1" linktype="document">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a>foo</a>')
Exemplo n.º 46
0
 def get_context(self, request, page):
     from wagtail.wagtailcore.rich_text import expand_db_html
     context = super().get_context(request, page)
     context['content'] = expand_db_html(self.body)
     return context
Exemplo n.º 47
0
 def render_basic(self, value):
     return mark_safe('<div class="rich-text">' + expand_db_html(value) +
                      '</div>')
Exemplo n.º 48
0
 def __str__(self):
     return mark_safe(expand_db_html(self.source))
Exemplo n.º 49
0
 def to_representation(self, value):
     return expand_db_html(value)