prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  StreamField EmbedBlock renders the url only
  Given the following setup:
  
  ```
  class EmbedOnImage(StructBlock):
      embed = EmbedBlock()
      background_image = ImageChooserBlock(required=False)
  
      class Meta:
          template = 'streamfield_blocks/embed_on_image.html'
  ```
  
  `{{ self.embed }}` outputs the embed url only in `streamfield_blocks/embed_on_image.html`.
  
  And `EmbedBlock.render_basic` is never called: https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailembeds/blocks.py#L8
  
  Also, if I apply the embed filter too: `{{ self.embed|embed }}` then it outputs nothing because the embed filter won't call `embed_to_frontend_html` either, which would use the correct template to render it: https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py#L14
  
  
  </issue>
  <code>
  [start of wagtail/wagtailembeds/blocks.py]
  1 from wagtail.wagtailcore import blocks
  2 
  3 from wagtail.wagtailembeds.format import embed_to_frontend_html
  4 
  5 
  6 class EmbedBlock(blocks.URLBlock):
  7     def render_basic(self, value):
  8         return embed_to_frontend_html(value)
  9
  [end of wagtail/wagtailembeds/blocks.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/wagtail/wagtailembeds/blocks.py b/wagtail/wagtailembeds/blocks.py
  --- a/wagtail/wagtailembeds/blocks.py
  +++ b/wagtail/wagtailembeds/blocks.py
  @@ -1,8 +1,62 @@
  +from django.utils.encoding import python_2_unicode_compatible
  +
   from wagtail.wagtailcore import blocks
   
   from wagtail.wagtailembeds.format import embed_to_frontend_html
   
   
  +@python_2_unicode_compatible
  +class EmbedValue(object):
  +    """
  +    Native value of an EmbedBlock. Should, at minimum, have a 'url' property
  +    and render as the embed HTML when rendered in a template.
  +    NB We don't use a wagtailembeds.model.Embed object for this, because
  +    we want to be able to do {{ value.url|embed:max_width=500 }} without
  +    doing a redundant fetch of the embed at the default width.
  +    """
  +    def __init__(self, url):
  +        self.url = url
  +
  +    def __str__(self):
  +        return embed_to_frontend_html(self.url)
  +
  +
   class EmbedBlock(blocks.URLBlock):
  -    def render_basic(self, value):
  -        return embed_to_frontend_html(value)
  +    def get_default(self):
  +        # Allow specifying the default for an EmbedBlock as either an EmbedValue or a string (or None).
  +        if not self.meta.default:
  +            return None
  +        elif isinstance(self.meta.default, EmbedValue):
  +            return self.meta.default
  +        else:
  +            # assume default has been passed as a string
  +            return EmbedValue(self.meta.default)
  +
  +    def to_python(self, value):
  +        # The JSON representation of an EmbedBlock's value is a URL string;
  +        # this should be converted to an EmbedValue (or None).
  +        if not value:
  +            return None
  +        else:
  +            return EmbedValue(value)
  +
  +    def get_prep_value(self, value):
  +        # serialisable value should be a URL string
  +        if value is None:
  +            return ''
  +        else:
  +            return value.url
  +
  +    def value_for_form(self, value):
  +        # the value to be handled by the URLField is a plain URL string (or the empty string)
  +        if value is None:
  +            return ''
  +        else:
  +            return value.url
  +
  +    def value_from_form(self, value):
  +        # convert the value returned from the form (a URL string) to an EmbedValue (or None)
  +        if not value:
  +            return None
  +        else:
  +            return EmbedValue(value)
  
verification_info: {"golden_diff": "diff --git a/wagtail/wagtailembeds/blocks.py b/wagtail/wagtailembeds/blocks.py\n--- a/wagtail/wagtailembeds/blocks.py\n+++ b/wagtail/wagtailembeds/blocks.py\n@@ -1,8 +1,62 @@\n+from django.utils.encoding import python_2_unicode_compatible\n+\n from wagtail.wagtailcore import blocks\n \n from wagtail.wagtailembeds.format import embed_to_frontend_html\n \n \n+@python_2_unicode_compatible\n+class EmbedValue(object):\n+    \"\"\"\n+    Native value of an EmbedBlock. Should, at minimum, have a 'url' property\n+    and render as the embed HTML when rendered in a template.\n+    NB We don't use a wagtailembeds.model.Embed object for this, because\n+    we want to be able to do {{ value.url|embed:max_width=500 }} without\n+    doing a redundant fetch of the embed at the default width.\n+    \"\"\"\n+    def __init__(self, url):\n+        self.url = url\n+\n+    def __str__(self):\n+        return embed_to_frontend_html(self.url)\n+\n+\n class EmbedBlock(blocks.URLBlock):\n-    def render_basic(self, value):\n-        return embed_to_frontend_html(value)\n+    def get_default(self):\n+        # Allow specifying the default for an EmbedBlock as either an EmbedValue or a string (or None).\n+        if not self.meta.default:\n+            return None\n+        elif isinstance(self.meta.default, EmbedValue):\n+            return self.meta.default\n+        else:\n+            # assume default has been passed as a string\n+            return EmbedValue(self.meta.default)\n+\n+    def to_python(self, value):\n+        # The JSON representation of an EmbedBlock's value is a URL string;\n+        # this should be converted to an EmbedValue (or None).\n+        if not value:\n+            return None\n+        else:\n+            return EmbedValue(value)\n+\n+    def get_prep_value(self, value):\n+        # serialisable value should be a URL string\n+        if value is None:\n+            return ''\n+        else:\n+            return value.url\n+\n+    def value_for_form(self, value):\n+        # the value to be handled by the URLField is a plain URL string (or the empty string)\n+        if value is None:\n+            return ''\n+        else:\n+            return value.url\n+\n+    def value_from_form(self, value):\n+        # convert the value returned from the form (a URL string) to an EmbedValue (or None)\n+        if not value:\n+            return None\n+        else:\n+            return EmbedValue(value)\n", "issue": "StreamField EmbedBlock renders the url only\nGiven the following setup:\n\n```\nclass EmbedOnImage(StructBlock):\n    embed = EmbedBlock()\n    background_image = ImageChooserBlock(required=False)\n\n    class Meta:\n        template = 'streamfield_blocks/embed_on_image.html'\n```\n\n`{{ self.embed }}` outputs the embed url only in `streamfield_blocks/embed_on_image.html`.\n\nAnd `EmbedBlock.render_basic` is never called: https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailembeds/blocks.py#L8\n\nAlso, if I apply the embed filter too: `{{ self.embed|embed }}` then it outputs nothing because the embed filter won't call `embed_to_frontend_html` either, which would use the correct template to render it: https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailembeds/templatetags/wagtailembeds_tags.py#L14\n\n", "before_files": [{"content": "from wagtail.wagtailcore import blocks\n\nfrom wagtail.wagtailembeds.format import embed_to_frontend_html\n\n\nclass EmbedBlock(blocks.URLBlock):\n    def render_basic(self, value):\n        return embed_to_frontend_html(value)\n", "path": "wagtail/wagtailembeds/blocks.py"}]}