We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Ordenar proposições não recebidas por qualquer campo do cabeçalho
Na tela do operador de consulta às proposições não recebidas,

![visao operador](https://user-images.githubusercontent.com/22030378/40062199-3c035098-584a-11e8-9ea9-a472dce15bde.png)

 seria útil que o cabeçalho possibilitasse a ordenação ascendente/descendente por qualquer um dos campos, conforme escolha do usuário. É a mesma funcionalidade na visão das proposições pelo autor:

![visao autor](https://user-images.githubusercontent.com/22030378/40062085-e72132b6-5849-11e8-9a71-73690ea85fcd.png)

Tal recurso, aliado ao recebimento de proposições sem recibo, agilizará muito os processos internos, sobretudo nas Câmaras com grande volume de matérias legislativas a cada sessão.



--- 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/base/templatetags/common_tags.py`
Content:
```
1 from compressor.utils import get_class
2 from django import template
3 from django.template.defaultfilters import stringfilter
4 
5 from sapl.base.models import AppConfig
6 from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa
7 from sapl.norma.models import NormaJuridica
8 from sapl.parlamentares.models import Filiacao
9 from sapl.utils import filiacao_data
10 
11 register = template.Library()
12 
13 
14 @register.simple_tag
15 def field_verbose_name(instance, field_name):
16     return instance._meta.get_field(field_name).verbose_name
17 
18 
19 @register.simple_tag
20 def fieldclass_verbose_name(class_name, field_name):
21     cls = get_class(class_name)
22     return cls._meta.get_field(field_name).verbose_name
23 
24 
25 @register.simple_tag
26 def model_verbose_name(class_name):
27     model = get_class(class_name)
28     return model._meta.verbose_name
29 
30 
31 @register.simple_tag
32 def model_verbose_name_plural(class_name):
33     model = get_class(class_name)
34     return model._meta.verbose_name_plural
35 
36 
37 @register.filter
38 def lookup(d, key):
39     return d[key] if key in d else []
40 
41 
42 @register.filter
43 def isinst(value, class_str):
44     classe = value.__class__.__name__
45     return classe == class_str
46 
47 
48 @register.filter
49 @stringfilter
50 def strip_hash(value):
51     return value.split('/')[0][1:]
52 
53 
54 @register.filter
55 def get_add_perm(value, arg):
56     perm = value
57     view = arg
58 
59     try:
60         nome_app = view.__class__.model._meta.app_label
61     except AttributeError:
62         return None
63     nome_model = view.__class__.model.__name__.lower()
64     can_add = '.add_' + nome_model
65 
66     return perm.__contains__(nome_app + can_add)
67 
68 
69 @register.filter
70 def get_change_perm(value, arg):
71     perm = value
72     view = arg
73 
74     try:
75         nome_app = view.__class__.model._meta.app_label
76     except AttributeError:
77         return None
78     nome_model = view.__class__.model.__name__.lower()
79     can_change = '.change_' + nome_model
80 
81     return perm.__contains__(nome_app + can_change)
82 
83 
84 @register.filter
85 def get_delete_perm(value, arg):
86     perm = value
87     view = arg
88 
89     try:
90         nome_app = view.__class__.model._meta.app_label
91     except AttributeError:
92         return None
93     nome_model = view.__class__.model.__name__.lower()
94     can_delete = '.delete_' + nome_model
95 
96     return perm.__contains__(nome_app + can_delete)
97 
98 
99 @register.filter
100 def ultima_filiacao(value):
101     parlamentar = value
102 
103     ultima_filiacao = Filiacao.objects.filter(
104         parlamentar=parlamentar).order_by('-data').first()
105 
106     if ultima_filiacao:
107         return ultima_filiacao.partido
108     else:
109         return None
110 
111 
112 @register.filter
113 def get_config_attr(attribute):
114     return AppConfig.attr(attribute)
115 
116 
117 @register.filter
118 def str2intabs(value):
119     if not isinstance(value, str):
120         return ''
121     try:
122         v = int(value)
123         v = abs(v)
124         return v
125     except:
126         return ''
127 
128 
129 @register.filter
130 def has_iframe(request):
131 
132     iframe = request.session.get('iframe', False)
133     if not iframe and 'iframe' in request.GET:
134         ival = request.GET['iframe']
135         if ival and int(ival) == 1:
136             request.session['iframe'] = True
137             return True
138     elif 'iframe' in request.GET:
139         ival = request.GET['iframe']
140         if ival and int(ival) == 0:
141             del request.session['iframe']
142             return False
143 
144     return iframe
145 
146 
147 @register.filter
148 def url(value):
149     if value.startswith('http://') or value.startswith('https://'):
150         return True
151     return False
152 
153 
154 @register.filter
155 def cronometro_to_seconds(value):
156     if not AppConfig.attr('cronometro_' + value):
157         return 0
158 
159     m, s, x = AppConfig.attr(
160         'cronometro_' + value).isoformat().split(':')
161 
162     return 60 * int(m) + int(s)
163 
164 
165 @register.filter
166 def to_list_pk(object_list):
167     return [o.pk for o in object_list]
168 
169 
170 @register.filter
171 def search_get_model(object):
172     if type(object) == MateriaLegislativa:
173         return 'm'
174     elif type(object) == DocumentoAcessorio:
175         return 'd'
176     elif type(object) == NormaJuridica:
177         return 'n'
178 
179     return None
180 
181 
182 @register.filter
183 def urldetail_content_type(obj, value):
184     return '%s:%s_detail' % (
185         value._meta.app_config.name, obj.content_type.model)
186 
187 
188 @register.filter
189 def urldetail(obj):
190     return '%s:%s_detail' % (
191         obj._meta.app_config.name, obj._meta.model_name)
192 
193 
194 @register.filter
195 def filiacao_data_filter(parlamentar, data_inicio):
196     return filiacao_data(parlamentar, data_inicio)
197 
198 
199 @register.filter
200 def filiacao_intervalo_filter(parlamentar, date_range):
201     return filiacao_data(parlamentar, date_range[0], date_range[1])
202
```
--- 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/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py
--- a/sapl/base/templatetags/common_tags.py
+++ b/sapl/base/templatetags/common_tags.py
@@ -3,7 +3,7 @@
 from django.template.defaultfilters import stringfilter
 
 from sapl.base.models import AppConfig
-from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa
+from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa, Proposicao
 from sapl.norma.models import NormaJuridica
 from sapl.parlamentares.models import Filiacao
 from sapl.utils import filiacao_data
@@ -11,6 +11,11 @@
 register = template.Library()
 
 
+@register.simple_tag
+def define(arg):
+  return arg
+
+
 @register.simple_tag
 def field_verbose_name(instance, field_name):
     return instance._meta.get_field(field_name).verbose_name
@@ -34,6 +39,30 @@
     return model._meta.verbose_name_plural
 
 
+@register.filter
+def split(value, arg):
+    return value.split(arg)
+
+
+@register.filter
+def sort_by_keys(value, key):
+    transformed = []
+    id_props = [x.id for x in value]
+    qs = Proposicao.objects.filter(pk__in=id_props)
+    key_descricao = {'1': 'data_envio',
+                        '-1': '-data_envio',
+                        '2': 'tipo',
+                        '-2': '-tipo',
+                        '3': 'descricao',
+                        '-3': '-descricao',
+                        '4': 'autor',
+                        '-4': '-autor'
+                        }
+
+    transformed = qs.order_by(key_descricao[key])
+    return transformed
+
+
 @register.filter
 def lookup(d, key):
     return d[key] if key in d else []

{"golden_diff": "diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py\n--- a/sapl/base/templatetags/common_tags.py\n+++ b/sapl/base/templatetags/common_tags.py\n@@ -3,7 +3,7 @@\n from django.template.defaultfilters import stringfilter\n \n from sapl.base.models import AppConfig\n-from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa\n+from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa, Proposicao\n from sapl.norma.models import NormaJuridica\n from sapl.parlamentares.models import Filiacao\n from sapl.utils import filiacao_data\n@@ -11,6 +11,11 @@\n register = template.Library()\n \n \n+@register.simple_tag\n+def define(arg):\n+  return arg\n+\n+\n @register.simple_tag\n def field_verbose_name(instance, field_name):\n     return instance._meta.get_field(field_name).verbose_name\n@@ -34,6 +39,30 @@\n     return model._meta.verbose_name_plural\n \n \n+@register.filter\n+def split(value, arg):\n+    return value.split(arg)\n+\n+\n+@register.filter\n+def sort_by_keys(value, key):\n+    transformed = []\n+    id_props = [x.id for x in value]\n+    qs = Proposicao.objects.filter(pk__in=id_props)\n+    key_descricao = {'1': 'data_envio',\n+                        '-1': '-data_envio',\n+                        '2': 'tipo',\n+                        '-2': '-tipo',\n+                        '3': 'descricao',\n+                        '-3': '-descricao',\n+                        '4': 'autor',\n+                        '-4': '-autor'\n+                        }\n+\n+    transformed = qs.order_by(key_descricao[key])\n+    return transformed\n+\n+\n @register.filter\n def lookup(d, key):\n     return d[key] if key in d else []\n", "issue": "Ordenar proposi\u00e7\u00f5es n\u00e3o recebidas por qualquer campo do cabe\u00e7alho\nNa tela do operador de consulta \u00e0s proposi\u00e7\u00f5es n\u00e3o recebidas,\r\n\r\n![visao operador](https://user-images.githubusercontent.com/22030378/40062199-3c035098-584a-11e8-9ea9-a472dce15bde.png)\r\n\r\n seria \u00fatil que o cabe\u00e7alho possibilitasse a ordena\u00e7\u00e3o ascendente/descendente por qualquer um dos campos, conforme escolha do usu\u00e1rio. \u00c9 a mesma funcionalidade na vis\u00e3o das proposi\u00e7\u00f5es pelo autor:\r\n\r\n![visao autor](https://user-images.githubusercontent.com/22030378/40062085-e72132b6-5849-11e8-9a71-73690ea85fcd.png)\r\n\r\nTal recurso, aliado ao recebimento de proposi\u00e7\u00f5es sem recibo, agilizar\u00e1 muito os processos internos, sobretudo nas C\u00e2maras com grande volume de mat\u00e9rias legislativas a cada sess\u00e3o.\r\n\r\n\n", "before_files": [{"content": "from compressor.utils import get_class\nfrom django import template\nfrom django.template.defaultfilters import stringfilter\n\nfrom sapl.base.models import AppConfig\nfrom sapl.materia.models import DocumentoAcessorio, MateriaLegislativa\nfrom sapl.norma.models import NormaJuridica\nfrom sapl.parlamentares.models import Filiacao\nfrom sapl.utils import filiacao_data\n\nregister = template.Library()\n\n\n@register.simple_tag\ndef field_verbose_name(instance, field_name):\n    return instance._meta.get_field(field_name).verbose_name\n\n\n@register.simple_tag\ndef fieldclass_verbose_name(class_name, field_name):\n    cls = get_class(class_name)\n    return cls._meta.get_field(field_name).verbose_name\n\n\n@register.simple_tag\ndef model_verbose_name(class_name):\n    model = get_class(class_name)\n    return model._meta.verbose_name\n\n\n@register.simple_tag\ndef model_verbose_name_plural(class_name):\n    model = get_class(class_name)\n    return model._meta.verbose_name_plural\n\n\n@register.filter\ndef lookup(d, key):\n    return d[key] if key in d else []\n\n\n@register.filter\ndef isinst(value, class_str):\n    classe = value.__class__.__name__\n    return classe == class_str\n\n\n@register.filter\n@stringfilter\ndef strip_hash(value):\n    return value.split('/')[0][1:]\n\n\n@register.filter\ndef get_add_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_add = '.add_' + nome_model\n\n    return perm.__contains__(nome_app + can_add)\n\n\n@register.filter\ndef get_change_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_change = '.change_' + nome_model\n\n    return perm.__contains__(nome_app + can_change)\n\n\n@register.filter\ndef get_delete_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_delete = '.delete_' + nome_model\n\n    return perm.__contains__(nome_app + can_delete)\n\n\n@register.filter\ndef ultima_filiacao(value):\n    parlamentar = value\n\n    ultima_filiacao = Filiacao.objects.filter(\n        parlamentar=parlamentar).order_by('-data').first()\n\n    if ultima_filiacao:\n        return ultima_filiacao.partido\n    else:\n        return None\n\n\n@register.filter\ndef get_config_attr(attribute):\n    return AppConfig.attr(attribute)\n\n\n@register.filter\ndef str2intabs(value):\n    if not isinstance(value, str):\n        return ''\n    try:\n        v = int(value)\n        v = abs(v)\n        return v\n    except:\n        return ''\n\n\n@register.filter\ndef has_iframe(request):\n\n    iframe = request.session.get('iframe', False)\n    if not iframe and 'iframe' in request.GET:\n        ival = request.GET['iframe']\n        if ival and int(ival) == 1:\n            request.session['iframe'] = True\n            return True\n    elif 'iframe' in request.GET:\n        ival = request.GET['iframe']\n        if ival and int(ival) == 0:\n            del request.session['iframe']\n            return False\n\n    return iframe\n\n\n@register.filter\ndef url(value):\n    if value.startswith('http://') or value.startswith('https://'):\n        return True\n    return False\n\n\n@register.filter\ndef cronometro_to_seconds(value):\n    if not AppConfig.attr('cronometro_' + value):\n        return 0\n\n    m, s, x = AppConfig.attr(\n        'cronometro_' + value).isoformat().split(':')\n\n    return 60 * int(m) + int(s)\n\n\n@register.filter\ndef to_list_pk(object_list):\n    return [o.pk for o in object_list]\n\n\n@register.filter\ndef search_get_model(object):\n    if type(object) == MateriaLegislativa:\n        return 'm'\n    elif type(object) == DocumentoAcessorio:\n        return 'd'\n    elif type(object) == NormaJuridica:\n        return 'n'\n\n    return None\n\n\n@register.filter\ndef urldetail_content_type(obj, value):\n    return '%s:%s_detail' % (\n        value._meta.app_config.name, obj.content_type.model)\n\n\n@register.filter\ndef urldetail(obj):\n    return '%s:%s_detail' % (\n        obj._meta.app_config.name, obj._meta.model_name)\n\n\n@register.filter\ndef filiacao_data_filter(parlamentar, data_inicio):\n    return filiacao_data(parlamentar, data_inicio)\n\n\n@register.filter\ndef filiacao_intervalo_filter(parlamentar, date_range):\n    return filiacao_data(parlamentar, date_range[0], date_range[1])\n", "path": "sapl/base/templatetags/common_tags.py"}], "after_files": [{"content": "from compressor.utils import get_class\nfrom django import template\nfrom django.template.defaultfilters import stringfilter\n\nfrom sapl.base.models import AppConfig\nfrom sapl.materia.models import DocumentoAcessorio, MateriaLegislativa, Proposicao\nfrom sapl.norma.models import NormaJuridica\nfrom sapl.parlamentares.models import Filiacao\nfrom sapl.utils import filiacao_data\n\nregister = template.Library()\n\n\n@register.simple_tag\ndef define(arg):\n  return arg\n\n\n@register.simple_tag\ndef field_verbose_name(instance, field_name):\n    return instance._meta.get_field(field_name).verbose_name\n\n\n@register.simple_tag\ndef fieldclass_verbose_name(class_name, field_name):\n    cls = get_class(class_name)\n    return cls._meta.get_field(field_name).verbose_name\n\n\n@register.simple_tag\ndef model_verbose_name(class_name):\n    model = get_class(class_name)\n    return model._meta.verbose_name\n\n\n@register.simple_tag\ndef model_verbose_name_plural(class_name):\n    model = get_class(class_name)\n    return model._meta.verbose_name_plural\n\n\n@register.filter\ndef split(value, arg):\n    return value.split(arg)\n\n\n@register.filter\ndef sort_by_keys(value, key):\n    transformed = []\n    id_props = [x.id for x in value]\n    qs = Proposicao.objects.filter(pk__in=id_props)\n    key_descricao = {'1': 'data_envio',\n                        '-1': '-data_envio',\n                        '2': 'tipo',\n                        '-2': '-tipo',\n                        '3': 'descricao',\n                        '-3': '-descricao',\n                        '4': 'autor',\n                        '-4': '-autor'\n                        }\n\n    transformed = qs.order_by(key_descricao[key])\n    return transformed\n\n\n@register.filter\ndef lookup(d, key):\n    return d[key] if key in d else []\n\n\n@register.filter\ndef isinst(value, class_str):\n    classe = value.__class__.__name__\n    return classe == class_str\n\n\n@register.filter\n@stringfilter\ndef strip_hash(value):\n    return value.split('/')[0][1:]\n\n\n@register.filter\ndef get_add_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_add = '.add_' + nome_model\n\n    return perm.__contains__(nome_app + can_add)\n\n\n@register.filter\ndef get_change_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_change = '.change_' + nome_model\n\n    return perm.__contains__(nome_app + can_change)\n\n\n@register.filter\ndef get_delete_perm(value, arg):\n    perm = value\n    view = arg\n\n    try:\n        nome_app = view.__class__.model._meta.app_label\n    except AttributeError:\n        return None\n    nome_model = view.__class__.model.__name__.lower()\n    can_delete = '.delete_' + nome_model\n\n    return perm.__contains__(nome_app + can_delete)\n\n\n@register.filter\ndef ultima_filiacao(value):\n    parlamentar = value\n\n    ultima_filiacao = Filiacao.objects.filter(\n        parlamentar=parlamentar).order_by('-data').first()\n\n    if ultima_filiacao:\n        return ultima_filiacao.partido\n    else:\n        return None\n\n\n@register.filter\ndef get_config_attr(attribute):\n    return AppConfig.attr(attribute)\n\n\n@register.filter\ndef str2intabs(value):\n    if not isinstance(value, str):\n        return ''\n    try:\n        v = int(value)\n        v = abs(v)\n        return v\n    except:\n        return ''\n\n\n@register.filter\ndef has_iframe(request):\n\n    iframe = request.session.get('iframe', False)\n    if not iframe and 'iframe' in request.GET:\n        ival = request.GET['iframe']\n        if ival and int(ival) == 1:\n            request.session['iframe'] = True\n            return True\n    elif 'iframe' in request.GET:\n        ival = request.GET['iframe']\n        if ival and int(ival) == 0:\n            del request.session['iframe']\n            return False\n\n    return iframe\n\n\n@register.filter\ndef url(value):\n    if value.startswith('http://') or value.startswith('https://'):\n        return True\n    return False\n\n\n@register.filter\ndef cronometro_to_seconds(value):\n    if not AppConfig.attr('cronometro_' + value):\n        return 0\n\n    m, s, x = AppConfig.attr(\n        'cronometro_' + value).isoformat().split(':')\n\n    return 60 * int(m) + int(s)\n\n\n@register.filter\ndef to_list_pk(object_list):\n    return [o.pk for o in object_list]\n\n\n@register.filter\ndef search_get_model(object):\n    if type(object) == MateriaLegislativa:\n        return 'm'\n    elif type(object) == DocumentoAcessorio:\n        return 'd'\n    elif type(object) == NormaJuridica:\n        return 'n'\n\n    return None\n\n\n@register.filter\ndef urldetail_content_type(obj, value):\n    return '%s:%s_detail' % (\n        value._meta.app_config.name, obj.content_type.model)\n\n\n@register.filter\ndef urldetail(obj):\n    return '%s:%s_detail' % (\n        obj._meta.app_config.name, obj._meta.model_name)\n\n\n@register.filter\ndef filiacao_data_filter(parlamentar, data_inicio):\n    return filiacao_data(parlamentar, data_inicio)\n\n\n@register.filter\ndef filiacao_intervalo_filter(parlamentar, date_range):\n    return filiacao_data(parlamentar, date_range[0], date_range[1])\n", "path": "sapl/base/templatetags/common_tags.py"}]}