Skip to content

Commit 8bf32fc

Browse files
committed
Adjust several searchable fields to match a changed interface in select2-field.js
- Legacy-Id: 18867
1 parent 84a52da commit 8bf32fc

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

ietf/doc/fields.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
from ietf.doc.models import Document, DocAlias
1515
from ietf.doc.utils import uppercase_std_abbreviated_name
1616

17+
def select2_id_doc_name(objs):
18+
return [{
19+
"id": o.pk,
20+
"text": escape(uppercase_std_abbreviated_name(o.name)),
21+
} for o in objs]
22+
23+
1724
def select2_id_doc_name_json(objs):
18-
return json.dumps([{ "id": o.pk, "text": escape(uppercase_std_abbreviated_name(o.name)) } for o in objs])
25+
return json.dumps(select2_id_doc_name(objs))
1926

2027
# FIXME: select2 version 4 uses a standard select for the AJAX case -
2128
# switching to that would allow us to derive from the standard
@@ -71,7 +78,9 @@ def prepare_value(self, value):
7178
if isinstance(value, self.model):
7279
value = [value]
7380

74-
self.widget.attrs["data-pre"] = select2_id_doc_name_json(value)
81+
self.widget.attrs["data-pre"] = json.dumps({
82+
d['id']: d for d in select2_id_doc_name(value)
83+
})
7584

7685
# doing this in the constructor is difficult because the URL
7786
# patterns may not have been fully constructed there yet

ietf/ipr/fields.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212

1313
from ietf.ipr.models import IprDisclosureBase
1414

15+
def select2_id_ipr_title(objs):
16+
return [{
17+
"id": o.pk,
18+
"text": escape("%s <%s>" % (o.title, o.time.date().isoformat())),
19+
} for o in objs]
20+
1521
def select2_id_ipr_title_json(value):
16-
return json.dumps([{ "id": o.pk, "text": escape("%s <%s>" % (o.title, o.time.date().isoformat())) } for o in value])
22+
return json.dumps(select2_id_ipr_title(value))
1723

1824
class SearchableIprDisclosuresField(forms.CharField):
1925
"""Server-based multi-select field for choosing documents using
@@ -61,7 +67,9 @@ def prepare_value(self, value):
6167
if isinstance(value, self.model):
6268
value = [value]
6369

64-
self.widget.attrs["data-pre"] = select2_id_ipr_title_json(value)
70+
self.widget.attrs["data-pre"] = json.dumps({
71+
d['id']: d for d in select2_id_ipr_title(value)
72+
})
6573

6674
# doing this in the constructor is difficult because the URL
6775
# patterns may not have been fully constructed there yet

ietf/liaisons/fields.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010

1111
from ietf.liaisons.models import LiaisonStatement
1212

13+
def select2_id_liaison(objs):
14+
return [{
15+
"id": o.pk,
16+
"text":"[{}] {}".format(o.pk, escape(o.title)),
17+
} for o in objs]
18+
1319
def select2_id_liaison_json(objs):
14-
return json.dumps([{ "id": o.pk, "text":"[{}] {}".format(o.pk, escape(o.title)) } for o in objs])
20+
return json.dumps(select2_id_liaison(objs))
1521

1622
def select2_id_group_json(objs):
1723
return json.dumps([{ "id": o.pk, "text": escape(o.acronym) } for o in objs])
@@ -56,7 +62,9 @@ def prepare_value(self, value):
5662
if isinstance(value, LiaisonStatement):
5763
value = [value]
5864

59-
self.widget.attrs["data-pre"] = select2_id_liaison_json(value)
65+
self.widget.attrs["data-pre"] = json.dumps({
66+
d['id']: d for d in select2_id_liaison(value)
67+
})
6068

6169
# doing this in the constructor is difficult because the URL
6270
# patterns may not have been fully constructed there yet

0 commit comments

Comments
 (0)