We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Norma Jurídica - Detalhe
Nos detalhes da norma jurídica, no que seria o título da norma, não aparece mais o nome da norma.
Antes aparecia "Decreto Legislativo nº ....."

![image](https://user-images.githubusercontent.com/13314947/44723262-e39f6500-aaa5-11e8-9024-02c10e26c0b5.png)

Norma Jurídica - Detalhe
Nos detalhes da norma jurídica, no que seria o título da norma, não aparece mais o nome da norma.
Antes aparecia "Decreto Legislativo nº ....."

![image](https://user-images.githubusercontent.com/13314947/44723262-e39f6500-aaa5-11e8-9024-02c10e26c0b5.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/norma/models.py`
Content:
```
1 from django.contrib.contenttypes.fields import GenericRelation
2 from django.db import models
3 from django.template import defaultfilters
4 from django.utils.translation import ugettext_lazy as _
5 from model_utils import Choices
6 import reversion
7 
8 from sapl.compilacao.models import TextoArticulado
9 from sapl.materia.models import MateriaLegislativa
10 from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES,
11                         restringe_tipos_de_arquivo_txt, texto_upload_path)
12 
13 
14 @reversion.register()
15 class AssuntoNorma(models.Model):
16     assunto = models.CharField(max_length=50, verbose_name=_('Assunto'))
17     descricao = models.CharField(
18         max_length=250, blank=True, verbose_name=_('Descrição'))
19 
20     class Meta:
21         verbose_name = _('Assunto de Norma Jurídica')
22         verbose_name_plural = _('Assuntos de Normas Jurídicas')
23         ordering = ['assunto']
24 
25     def __str__(self):
26         return self.assunto
27 
28 
29 @reversion.register()
30 class TipoNormaJuridica(models.Model):
31     # TODO transform into Domain Model and use an FK for the field
32     EQUIVALENTE_LEXML_CHOICES = ((name, name) for name in
33                                  ('constituicao',
34                                   'ementa.constitucional',
35                                   'lei.complementar',
36                                   'lei.delegada',
37                                   'lei',
38                                   'decreto.lei',
39                                   'medida.provisoria',
40                                   'decreto',
41                                   'lei.organica',
42                                   'emenda.lei.organica',
43                                   'decreto.legislativo',
44                                   'resolucao',
45                                   'regimento.interno',
46                                   ))
47     equivalente_lexml = models.CharField(
48         max_length=50,
49         blank=True,
50         verbose_name=_('Equivalente LexML'),
51         choices=EQUIVALENTE_LEXML_CHOICES)
52     sigla = models.CharField(max_length=3, verbose_name=_('Sigla'))
53     descricao = models.CharField(max_length=50, verbose_name=_('Descrição'))
54 
55     class Meta:
56         verbose_name = _('Tipo de Norma Jurídica')
57         verbose_name_plural = _('Tipos de Norma Jurídica')
58         ordering = ['descricao']
59 
60     def __str__(self):
61         return self.descricao
62 
63 
64 def norma_upload_path(instance, filename):
65     return texto_upload_path(instance, filename, subpath=instance.ano)
66 
67 
68 @reversion.register()
69 class NormaJuridica(models.Model):
70     ESFERA_FEDERACAO_CHOICES = Choices(
71         ('M', 'municipal', _('Municipal')),
72         ('E', 'estadual', _('Estadual')),
73         ('F', 'federal', _('Federal')),
74     )
75 
76     texto_integral = models.FileField(
77         blank=True,
78         null=True,
79         upload_to=norma_upload_path,
80         verbose_name=_('Texto Integral'),
81         validators=[restringe_tipos_de_arquivo_txt])
82     tipo = models.ForeignKey(
83         TipoNormaJuridica,
84         on_delete=models.PROTECT,
85         verbose_name=_('Tipo da Norma Juridica'))
86     materia = models.ForeignKey(
87         MateriaLegislativa, blank=True, null=True,
88         on_delete=models.PROTECT, verbose_name=_('Matéria'))
89     numero = models.CharField(
90         max_length=8,
91         verbose_name=_('Número'))
92     ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),
93                                            choices=RANGE_ANOS)
94     esfera_federacao = models.CharField(
95         max_length=1,
96         verbose_name=_('Esfera Federação'),
97         choices=ESFERA_FEDERACAO_CHOICES)
98     data = models.DateField(blank=False, null=True, verbose_name=_('Data'))
99     data_publicacao = models.DateField(
100         blank=True, null=True, verbose_name=_('Data Publicação'))
101     veiculo_publicacao = models.CharField(
102         max_length=30,
103         blank=True,
104         verbose_name=_('Veículo Publicação'))
105     pagina_inicio_publicacao = models.PositiveIntegerField(
106         blank=True, null=True, verbose_name=_('Pg. Início'))
107     pagina_fim_publicacao = models.PositiveIntegerField(
108         blank=True, null=True, verbose_name=_('Pg. Fim'))
109     ementa = models.TextField(verbose_name=_('Ementa'))
110     indexacao = models.TextField(
111         blank=True, verbose_name=_('Indexação'))
112     observacao = models.TextField(
113         blank=True, verbose_name=_('Observação'))
114     complemento = models.NullBooleanField(
115         blank=True, verbose_name=_('Complementar ?'),
116         choices=YES_NO_CHOICES)
117     # XXX was a CharField (attention on migrate)
118     assuntos = models.ManyToManyField(
119         AssuntoNorma, blank=True,
120         verbose_name=_('Assuntos'))
121     data_vigencia = models.DateField(blank=True, null=True)
122     timestamp = models.DateTimeField(null=True)
123 
124     texto_articulado = GenericRelation(
125         TextoArticulado, related_query_name='texto_articulado')
126 
127     data_ultima_atualizacao = models.DateTimeField(
128         blank=True, null=True,
129         auto_now=True,
130         verbose_name=_('Data'))
131 
132     class Meta:
133         verbose_name = _('Norma Jurídica')
134         verbose_name_plural = _('Normas Jurídicas')
135         ordering = ['-data', '-numero']
136 
137     def get_normas_relacionadas(self):
138         principais = NormaRelacionada.objects.filter(
139             norma_principal=self.id)
140         relacionadas = NormaRelacionada.objects.filter(
141             norma_relacionada=self.id)
142         return (principais, relacionadas)
143 
144     def get_anexos_norma_juridica(self):
145         anexos = AnexoNormaJuridica.objects.filter(
146             norma=self.id)
147         return anexos
148 
149     def __str__(self):
150         return _('nº %(numero)s de %(data)s') % {
151             'numero': self.numero,
152             'data': defaultfilters.date(self.data, "d \d\e F \d\e Y")}
153 
154     @property
155     def epigrafe(self):
156         return _('%(tipo)s nº %(numero)s de %(data)s') % {
157             'tipo': self.tipo,
158             'numero': self.numero,
159             'data': defaultfilters.date(self.data, "d \d\e F \d\e Y")}
160 
161     def delete(self, using=None, keep_parents=False):
162         if self.texto_integral:
163             self.texto_integral.delete()
164 
165         return models.Model.delete(
166             self, using=using, keep_parents=keep_parents)
167 
168     def save(self, force_insert=False, force_update=False, using=None,
169              update_fields=None):
170 
171         if not self.pk and self.texto_integral:
172             texto_integral = self.texto_integral
173             self.texto_integral = None
174             models.Model.save(self, force_insert=force_insert,
175                               force_update=force_update,
176                               using=using,
177                               update_fields=update_fields)
178             self.texto_integral = texto_integral
179 
180         return models.Model.save(self, force_insert=force_insert,
181                                  force_update=force_update,
182                                  using=using,
183                                  update_fields=update_fields)
184 
185 
186 @reversion.register()
187 class LegislacaoCitada(models.Model):
188     materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE)
189     norma = models.ForeignKey(NormaJuridica, on_delete=models.CASCADE)
190     disposicoes = models.CharField(
191         max_length=15, blank=True, verbose_name=_('Disposição'))
192     parte = models.CharField(
193         max_length=8, blank=True, verbose_name=_('Parte'))
194     livro = models.CharField(
195         max_length=7, blank=True, verbose_name=_('Livro'))
196     titulo = models.CharField(
197         max_length=7, blank=True, verbose_name=_('Título'))
198     capitulo = models.CharField(
199         max_length=7, blank=True, verbose_name=_('Capítulo'))
200     secao = models.CharField(
201         max_length=7, blank=True, verbose_name=_('Seção'))
202     subsecao = models.CharField(
203         max_length=7, blank=True, verbose_name=_('Subseção'))
204     artigo = models.CharField(
205         max_length=4, blank=True, verbose_name=_('Artigo'))
206     paragrafo = models.CharField(
207         max_length=3, blank=True, verbose_name=_('Parágrafo'))
208     inciso = models.CharField(
209         max_length=10, blank=True, verbose_name=_('Inciso'))
210     alinea = models.CharField(
211         max_length=3, blank=True, verbose_name=_('Alínea'))
212     item = models.CharField(
213         max_length=3, blank=True, verbose_name=_('Item'))
214 
215     class Meta:
216         verbose_name = _('Legislação')
217         verbose_name_plural = _('Legislações')
218 
219     def __str__(self):
220         return str(self.norma)
221 
222 
223 @reversion.register()
224 class TipoVinculoNormaJuridica(models.Model):
225     sigla = models.CharField(
226         max_length=1, blank=True, verbose_name=_('Sigla'))
227     descricao_ativa = models.CharField(
228         max_length=50, blank=True, verbose_name=_('Descrição Ativa'))
229     descricao_passiva = models.CharField(
230         max_length=50, blank=True, verbose_name=_('Descrição Passiva'))
231 
232     class Meta:
233         verbose_name = _('Tipo de Vínculo entre Normas Jurídicas')
234         verbose_name_plural = _('Tipos de Vínculos entre Normas Jurídicas')
235 
236     def __str__(self):
237         return self.descricao_ativa
238 
239 
240 @reversion.register()
241 class NormaRelacionada(models.Model):
242     norma_principal = models.ForeignKey(
243         NormaJuridica,
244         related_name='norma_principal',
245         on_delete=models.PROTECT,
246         verbose_name=_('Norma Principal'))
247     norma_relacionada = models.ForeignKey(
248         NormaJuridica,
249         related_name='norma_relacionada',
250         on_delete=models.PROTECT,
251         verbose_name=_('Norma Relacionada'))
252     tipo_vinculo = models.ForeignKey(
253         TipoVinculoNormaJuridica,
254         on_delete=models.PROTECT,
255         verbose_name=_('Tipo de Vínculo'))
256 
257     class Meta:
258         verbose_name = _('Norma Relacionada')
259         verbose_name_plural = _('Normas Relacionadas')
260 
261     def __str__(self):
262         return _('Principal: %(norma_principal)s'
263                  ' - Relacionada: %(norma_relacionada)s') % {
264             'norma_principal': self.norma_principal,
265             'norma_relacionada': self.norma_relacionada}
266 
267 
268 @reversion.register()
269 class AnexoNormaJuridica(models.Model):
270     norma = models.ForeignKey(
271         NormaJuridica,
272         related_name='norma',
273         on_delete=models.PROTECT,
274         verbose_name=_('Norma Juridica'))
275     anexo_arquivo = models.FileField(
276         blank=True,
277         null=True,
278         upload_to=norma_upload_path,
279         verbose_name=_('Arquivo Anexo'),
280         validators=[restringe_tipos_de_arquivo_txt])
281     ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),
282                                            choices=RANGE_ANOS)
283 
284     class Meta:
285         verbose_name = _('Anexo da Norma Juridica')
286         verbose_name_plural = _('Anexos da Norma Juridica')
287 
288     def __str__(self):
289         return _('Anexo: %(anexo)s da norma %(norma)s') % {
290             'anexo': self.anexo_arquivo, 'norma': self.norma}
291
```
--- 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/norma/models.py b/sapl/norma/models.py
--- a/sapl/norma/models.py
+++ b/sapl/norma/models.py
@@ -147,7 +147,8 @@
         return anexos
 
     def __str__(self):
-        return _('nº %(numero)s de %(data)s') % {
+        return _('%(tipo)s nº %(numero)s de %(data)s') % {
+            'tipo': self.tipo,
             'numero': self.numero,
             'data': defaultfilters.date(self.data, "d \d\e F \d\e Y")}

{"golden_diff": "diff --git a/sapl/norma/models.py b/sapl/norma/models.py\n--- a/sapl/norma/models.py\n+++ b/sapl/norma/models.py\n@@ -147,7 +147,8 @@\n         return anexos\n \n     def __str__(self):\n-        return _('n\u00ba %(numero)s de %(data)s') % {\n+        return _('%(tipo)s n\u00ba %(numero)s de %(data)s') % {\n+            'tipo': self.tipo,\n             'numero': self.numero,\n             'data': defaultfilters.date(self.data, \"d \\d\\e F \\d\\e Y\")}\n", "issue": "Norma Jur\u00eddica - Detalhe\nNos detalhes da norma jur\u00eddica, no que seria o t\u00edtulo da norma, n\u00e3o aparece mais o nome da norma.\r\nAntes aparecia \"Decreto Legislativo n\u00ba .....\"\r\n\r\n![image](https://user-images.githubusercontent.com/13314947/44723262-e39f6500-aaa5-11e8-9024-02c10e26c0b5.png)\r\n\nNorma Jur\u00eddica - Detalhe\nNos detalhes da norma jur\u00eddica, no que seria o t\u00edtulo da norma, n\u00e3o aparece mais o nome da norma.\r\nAntes aparecia \"Decreto Legislativo n\u00ba .....\"\r\n\r\n![image](https://user-images.githubusercontent.com/13314947/44723262-e39f6500-aaa5-11e8-9024-02c10e26c0b5.png)\r\n\n", "before_files": [{"content": "from django.contrib.contenttypes.fields import GenericRelation\nfrom django.db import models\nfrom django.template import defaultfilters\nfrom django.utils.translation import ugettext_lazy as _\nfrom model_utils import Choices\nimport reversion\n\nfrom sapl.compilacao.models import TextoArticulado\nfrom sapl.materia.models import MateriaLegislativa\nfrom sapl.utils import (RANGE_ANOS, YES_NO_CHOICES,\n                        restringe_tipos_de_arquivo_txt, texto_upload_path)\n\n\n@reversion.register()\nclass AssuntoNorma(models.Model):\n    assunto = models.CharField(max_length=50, verbose_name=_('Assunto'))\n    descricao = models.CharField(\n        max_length=250, blank=True, verbose_name=_('Descri\u00e7\u00e3o'))\n\n    class Meta:\n        verbose_name = _('Assunto de Norma Jur\u00eddica')\n        verbose_name_plural = _('Assuntos de Normas Jur\u00eddicas')\n        ordering = ['assunto']\n\n    def __str__(self):\n        return self.assunto\n\n\n@reversion.register()\nclass TipoNormaJuridica(models.Model):\n    # TODO transform into Domain Model and use an FK for the field\n    EQUIVALENTE_LEXML_CHOICES = ((name, name) for name in\n                                 ('constituicao',\n                                  'ementa.constitucional',\n                                  'lei.complementar',\n                                  'lei.delegada',\n                                  'lei',\n                                  'decreto.lei',\n                                  'medida.provisoria',\n                                  'decreto',\n                                  'lei.organica',\n                                  'emenda.lei.organica',\n                                  'decreto.legislativo',\n                                  'resolucao',\n                                  'regimento.interno',\n                                  ))\n    equivalente_lexml = models.CharField(\n        max_length=50,\n        blank=True,\n        verbose_name=_('Equivalente LexML'),\n        choices=EQUIVALENTE_LEXML_CHOICES)\n    sigla = models.CharField(max_length=3, verbose_name=_('Sigla'))\n    descricao = models.CharField(max_length=50, verbose_name=_('Descri\u00e7\u00e3o'))\n\n    class Meta:\n        verbose_name = _('Tipo de Norma Jur\u00eddica')\n        verbose_name_plural = _('Tipos de Norma Jur\u00eddica')\n        ordering = ['descricao']\n\n    def __str__(self):\n        return self.descricao\n\n\ndef norma_upload_path(instance, filename):\n    return texto_upload_path(instance, filename, subpath=instance.ano)\n\n\n@reversion.register()\nclass NormaJuridica(models.Model):\n    ESFERA_FEDERACAO_CHOICES = Choices(\n        ('M', 'municipal', _('Municipal')),\n        ('E', 'estadual', _('Estadual')),\n        ('F', 'federal', _('Federal')),\n    )\n\n    texto_integral = models.FileField(\n        blank=True,\n        null=True,\n        upload_to=norma_upload_path,\n        verbose_name=_('Texto Integral'),\n        validators=[restringe_tipos_de_arquivo_txt])\n    tipo = models.ForeignKey(\n        TipoNormaJuridica,\n        on_delete=models.PROTECT,\n        verbose_name=_('Tipo da Norma Juridica'))\n    materia = models.ForeignKey(\n        MateriaLegislativa, blank=True, null=True,\n        on_delete=models.PROTECT, verbose_name=_('Mat\u00e9ria'))\n    numero = models.CharField(\n        max_length=8,\n        verbose_name=_('N\u00famero'))\n    ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),\n                                           choices=RANGE_ANOS)\n    esfera_federacao = models.CharField(\n        max_length=1,\n        verbose_name=_('Esfera Federa\u00e7\u00e3o'),\n        choices=ESFERA_FEDERACAO_CHOICES)\n    data = models.DateField(blank=False, null=True, verbose_name=_('Data'))\n    data_publicacao = models.DateField(\n        blank=True, null=True, verbose_name=_('Data Publica\u00e7\u00e3o'))\n    veiculo_publicacao = models.CharField(\n        max_length=30,\n        blank=True,\n        verbose_name=_('Ve\u00edculo Publica\u00e7\u00e3o'))\n    pagina_inicio_publicacao = models.PositiveIntegerField(\n        blank=True, null=True, verbose_name=_('Pg. In\u00edcio'))\n    pagina_fim_publicacao = models.PositiveIntegerField(\n        blank=True, null=True, verbose_name=_('Pg. Fim'))\n    ementa = models.TextField(verbose_name=_('Ementa'))\n    indexacao = models.TextField(\n        blank=True, verbose_name=_('Indexa\u00e7\u00e3o'))\n    observacao = models.TextField(\n        blank=True, verbose_name=_('Observa\u00e7\u00e3o'))\n    complemento = models.NullBooleanField(\n        blank=True, verbose_name=_('Complementar ?'),\n        choices=YES_NO_CHOICES)\n    # XXX was a CharField (attention on migrate)\n    assuntos = models.ManyToManyField(\n        AssuntoNorma, blank=True,\n        verbose_name=_('Assuntos'))\n    data_vigencia = models.DateField(blank=True, null=True)\n    timestamp = models.DateTimeField(null=True)\n\n    texto_articulado = GenericRelation(\n        TextoArticulado, related_query_name='texto_articulado')\n\n    data_ultima_atualizacao = models.DateTimeField(\n        blank=True, null=True,\n        auto_now=True,\n        verbose_name=_('Data'))\n\n    class Meta:\n        verbose_name = _('Norma Jur\u00eddica')\n        verbose_name_plural = _('Normas Jur\u00eddicas')\n        ordering = ['-data', '-numero']\n\n    def get_normas_relacionadas(self):\n        principais = NormaRelacionada.objects.filter(\n            norma_principal=self.id)\n        relacionadas = NormaRelacionada.objects.filter(\n            norma_relacionada=self.id)\n        return (principais, relacionadas)\n\n    def get_anexos_norma_juridica(self):\n        anexos = AnexoNormaJuridica.objects.filter(\n            norma=self.id)\n        return anexos\n\n    def __str__(self):\n        return _('n\u00ba %(numero)s de %(data)s') % {\n            'numero': self.numero,\n            'data': defaultfilters.date(self.data, \"d \\d\\e F \\d\\e Y\")}\n\n    @property\n    def epigrafe(self):\n        return _('%(tipo)s n\u00ba %(numero)s de %(data)s') % {\n            'tipo': self.tipo,\n            'numero': self.numero,\n            'data': defaultfilters.date(self.data, \"d \\d\\e F \\d\\e Y\")}\n\n    def delete(self, using=None, keep_parents=False):\n        if self.texto_integral:\n            self.texto_integral.delete()\n\n        return models.Model.delete(\n            self, using=using, keep_parents=keep_parents)\n\n    def save(self, force_insert=False, force_update=False, using=None,\n             update_fields=None):\n\n        if not self.pk and self.texto_integral:\n            texto_integral = self.texto_integral\n            self.texto_integral = None\n            models.Model.save(self, force_insert=force_insert,\n                              force_update=force_update,\n                              using=using,\n                              update_fields=update_fields)\n            self.texto_integral = texto_integral\n\n        return models.Model.save(self, force_insert=force_insert,\n                                 force_update=force_update,\n                                 using=using,\n                                 update_fields=update_fields)\n\n\n@reversion.register()\nclass LegislacaoCitada(models.Model):\n    materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE)\n    norma = models.ForeignKey(NormaJuridica, on_delete=models.CASCADE)\n    disposicoes = models.CharField(\n        max_length=15, blank=True, verbose_name=_('Disposi\u00e7\u00e3o'))\n    parte = models.CharField(\n        max_length=8, blank=True, verbose_name=_('Parte'))\n    livro = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Livro'))\n    titulo = models.CharField(\n        max_length=7, blank=True, verbose_name=_('T\u00edtulo'))\n    capitulo = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Cap\u00edtulo'))\n    secao = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Se\u00e7\u00e3o'))\n    subsecao = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Subse\u00e7\u00e3o'))\n    artigo = models.CharField(\n        max_length=4, blank=True, verbose_name=_('Artigo'))\n    paragrafo = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Par\u00e1grafo'))\n    inciso = models.CharField(\n        max_length=10, blank=True, verbose_name=_('Inciso'))\n    alinea = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Al\u00ednea'))\n    item = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Item'))\n\n    class Meta:\n        verbose_name = _('Legisla\u00e7\u00e3o')\n        verbose_name_plural = _('Legisla\u00e7\u00f5es')\n\n    def __str__(self):\n        return str(self.norma)\n\n\n@reversion.register()\nclass TipoVinculoNormaJuridica(models.Model):\n    sigla = models.CharField(\n        max_length=1, blank=True, verbose_name=_('Sigla'))\n    descricao_ativa = models.CharField(\n        max_length=50, blank=True, verbose_name=_('Descri\u00e7\u00e3o Ativa'))\n    descricao_passiva = models.CharField(\n        max_length=50, blank=True, verbose_name=_('Descri\u00e7\u00e3o Passiva'))\n\n    class Meta:\n        verbose_name = _('Tipo de V\u00ednculo entre Normas Jur\u00eddicas')\n        verbose_name_plural = _('Tipos de V\u00ednculos entre Normas Jur\u00eddicas')\n\n    def __str__(self):\n        return self.descricao_ativa\n\n\n@reversion.register()\nclass NormaRelacionada(models.Model):\n    norma_principal = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma_principal',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Principal'))\n    norma_relacionada = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma_relacionada',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Relacionada'))\n    tipo_vinculo = models.ForeignKey(\n        TipoVinculoNormaJuridica,\n        on_delete=models.PROTECT,\n        verbose_name=_('Tipo de V\u00ednculo'))\n\n    class Meta:\n        verbose_name = _('Norma Relacionada')\n        verbose_name_plural = _('Normas Relacionadas')\n\n    def __str__(self):\n        return _('Principal: %(norma_principal)s'\n                 ' - Relacionada: %(norma_relacionada)s') % {\n            'norma_principal': self.norma_principal,\n            'norma_relacionada': self.norma_relacionada}\n\n\n@reversion.register()\nclass AnexoNormaJuridica(models.Model):\n    norma = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Juridica'))\n    anexo_arquivo = models.FileField(\n        blank=True,\n        null=True,\n        upload_to=norma_upload_path,\n        verbose_name=_('Arquivo Anexo'),\n        validators=[restringe_tipos_de_arquivo_txt])\n    ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),\n                                           choices=RANGE_ANOS)\n\n    class Meta:\n        verbose_name = _('Anexo da Norma Juridica')\n        verbose_name_plural = _('Anexos da Norma Juridica')\n\n    def __str__(self):\n        return _('Anexo: %(anexo)s da norma %(norma)s') % {\n            'anexo': self.anexo_arquivo, 'norma': self.norma}\n", "path": "sapl/norma/models.py"}], "after_files": [{"content": "from django.contrib.contenttypes.fields import GenericRelation\nfrom django.db import models\nfrom django.template import defaultfilters\nfrom django.utils.translation import ugettext_lazy as _\nfrom model_utils import Choices\nimport reversion\n\nfrom sapl.compilacao.models import TextoArticulado\nfrom sapl.materia.models import MateriaLegislativa\nfrom sapl.utils import (RANGE_ANOS, YES_NO_CHOICES,\n                        restringe_tipos_de_arquivo_txt, texto_upload_path)\n\n\n@reversion.register()\nclass AssuntoNorma(models.Model):\n    assunto = models.CharField(max_length=50, verbose_name=_('Assunto'))\n    descricao = models.CharField(\n        max_length=250, blank=True, verbose_name=_('Descri\u00e7\u00e3o'))\n\n    class Meta:\n        verbose_name = _('Assunto de Norma Jur\u00eddica')\n        verbose_name_plural = _('Assuntos de Normas Jur\u00eddicas')\n        ordering = ['assunto']\n\n    def __str__(self):\n        return self.assunto\n\n\n@reversion.register()\nclass TipoNormaJuridica(models.Model):\n    # TODO transform into Domain Model and use an FK for the field\n    EQUIVALENTE_LEXML_CHOICES = ((name, name) for name in\n                                 ('constituicao',\n                                  'ementa.constitucional',\n                                  'lei.complementar',\n                                  'lei.delegada',\n                                  'lei',\n                                  'decreto.lei',\n                                  'medida.provisoria',\n                                  'decreto',\n                                  'lei.organica',\n                                  'emenda.lei.organica',\n                                  'decreto.legislativo',\n                                  'resolucao',\n                                  'regimento.interno',\n                                  ))\n    equivalente_lexml = models.CharField(\n        max_length=50,\n        blank=True,\n        verbose_name=_('Equivalente LexML'),\n        choices=EQUIVALENTE_LEXML_CHOICES)\n    sigla = models.CharField(max_length=3, verbose_name=_('Sigla'))\n    descricao = models.CharField(max_length=50, verbose_name=_('Descri\u00e7\u00e3o'))\n\n    class Meta:\n        verbose_name = _('Tipo de Norma Jur\u00eddica')\n        verbose_name_plural = _('Tipos de Norma Jur\u00eddica')\n        ordering = ['descricao']\n\n    def __str__(self):\n        return self.descricao\n\n\ndef norma_upload_path(instance, filename):\n    return texto_upload_path(instance, filename, subpath=instance.ano)\n\n\n@reversion.register()\nclass NormaJuridica(models.Model):\n    ESFERA_FEDERACAO_CHOICES = Choices(\n        ('M', 'municipal', _('Municipal')),\n        ('E', 'estadual', _('Estadual')),\n        ('F', 'federal', _('Federal')),\n    )\n\n    texto_integral = models.FileField(\n        blank=True,\n        null=True,\n        upload_to=norma_upload_path,\n        verbose_name=_('Texto Integral'),\n        validators=[restringe_tipos_de_arquivo_txt])\n    tipo = models.ForeignKey(\n        TipoNormaJuridica,\n        on_delete=models.PROTECT,\n        verbose_name=_('Tipo da Norma Juridica'))\n    materia = models.ForeignKey(\n        MateriaLegislativa, blank=True, null=True,\n        on_delete=models.PROTECT, verbose_name=_('Mat\u00e9ria'))\n    numero = models.CharField(\n        max_length=8,\n        verbose_name=_('N\u00famero'))\n    ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),\n                                           choices=RANGE_ANOS)\n    esfera_federacao = models.CharField(\n        max_length=1,\n        verbose_name=_('Esfera Federa\u00e7\u00e3o'),\n        choices=ESFERA_FEDERACAO_CHOICES)\n    data = models.DateField(blank=False, null=True, verbose_name=_('Data'))\n    data_publicacao = models.DateField(\n        blank=True, null=True, verbose_name=_('Data Publica\u00e7\u00e3o'))\n    veiculo_publicacao = models.CharField(\n        max_length=30,\n        blank=True,\n        verbose_name=_('Ve\u00edculo Publica\u00e7\u00e3o'))\n    pagina_inicio_publicacao = models.PositiveIntegerField(\n        blank=True, null=True, verbose_name=_('Pg. In\u00edcio'))\n    pagina_fim_publicacao = models.PositiveIntegerField(\n        blank=True, null=True, verbose_name=_('Pg. Fim'))\n    ementa = models.TextField(verbose_name=_('Ementa'))\n    indexacao = models.TextField(\n        blank=True, verbose_name=_('Indexa\u00e7\u00e3o'))\n    observacao = models.TextField(\n        blank=True, verbose_name=_('Observa\u00e7\u00e3o'))\n    complemento = models.NullBooleanField(\n        blank=True, verbose_name=_('Complementar ?'),\n        choices=YES_NO_CHOICES)\n    # XXX was a CharField (attention on migrate)\n    assuntos = models.ManyToManyField(\n        AssuntoNorma, blank=True,\n        verbose_name=_('Assuntos'))\n    data_vigencia = models.DateField(blank=True, null=True)\n    timestamp = models.DateTimeField(null=True)\n\n    texto_articulado = GenericRelation(\n        TextoArticulado, related_query_name='texto_articulado')\n\n    data_ultima_atualizacao = models.DateTimeField(\n        blank=True, null=True,\n        auto_now=True,\n        verbose_name=_('Data'))\n\n    class Meta:\n        verbose_name = _('Norma Jur\u00eddica')\n        verbose_name_plural = _('Normas Jur\u00eddicas')\n        ordering = ['-data', '-numero']\n\n    def get_normas_relacionadas(self):\n        principais = NormaRelacionada.objects.filter(\n            norma_principal=self.id)\n        relacionadas = NormaRelacionada.objects.filter(\n            norma_relacionada=self.id)\n        return (principais, relacionadas)\n\n    def get_anexos_norma_juridica(self):\n        anexos = AnexoNormaJuridica.objects.filter(\n            norma=self.id)\n        return anexos\n\n    def __str__(self):\n        return _('%(tipo)s n\u00ba %(numero)s de %(data)s') % {\n            'tipo': self.tipo,\n            'numero': self.numero,\n            'data': defaultfilters.date(self.data, \"d \\d\\e F \\d\\e Y\")}\n\n    @property\n    def epigrafe(self):\n        return _('%(tipo)s n\u00ba %(numero)s de %(data)s') % {\n            'tipo': self.tipo,\n            'numero': self.numero,\n            'data': defaultfilters.date(self.data, \"d \\d\\e F \\d\\e Y\")}\n\n    def delete(self, using=None, keep_parents=False):\n        if self.texto_integral:\n            self.texto_integral.delete()\n\n        return models.Model.delete(\n            self, using=using, keep_parents=keep_parents)\n\n    def save(self, force_insert=False, force_update=False, using=None,\n             update_fields=None):\n\n        if not self.pk and self.texto_integral:\n            texto_integral = self.texto_integral\n            self.texto_integral = None\n            models.Model.save(self, force_insert=force_insert,\n                              force_update=force_update,\n                              using=using,\n                              update_fields=update_fields)\n            self.texto_integral = texto_integral\n\n        return models.Model.save(self, force_insert=force_insert,\n                                 force_update=force_update,\n                                 using=using,\n                                 update_fields=update_fields)\n\n\n@reversion.register()\nclass LegislacaoCitada(models.Model):\n    materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE)\n    norma = models.ForeignKey(NormaJuridica, on_delete=models.CASCADE)\n    disposicoes = models.CharField(\n        max_length=15, blank=True, verbose_name=_('Disposi\u00e7\u00e3o'))\n    parte = models.CharField(\n        max_length=8, blank=True, verbose_name=_('Parte'))\n    livro = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Livro'))\n    titulo = models.CharField(\n        max_length=7, blank=True, verbose_name=_('T\u00edtulo'))\n    capitulo = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Cap\u00edtulo'))\n    secao = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Se\u00e7\u00e3o'))\n    subsecao = models.CharField(\n        max_length=7, blank=True, verbose_name=_('Subse\u00e7\u00e3o'))\n    artigo = models.CharField(\n        max_length=4, blank=True, verbose_name=_('Artigo'))\n    paragrafo = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Par\u00e1grafo'))\n    inciso = models.CharField(\n        max_length=10, blank=True, verbose_name=_('Inciso'))\n    alinea = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Al\u00ednea'))\n    item = models.CharField(\n        max_length=3, blank=True, verbose_name=_('Item'))\n\n    class Meta:\n        verbose_name = _('Legisla\u00e7\u00e3o')\n        verbose_name_plural = _('Legisla\u00e7\u00f5es')\n\n    def __str__(self):\n        return str(self.norma)\n\n\n@reversion.register()\nclass TipoVinculoNormaJuridica(models.Model):\n    sigla = models.CharField(\n        max_length=1, blank=True, verbose_name=_('Sigla'))\n    descricao_ativa = models.CharField(\n        max_length=50, blank=True, verbose_name=_('Descri\u00e7\u00e3o Ativa'))\n    descricao_passiva = models.CharField(\n        max_length=50, blank=True, verbose_name=_('Descri\u00e7\u00e3o Passiva'))\n\n    class Meta:\n        verbose_name = _('Tipo de V\u00ednculo entre Normas Jur\u00eddicas')\n        verbose_name_plural = _('Tipos de V\u00ednculos entre Normas Jur\u00eddicas')\n\n    def __str__(self):\n        return self.descricao_ativa\n\n\n@reversion.register()\nclass NormaRelacionada(models.Model):\n    norma_principal = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma_principal',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Principal'))\n    norma_relacionada = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma_relacionada',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Relacionada'))\n    tipo_vinculo = models.ForeignKey(\n        TipoVinculoNormaJuridica,\n        on_delete=models.PROTECT,\n        verbose_name=_('Tipo de V\u00ednculo'))\n\n    class Meta:\n        verbose_name = _('Norma Relacionada')\n        verbose_name_plural = _('Normas Relacionadas')\n\n    def __str__(self):\n        return _('Principal: %(norma_principal)s'\n                 ' - Relacionada: %(norma_relacionada)s') % {\n            'norma_principal': self.norma_principal,\n            'norma_relacionada': self.norma_relacionada}\n\n\n@reversion.register()\nclass AnexoNormaJuridica(models.Model):\n    norma = models.ForeignKey(\n        NormaJuridica,\n        related_name='norma',\n        on_delete=models.PROTECT,\n        verbose_name=_('Norma Juridica'))\n    anexo_arquivo = models.FileField(\n        blank=True,\n        null=True,\n        upload_to=norma_upload_path,\n        verbose_name=_('Arquivo Anexo'),\n        validators=[restringe_tipos_de_arquivo_txt])\n    ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),\n                                           choices=RANGE_ANOS)\n\n    class Meta:\n        verbose_name = _('Anexo da Norma Juridica')\n        verbose_name_plural = _('Anexos da Norma Juridica')\n\n    def __str__(self):\n        return _('Anexo: %(anexo)s da norma %(norma)s') % {\n            'anexo': self.anexo_arquivo, 'norma': self.norma}\n", "path": "sapl/norma/models.py"}]}