We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Falta label de processo nos detalhes da matéria
O número do processo está perdido em meio aos detalhes da matéria. Falta o label processo 

![image](https://user-images.githubusercontent.com/13314947/28427707-78e650de-6d4d-11e7-93e9-deabf93ba1d9.png)


![image](https://user-images.githubusercontent.com/13314947/28427759-a6041434-6d4d-11e7-82e2-08b7c0c80ddd.png)


![image](https://user-images.githubusercontent.com/13314947/28427786-ba25feb4-6d4d-11e7-8d8b-0f573996a8fc.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sapl/crispy_layout_mixin.py`
Content:
```
1 from math import ceil
2 
3 from crispy_forms.bootstrap import FormActions
4 from crispy_forms.helper import FormHelper
5 from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
6 from django import template
7 from django.core.urlresolvers import reverse
8 from django.utils import formats
9 from django.utils.translation import ugettext as _
10 import rtyaml
11 
12 
13 def heads_and_tails(list_of_lists):
14     for alist in list_of_lists:
15         yield alist[0], alist[1:]
16 
17 
18 def to_column(name_span):
19     fieldname, span = name_span
20     return Div(fieldname, css_class='col-md-%d' % span)
21 
22 
23 def to_row(names_spans):
24     return Div(*map(to_column, names_spans), css_class='row-fluid')
25 
26 
27 def to_fieldsets(fields):
28     for field in fields:
29         if isinstance(field, list):
30             legend, row_specs = field[0], field[1:]
31             rows = [to_row(name_span_list) for name_span_list in row_specs]
32             yield Fieldset(legend, *rows)
33         else:
34             yield field
35 
36 
37 def form_actions(more=[], save_label=_('Salvar')):
38     return FormActions(
39         Submit('salvar', save_label, css_class='pull-right'), *more)
40 
41 
42 class SaplFormLayout(Layout):
43 
44     def __init__(self, *fields, cancel_label=_('Cancelar'),
45                  save_label=_('Salvar'), actions=None):
46 
47         buttons = actions
48         if not buttons:
49             buttons = form_actions(save_label=save_label, more=[
50                 HTML('<a href="{{ view.cancel_url }}"'
51                      ' class="btn btn-inverse">%s</a>' % cancel_label)
52                 if cancel_label else None])
53 
54         _fields = list(to_fieldsets(fields))
55         if buttons:
56             _fields += [to_row([(buttons, 12)])]
57         super(SaplFormLayout, self).__init__(*_fields)
58 
59 
60 def get_field_display(obj, fieldname):
61     field = ''
62     try:
63         field = obj._meta.get_field(fieldname)
64     except Exception as e:
65         """ nos casos que o fieldname não é um field_model,
66             ele pode ser um aggregate, annotate, um property, um manager,
67             ou mesmo uma método no model.
68         """
69         value = getattr(obj, fieldname)
70         verbose_name = ''
71 
72     else:
73         verbose_name = str(field.verbose_name)\
74             if hasattr(field, 'verbose_name') else ''
75 
76         if hasattr(field, 'choices') and field.choices:
77             value = getattr(obj, 'get_%s_display' % fieldname)()
78         else:
79             value = getattr(obj, fieldname)
80 
81     str_type_from_value = str(type(value))
82     str_type_from_field = str(type(field))
83 
84     if value is None:
85         display = ''
86     elif 'date' in str_type_from_value:
87         display = formats.date_format(value, "SHORT_DATE_FORMAT")
88     elif 'bool' in str_type_from_value:
89         display = _('Sim') if value else _('Não')
90     elif 'ImageFieldFile' in str(type(value)):
91         if value:
92             display = '<img src="{}" />'.format(value.url)
93         else:
94             display = ''
95     elif 'FieldFile' in str_type_from_value:
96         if value:
97             display = '<a href="{}">{}</a>'.format(
98                 value.url,
99                 value.name.split('/')[-1:][0])
100         else:
101             display = ''
102     elif 'ManyRelatedManager' in str_type_from_value\
103             or 'RelatedManager' in str_type_from_value\
104             or 'GenericRelatedObjectManager' in str_type_from_value:
105         display = '<ul>'
106         for v in value.all():
107             display += '<li>%s</li>' % str(v)
108         display += '</ul>'
109         if not verbose_name:
110             if hasattr(field, 'related_model'):
111                 verbose_name = str(
112                     field.related_model._meta.verbose_name_plural)
113             elif hasattr(field, 'model'):
114                 verbose_name = str(field.model._meta.verbose_name_plural)
115     elif 'GenericForeignKey' in str_type_from_field:
116         display = '<a href="{}">{}</a>'.format(
117             reverse(
118                 '%s:%s_detail' % (
119                     value._meta.app_config.name, obj.content_type.model),
120                 args=(value.id,)),
121             value)
122     else:
123         display = str(value)
124     return verbose_name, display
125 
126 
127 class CrispyLayoutFormMixin:
128 
129     @property
130     def layout_key(self):
131         if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key'):
132             return super(CrispyLayoutFormMixin, self).layout_key
133         else:
134             return self.model.__name__
135 
136     @property
137     def layout_key_set(self):
138         if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key_set'):
139             return super(CrispyLayoutFormMixin, self).layout_key_set
140         else:
141             obj = self.crud if hasattr(self, 'crud') else self
142             return getattr(obj.model,
143                            obj.model_set).field.model.__name__
144 
145     def get_layout(self):
146         yaml_layout = '%s/layouts.yaml' % self.model._meta.app_config.label
147         return read_layout_from_yaml(yaml_layout, self.layout_key)
148 
149     def get_layout_set(self):
150         obj = self.crud if hasattr(self, 'crud') else self
151         yaml_layout = '%s/layouts.yaml' % getattr(
152             obj.model, obj.model_set).field.model._meta.app_config.label
153         return read_layout_from_yaml(yaml_layout, self.layout_key_set)
154 
155     @property
156     def fields(self):
157         if hasattr(self, 'form_class') and self.form_class:
158             return None
159         else:
160             '''Returns all fields in the layout'''
161             return [fieldname for legend_rows in self.get_layout()
162                     for row in legend_rows[1:]
163                     for fieldname, span in row]
164 
165     def get_form(self, form_class=None):
166         try:
167             form = super(CrispyLayoutFormMixin, self).get_form(form_class)
168         except AttributeError:
169             # simply return None if there is no get_form on super
170             pass
171         else:
172             if self.layout_key:
173                 form.helper = FormHelper()
174                 form.helper.layout = SaplFormLayout(*self.get_layout())
175             return form
176 
177     @property
178     def list_field_names(self):
179         '''The list of field names to display on table
180 
181         This base implementation returns the field names
182         in the first fieldset of the layout.
183         '''
184         obj = self.crud if hasattr(self, 'crud') else self
185         if hasattr(obj, 'list_field_names') and obj.list_field_names:
186             return obj.list_field_names
187         rows = self.get_layout()[0][1:]
188         return [fieldname for row in rows for fieldname, __ in row]
189 
190     @property
191     def list_field_names_set(self):
192         '''The list of field names to display on table
193 
194         This base implementation returns the field names
195         in the first fieldset of the layout.
196         '''
197         rows = self.get_layout_set()[0][1:]
198         return [fieldname for row in rows for fieldname, __ in row]
199 
200     def get_column(self, fieldname, span):
201         obj = self.get_object()
202         verbose_name, text = get_field_display(obj, fieldname)
203         return {
204             'id': fieldname,
205             'span': span,
206             'verbose_name': verbose_name,
207             'text': text,
208         }
209 
210     @property
211     def layout_display(self):
212 
213         return [
214             {'legend': legend,
215              'rows': [[self.get_column(fieldname, span)
216                        for fieldname, span in row]
217                       for row in rows]
218              } for legend, rows in heads_and_tails(self.get_layout())]
219 
220 
221 def read_yaml_from_file(yaml_layout):
222     # TODO cache this at application level
223     t = template.loader.get_template(yaml_layout)
224     # aqui é importante converter para str pois, dependendo do ambiente,
225     # o rtyaml pode usar yaml.CSafeLoader, que exige str ou stream
226     rendered = str(t.render())
227     return rtyaml.load(rendered)
228 
229 
230 def read_layout_from_yaml(yaml_layout, key):
231     # TODO cache this at application level
232     yaml = read_yaml_from_file(yaml_layout)
233     base = yaml[key]
234 
235     def line_to_namespans(line):
236         split = [cell.split(':') for cell in line.split()]
237         namespans = [[s[0], int(s[1]) if len(s) > 1 else 0] for s in split]
238         remaining = 12 - sum(s for n, s in namespans)
239         nondefined = [ns for ns in namespans if not ns[1]]
240         while nondefined:
241             span = ceil(remaining / len(nondefined))
242             namespan = nondefined.pop(0)
243             namespan[1] = span
244             remaining = remaining - span
245         return list(map(tuple, namespans))
246 
247     return [[legend] + [line_to_namespans(l) for l in lines]
248             for legend, lines in base.items()]
249
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py
--- a/sapl/crispy_layout_mixin.py
+++ b/sapl/crispy_layout_mixin.py
@@ -67,7 +67,10 @@
             ou mesmo uma método no model.
         """
         value = getattr(obj, fieldname)
-        verbose_name = ''
+        try:
+            verbose_name = value.model._meta.verbose_name
+        except AttributeError:
+            verbose_name = ''
 
     else:
         verbose_name = str(field.verbose_name)\

{"golden_diff": "diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py\n--- a/sapl/crispy_layout_mixin.py\n+++ b/sapl/crispy_layout_mixin.py\n@@ -67,7 +67,10 @@\n             ou mesmo uma m\u00e9todo no model.\n         \"\"\"\n         value = getattr(obj, fieldname)\n-        verbose_name = ''\n+        try:\n+            verbose_name = value.model._meta.verbose_name\n+        except AttributeError:\n+            verbose_name = ''\n \n     else:\n         verbose_name = str(field.verbose_name)\\\n", "issue": "Falta label de processo nos detalhes da mat\u00e9ria\nO n\u00famero do processo est\u00e1 perdido em meio aos detalhes da mat\u00e9ria. Falta o label processo \r\n\r\n![image](https://user-images.githubusercontent.com/13314947/28427707-78e650de-6d4d-11e7-93e9-deabf93ba1d9.png)\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/13314947/28427759-a6041434-6d4d-11e7-82e2-08b7c0c80ddd.png)\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/13314947/28427786-ba25feb4-6d4d-11e7-8d8b-0f573996a8fc.png)\r\n\n", "before_files": [{"content": "from math import ceil\n\nfrom crispy_forms.bootstrap import FormActions\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit\nfrom django import template\nfrom django.core.urlresolvers import reverse\nfrom django.utils import formats\nfrom django.utils.translation import ugettext as _\nimport rtyaml\n\n\ndef heads_and_tails(list_of_lists):\n    for alist in list_of_lists:\n        yield alist[0], alist[1:]\n\n\ndef to_column(name_span):\n    fieldname, span = name_span\n    return Div(fieldname, css_class='col-md-%d' % span)\n\n\ndef to_row(names_spans):\n    return Div(*map(to_column, names_spans), css_class='row-fluid')\n\n\ndef to_fieldsets(fields):\n    for field in fields:\n        if isinstance(field, list):\n            legend, row_specs = field[0], field[1:]\n            rows = [to_row(name_span_list) for name_span_list in row_specs]\n            yield Fieldset(legend, *rows)\n        else:\n            yield field\n\n\ndef form_actions(more=[], save_label=_('Salvar')):\n    return FormActions(\n        Submit('salvar', save_label, css_class='pull-right'), *more)\n\n\nclass SaplFormLayout(Layout):\n\n    def __init__(self, *fields, cancel_label=_('Cancelar'),\n                 save_label=_('Salvar'), actions=None):\n\n        buttons = actions\n        if not buttons:\n            buttons = form_actions(save_label=save_label, more=[\n                HTML('<a href=\"{{ view.cancel_url }}\"'\n                     ' class=\"btn btn-inverse\">%s</a>' % cancel_label)\n                if cancel_label else None])\n\n        _fields = list(to_fieldsets(fields))\n        if buttons:\n            _fields += [to_row([(buttons, 12)])]\n        super(SaplFormLayout, self).__init__(*_fields)\n\n\ndef get_field_display(obj, fieldname):\n    field = ''\n    try:\n        field = obj._meta.get_field(fieldname)\n    except Exception as e:\n        \"\"\" nos casos que o fieldname n\u00e3o \u00e9 um field_model,\n            ele pode ser um aggregate, annotate, um property, um manager,\n            ou mesmo uma m\u00e9todo no model.\n        \"\"\"\n        value = getattr(obj, fieldname)\n        verbose_name = ''\n\n    else:\n        verbose_name = str(field.verbose_name)\\\n            if hasattr(field, 'verbose_name') else ''\n\n        if hasattr(field, 'choices') and field.choices:\n            value = getattr(obj, 'get_%s_display' % fieldname)()\n        else:\n            value = getattr(obj, fieldname)\n\n    str_type_from_value = str(type(value))\n    str_type_from_field = str(type(field))\n\n    if value is None:\n        display = ''\n    elif 'date' in str_type_from_value:\n        display = formats.date_format(value, \"SHORT_DATE_FORMAT\")\n    elif 'bool' in str_type_from_value:\n        display = _('Sim') if value else _('N\u00e3o')\n    elif 'ImageFieldFile' in str(type(value)):\n        if value:\n            display = '<img src=\"{}\" />'.format(value.url)\n        else:\n            display = ''\n    elif 'FieldFile' in str_type_from_value:\n        if value:\n            display = '<a href=\"{}\">{}</a>'.format(\n                value.url,\n                value.name.split('/')[-1:][0])\n        else:\n            display = ''\n    elif 'ManyRelatedManager' in str_type_from_value\\\n            or 'RelatedManager' in str_type_from_value\\\n            or 'GenericRelatedObjectManager' in str_type_from_value:\n        display = '<ul>'\n        for v in value.all():\n            display += '<li>%s</li>' % str(v)\n        display += '</ul>'\n        if not verbose_name:\n            if hasattr(field, 'related_model'):\n                verbose_name = str(\n                    field.related_model._meta.verbose_name_plural)\n            elif hasattr(field, 'model'):\n                verbose_name = str(field.model._meta.verbose_name_plural)\n    elif 'GenericForeignKey' in str_type_from_field:\n        display = '<a href=\"{}\">{}</a>'.format(\n            reverse(\n                '%s:%s_detail' % (\n                    value._meta.app_config.name, obj.content_type.model),\n                args=(value.id,)),\n            value)\n    else:\n        display = str(value)\n    return verbose_name, display\n\n\nclass CrispyLayoutFormMixin:\n\n    @property\n    def layout_key(self):\n        if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key'):\n            return super(CrispyLayoutFormMixin, self).layout_key\n        else:\n            return self.model.__name__\n\n    @property\n    def layout_key_set(self):\n        if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key_set'):\n            return super(CrispyLayoutFormMixin, self).layout_key_set\n        else:\n            obj = self.crud if hasattr(self, 'crud') else self\n            return getattr(obj.model,\n                           obj.model_set).field.model.__name__\n\n    def get_layout(self):\n        yaml_layout = '%s/layouts.yaml' % self.model._meta.app_config.label\n        return read_layout_from_yaml(yaml_layout, self.layout_key)\n\n    def get_layout_set(self):\n        obj = self.crud if hasattr(self, 'crud') else self\n        yaml_layout = '%s/layouts.yaml' % getattr(\n            obj.model, obj.model_set).field.model._meta.app_config.label\n        return read_layout_from_yaml(yaml_layout, self.layout_key_set)\n\n    @property\n    def fields(self):\n        if hasattr(self, 'form_class') and self.form_class:\n            return None\n        else:\n            '''Returns all fields in the layout'''\n            return [fieldname for legend_rows in self.get_layout()\n                    for row in legend_rows[1:]\n                    for fieldname, span in row]\n\n    def get_form(self, form_class=None):\n        try:\n            form = super(CrispyLayoutFormMixin, self).get_form(form_class)\n        except AttributeError:\n            # simply return None if there is no get_form on super\n            pass\n        else:\n            if self.layout_key:\n                form.helper = FormHelper()\n                form.helper.layout = SaplFormLayout(*self.get_layout())\n            return form\n\n    @property\n    def list_field_names(self):\n        '''The list of field names to display on table\n\n        This base implementation returns the field names\n        in the first fieldset of the layout.\n        '''\n        obj = self.crud if hasattr(self, 'crud') else self\n        if hasattr(obj, 'list_field_names') and obj.list_field_names:\n            return obj.list_field_names\n        rows = self.get_layout()[0][1:]\n        return [fieldname for row in rows for fieldname, __ in row]\n\n    @property\n    def list_field_names_set(self):\n        '''The list of field names to display on table\n\n        This base implementation returns the field names\n        in the first fieldset of the layout.\n        '''\n        rows = self.get_layout_set()[0][1:]\n        return [fieldname for row in rows for fieldname, __ in row]\n\n    def get_column(self, fieldname, span):\n        obj = self.get_object()\n        verbose_name, text = get_field_display(obj, fieldname)\n        return {\n            'id': fieldname,\n            'span': span,\n            'verbose_name': verbose_name,\n            'text': text,\n        }\n\n    @property\n    def layout_display(self):\n\n        return [\n            {'legend': legend,\n             'rows': [[self.get_column(fieldname, span)\n                       for fieldname, span in row]\n                      for row in rows]\n             } for legend, rows in heads_and_tails(self.get_layout())]\n\n\ndef read_yaml_from_file(yaml_layout):\n    # TODO cache this at application level\n    t = template.loader.get_template(yaml_layout)\n    # aqui \u00e9 importante converter para str pois, dependendo do ambiente,\n    # o rtyaml pode usar yaml.CSafeLoader, que exige str ou stream\n    rendered = str(t.render())\n    return rtyaml.load(rendered)\n\n\ndef read_layout_from_yaml(yaml_layout, key):\n    # TODO cache this at application level\n    yaml = read_yaml_from_file(yaml_layout)\n    base = yaml[key]\n\n    def line_to_namespans(line):\n        split = [cell.split(':') for cell in line.split()]\n        namespans = [[s[0], int(s[1]) if len(s) > 1 else 0] for s in split]\n        remaining = 12 - sum(s for n, s in namespans)\n        nondefined = [ns for ns in namespans if not ns[1]]\n        while nondefined:\n            span = ceil(remaining / len(nondefined))\n            namespan = nondefined.pop(0)\n            namespan[1] = span\n            remaining = remaining - span\n        return list(map(tuple, namespans))\n\n    return [[legend] + [line_to_namespans(l) for l in lines]\n            for legend, lines in base.items()]\n", "path": "sapl/crispy_layout_mixin.py"}], "after_files": [{"content": "from math import ceil\n\nfrom crispy_forms.bootstrap import FormActions\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit\nfrom django import template\nfrom django.core.urlresolvers import reverse\nfrom django.utils import formats\nfrom django.utils.translation import ugettext as _\nimport rtyaml\n\n\ndef heads_and_tails(list_of_lists):\n    for alist in list_of_lists:\n        yield alist[0], alist[1:]\n\n\ndef to_column(name_span):\n    fieldname, span = name_span\n    return Div(fieldname, css_class='col-md-%d' % span)\n\n\ndef to_row(names_spans):\n    return Div(*map(to_column, names_spans), css_class='row-fluid')\n\n\ndef to_fieldsets(fields):\n    for field in fields:\n        if isinstance(field, list):\n            legend, row_specs = field[0], field[1:]\n            rows = [to_row(name_span_list) for name_span_list in row_specs]\n            yield Fieldset(legend, *rows)\n        else:\n            yield field\n\n\ndef form_actions(more=[], save_label=_('Salvar')):\n    return FormActions(\n        Submit('salvar', save_label, css_class='pull-right'), *more)\n\n\nclass SaplFormLayout(Layout):\n\n    def __init__(self, *fields, cancel_label=_('Cancelar'),\n                 save_label=_('Salvar'), actions=None):\n\n        buttons = actions\n        if not buttons:\n            buttons = form_actions(save_label=save_label, more=[\n                HTML('<a href=\"{{ view.cancel_url }}\"'\n                     ' class=\"btn btn-inverse\">%s</a>' % cancel_label)\n                if cancel_label else None])\n\n        _fields = list(to_fieldsets(fields))\n        if buttons:\n            _fields += [to_row([(buttons, 12)])]\n        super(SaplFormLayout, self).__init__(*_fields)\n\n\ndef get_field_display(obj, fieldname):\n    field = ''\n    try:\n        field = obj._meta.get_field(fieldname)\n    except Exception as e:\n        \"\"\" nos casos que o fieldname n\u00e3o \u00e9 um field_model,\n            ele pode ser um aggregate, annotate, um property, um manager,\n            ou mesmo uma m\u00e9todo no model.\n        \"\"\"\n        value = getattr(obj, fieldname)\n        try:\n            verbose_name = value.model._meta.verbose_name\n        except AttributeError:\n            verbose_name = ''\n\n    else:\n        verbose_name = str(field.verbose_name)\\\n            if hasattr(field, 'verbose_name') else ''\n\n        if hasattr(field, 'choices') and field.choices:\n            value = getattr(obj, 'get_%s_display' % fieldname)()\n        else:\n            value = getattr(obj, fieldname)\n\n    str_type_from_value = str(type(value))\n    str_type_from_field = str(type(field))\n\n    if value is None:\n        display = ''\n    elif 'date' in str_type_from_value:\n        display = formats.date_format(value, \"SHORT_DATE_FORMAT\")\n    elif 'bool' in str_type_from_value:\n        display = _('Sim') if value else _('N\u00e3o')\n    elif 'ImageFieldFile' in str(type(value)):\n        if value:\n            display = '<img src=\"{}\" />'.format(value.url)\n        else:\n            display = ''\n    elif 'FieldFile' in str_type_from_value:\n        if value:\n            display = '<a href=\"{}\">{}</a>'.format(\n                value.url,\n                value.name.split('/')[-1:][0])\n        else:\n            display = ''\n    elif 'ManyRelatedManager' in str_type_from_value\\\n            or 'RelatedManager' in str_type_from_value\\\n            or 'GenericRelatedObjectManager' in str_type_from_value:\n        display = '<ul>'\n        for v in value.all():\n            display += '<li>%s</li>' % str(v)\n        display += '</ul>'\n        if not verbose_name:\n            if hasattr(field, 'related_model'):\n                verbose_name = str(\n                    field.related_model._meta.verbose_name_plural)\n            elif hasattr(field, 'model'):\n                verbose_name = str(field.model._meta.verbose_name_plural)\n    elif 'GenericForeignKey' in str_type_from_field:\n        display = '<a href=\"{}\">{}</a>'.format(\n            reverse(\n                '%s:%s_detail' % (\n                    value._meta.app_config.name, obj.content_type.model),\n                args=(value.id,)),\n            value)\n    else:\n        display = str(value)\n    return verbose_name, display\n\n\nclass CrispyLayoutFormMixin:\n\n    @property\n    def layout_key(self):\n        if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key'):\n            return super(CrispyLayoutFormMixin, self).layout_key\n        else:\n            return self.model.__name__\n\n    @property\n    def layout_key_set(self):\n        if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key_set'):\n            return super(CrispyLayoutFormMixin, self).layout_key_set\n        else:\n            obj = self.crud if hasattr(self, 'crud') else self\n            return getattr(obj.model,\n                           obj.model_set).field.model.__name__\n\n    def get_layout(self):\n        yaml_layout = '%s/layouts.yaml' % self.model._meta.app_config.label\n        return read_layout_from_yaml(yaml_layout, self.layout_key)\n\n    def get_layout_set(self):\n        obj = self.crud if hasattr(self, 'crud') else self\n        yaml_layout = '%s/layouts.yaml' % getattr(\n            obj.model, obj.model_set).field.model._meta.app_config.label\n        return read_layout_from_yaml(yaml_layout, self.layout_key_set)\n\n    @property\n    def fields(self):\n        if hasattr(self, 'form_class') and self.form_class:\n            return None\n        else:\n            '''Returns all fields in the layout'''\n            return [fieldname for legend_rows in self.get_layout()\n                    for row in legend_rows[1:]\n                    for fieldname, span in row]\n\n    def get_form(self, form_class=None):\n        try:\n            form = super(CrispyLayoutFormMixin, self).get_form(form_class)\n        except AttributeError:\n            # simply return None if there is no get_form on super\n            pass\n        else:\n            if self.layout_key:\n                form.helper = FormHelper()\n                form.helper.layout = SaplFormLayout(*self.get_layout())\n            return form\n\n    @property\n    def list_field_names(self):\n        '''The list of field names to display on table\n\n        This base implementation returns the field names\n        in the first fieldset of the layout.\n        '''\n        obj = self.crud if hasattr(self, 'crud') else self\n        if hasattr(obj, 'list_field_names') and obj.list_field_names:\n            return obj.list_field_names\n        rows = self.get_layout()[0][1:]\n        return [fieldname for row in rows for fieldname, __ in row]\n\n    @property\n    def list_field_names_set(self):\n        '''The list of field names to display on table\n\n        This base implementation returns the field names\n        in the first fieldset of the layout.\n        '''\n        rows = self.get_layout_set()[0][1:]\n        return [fieldname for row in rows for fieldname, __ in row]\n\n    def get_column(self, fieldname, span):\n        obj = self.get_object()\n        verbose_name, text = get_field_display(obj, fieldname)\n        return {\n            'id': fieldname,\n            'span': span,\n            'verbose_name': verbose_name,\n            'text': text,\n        }\n\n    @property\n    def layout_display(self):\n\n        return [\n            {'legend': legend,\n             'rows': [[self.get_column(fieldname, span)\n                       for fieldname, span in row]\n                      for row in rows]\n             } for legend, rows in heads_and_tails(self.get_layout())]\n\n\ndef read_yaml_from_file(yaml_layout):\n    # TODO cache this at application level\n    t = template.loader.get_template(yaml_layout)\n    # aqui \u00e9 importante converter para str pois, dependendo do ambiente,\n    # o rtyaml pode usar yaml.CSafeLoader, que exige str ou stream\n    rendered = str(t.render())\n    return rtyaml.load(rendered)\n\n\ndef read_layout_from_yaml(yaml_layout, key):\n    # TODO cache this at application level\n    yaml = read_yaml_from_file(yaml_layout)\n    base = yaml[key]\n\n    def line_to_namespans(line):\n        split = [cell.split(':') for cell in line.split()]\n        namespans = [[s[0], int(s[1]) if len(s) > 1 else 0] for s in split]\n        remaining = 12 - sum(s for n, s in namespans)\n        nondefined = [ns for ns in namespans if not ns[1]]\n        while nondefined:\n            span = ceil(remaining / len(nondefined))\n            namespan = nondefined.pop(0)\n            namespan[1] = span\n            remaining = remaining - span\n        return list(map(tuple, namespans))\n\n    return [[legend] + [line_to_namespans(l) for l in lines]\n            for legend, lines in base.items()]\n", "path": "sapl/crispy_layout_mixin.py"}]}