Adjust several searchable fields to match a changed interface in select2-field.js
- Legacy-Id: 18867
This commit is contained in:
parent
84a52dad81
commit
8bf32fc890
|
@ -14,8 +14,15 @@ import debug # pyflakes:ignore
|
|||
from ietf.doc.models import Document, DocAlias
|
||||
from ietf.doc.utils import uppercase_std_abbreviated_name
|
||||
|
||||
def select2_id_doc_name(objs):
|
||||
return [{
|
||||
"id": o.pk,
|
||||
"text": escape(uppercase_std_abbreviated_name(o.name)),
|
||||
} for o in objs]
|
||||
|
||||
|
||||
def select2_id_doc_name_json(objs):
|
||||
return json.dumps([{ "id": o.pk, "text": escape(uppercase_std_abbreviated_name(o.name)) } for o in objs])
|
||||
return json.dumps(select2_id_doc_name(objs))
|
||||
|
||||
# FIXME: select2 version 4 uses a standard select for the AJAX case -
|
||||
# switching to that would allow us to derive from the standard
|
||||
|
@ -71,7 +78,9 @@ class SearchableDocumentsField(forms.CharField):
|
|||
if isinstance(value, self.model):
|
||||
value = [value]
|
||||
|
||||
self.widget.attrs["data-pre"] = select2_id_doc_name_json(value)
|
||||
self.widget.attrs["data-pre"] = json.dumps({
|
||||
d['id']: d for d in select2_id_doc_name(value)
|
||||
})
|
||||
|
||||
# doing this in the constructor is difficult because the URL
|
||||
# patterns may not have been fully constructed there yet
|
||||
|
|
|
@ -12,8 +12,14 @@ import debug # pyflakes:ignore
|
|||
|
||||
from ietf.ipr.models import IprDisclosureBase
|
||||
|
||||
def select2_id_ipr_title(objs):
|
||||
return [{
|
||||
"id": o.pk,
|
||||
"text": escape("%s <%s>" % (o.title, o.time.date().isoformat())),
|
||||
} for o in objs]
|
||||
|
||||
def select2_id_ipr_title_json(value):
|
||||
return json.dumps([{ "id": o.pk, "text": escape("%s <%s>" % (o.title, o.time.date().isoformat())) } for o in value])
|
||||
return json.dumps(select2_id_ipr_title(value))
|
||||
|
||||
class SearchableIprDisclosuresField(forms.CharField):
|
||||
"""Server-based multi-select field for choosing documents using
|
||||
|
@ -61,7 +67,9 @@ class SearchableIprDisclosuresField(forms.CharField):
|
|||
if isinstance(value, self.model):
|
||||
value = [value]
|
||||
|
||||
self.widget.attrs["data-pre"] = select2_id_ipr_title_json(value)
|
||||
self.widget.attrs["data-pre"] = json.dumps({
|
||||
d['id']: d for d in select2_id_ipr_title(value)
|
||||
})
|
||||
|
||||
# doing this in the constructor is difficult because the URL
|
||||
# patterns may not have been fully constructed there yet
|
||||
|
|
|
@ -10,8 +10,14 @@ from django.urls import reverse as urlreverse
|
|||
|
||||
from ietf.liaisons.models import LiaisonStatement
|
||||
|
||||
def select2_id_liaison(objs):
|
||||
return [{
|
||||
"id": o.pk,
|
||||
"text":"[{}] {}".format(o.pk, escape(o.title)),
|
||||
} for o in objs]
|
||||
|
||||
def select2_id_liaison_json(objs):
|
||||
return json.dumps([{ "id": o.pk, "text":"[{}] {}".format(o.pk, escape(o.title)) } for o in objs])
|
||||
return json.dumps(select2_id_liaison(objs))
|
||||
|
||||
def select2_id_group_json(objs):
|
||||
return json.dumps([{ "id": o.pk, "text": escape(o.acronym) } for o in objs])
|
||||
|
@ -56,7 +62,9 @@ class SearchableLiaisonStatementsField(forms.CharField):
|
|||
if isinstance(value, LiaisonStatement):
|
||||
value = [value]
|
||||
|
||||
self.widget.attrs["data-pre"] = select2_id_liaison_json(value)
|
||||
self.widget.attrs["data-pre"] = json.dumps({
|
||||
d['id']: d for d in select2_id_liaison(value)
|
||||
})
|
||||
|
||||
# doing this in the constructor is difficult because the URL
|
||||
# patterns may not have been fully constructed there yet
|
||||
|
|
Loading…
Reference in a new issue