prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Audiências Públicas sem possibilidade de Edição
  Ao criar uma Audiência Pública e salva-la, não aparecem os metadados da matéria legislativa inseridas no preenchimento. 
  Ao clicar em Editar, só  aparece o título da audiência criada.
  grato
  
  </issue>
  <code>
  [start of sapl/audiencia/views.py]
  1 from django.http import HttpResponse
  2 from django.views.decorators.clickjacking import xframe_options_exempt
  3 from django.views.generic import UpdateView
  4 from sapl.crud.base import RP_DETAIL, RP_LIST, Crud
  5 
  6 from .forms import AudienciaForm
  7 from .models import AudienciaPublica
  8 
  9 
  10 def index(request):
  11     return HttpResponse("Audiência  Pública")
  12 
  13 
  14 class AudienciaCrud(Crud):
  15     model = AudienciaPublica
  16     public = [RP_LIST, RP_DETAIL, ]
  17 
  18     class BaseMixin(Crud.BaseMixin):
  19         list_field_names = ['numero', 'nome', 'tipo', 'materia',
  20                             'data']
  21         ordering = 'nome', 'numero', 'tipo', 'data'
  22 
  23     class ListView(Crud.ListView):
  24         paginate_by = 10
  25 
  26     class CreateView(Crud.CreateView):
  27         form_class = AudienciaForm
  28 
  29         def form_valid(self, form):
  30             return super(Crud.CreateView, self).form_valid(form)
  31 
  32     class UpdateView(Crud.UpdateView):
  33         form_class = AudienciaForm
  34 
  35         def get_initial(self):
  36             initial = super(UpdateView, self).get_initial()
  37             initial['tipo_materia'] = self.object.materia.tipo.id
  38             initial['numero_materia'] = self.object.materia.numero
  39             initial['ano_materia'] = self.object.materia.ano
  40             return initial
  41      
  42     class DeleteView(Crud.DeleteView):
  43         pass
  44 
  45     class DetailView(Crud.DetailView):
  46 
  47         layout_key = 'AudienciaPublicaDetail'
  48 
  49         @xframe_options_exempt
  50         def get(self, request, *args, **kwargs):
  51             return super().get(request, *args, **kwargs)
  52 
  53
  [end of sapl/audiencia/views.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/sapl/audiencia/views.py b/sapl/audiencia/views.py
  --- a/sapl/audiencia/views.py
  +++ b/sapl/audiencia/views.py
  @@ -34,9 +34,10 @@
   
           def get_initial(self):
               initial = super(UpdateView, self).get_initial()
  -            initial['tipo_materia'] = self.object.materia.tipo.id
  -            initial['numero_materia'] = self.object.materia.numero
  -            initial['ano_materia'] = self.object.materia.ano
  +            if self.object.materia:
  +                initial['tipo_materia'] = self.object.materia.tipo.id
  +                initial['numero_materia'] = self.object.materia.numero
  +                initial['ano_materia'] = self.object.materia.ano
               return initial
        
       class DeleteView(Crud.DeleteView):
  
verification_info: {"golden_diff": "diff --git a/sapl/audiencia/views.py b/sapl/audiencia/views.py\n--- a/sapl/audiencia/views.py\n+++ b/sapl/audiencia/views.py\n@@ -34,9 +34,10 @@\n \n         def get_initial(self):\n             initial = super(UpdateView, self).get_initial()\n-            initial['tipo_materia'] = self.object.materia.tipo.id\n-            initial['numero_materia'] = self.object.materia.numero\n-            initial['ano_materia'] = self.object.materia.ano\n+            if self.object.materia:\n+                initial['tipo_materia'] = self.object.materia.tipo.id\n+                initial['numero_materia'] = self.object.materia.numero\n+                initial['ano_materia'] = self.object.materia.ano\n             return initial\n      \n     class DeleteView(Crud.DeleteView):\n", "issue": "Audi\u00eancias P\u00fablicas sem possibilidade de Edi\u00e7\u00e3o\nAo criar uma Audi\u00eancia P\u00fablica e salva-la, n\u00e3o aparecem os metadados da mat\u00e9ria legislativa inseridas no preenchimento. \r\nAo clicar em Editar, s\u00f3  aparece o t\u00edtulo da audi\u00eancia criada.\r\ngrato\n", "before_files": [{"content": "from django.http import HttpResponse\nfrom django.views.decorators.clickjacking import xframe_options_exempt\nfrom django.views.generic import UpdateView\nfrom sapl.crud.base import RP_DETAIL, RP_LIST, Crud\n\nfrom .forms import AudienciaForm\nfrom .models import AudienciaPublica\n\n\ndef index(request):\n    return HttpResponse(\"Audi\u00eancia  P\u00fablica\")\n\n\nclass AudienciaCrud(Crud):\n    model = AudienciaPublica\n    public = [RP_LIST, RP_DETAIL, ]\n\n    class BaseMixin(Crud.BaseMixin):\n        list_field_names = ['numero', 'nome', 'tipo', 'materia',\n                            'data']\n        ordering = 'nome', 'numero', 'tipo', 'data'\n\n    class ListView(Crud.ListView):\n        paginate_by = 10\n\n    class CreateView(Crud.CreateView):\n        form_class = AudienciaForm\n\n        def form_valid(self, form):\n            return super(Crud.CreateView, self).form_valid(form)\n\n    class UpdateView(Crud.UpdateView):\n        form_class = AudienciaForm\n\n        def get_initial(self):\n            initial = super(UpdateView, self).get_initial()\n            initial['tipo_materia'] = self.object.materia.tipo.id\n            initial['numero_materia'] = self.object.materia.numero\n            initial['ano_materia'] = self.object.materia.ano\n            return initial\n     \n    class DeleteView(Crud.DeleteView):\n        pass\n\n    class DetailView(Crud.DetailView):\n\n        layout_key = 'AudienciaPublicaDetail'\n\n        @xframe_options_exempt\n        def get(self, request, *args, **kwargs):\n            return super().get(request, *args, **kwargs)\n\n    ", "path": "sapl/audiencia/views.py"}]}