File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed
Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1414from ietf .doc .models import Document , DocAlias
1515from 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+
1724def 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
Original file line number Diff line number Diff line change 1212
1313from 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+
1521def 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
1824class 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
Original file line number Diff line number Diff line change 1010
1111from 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+
1319def 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
1622def 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
You can’t perform that action at this time.
0 commit comments