@@ -18,7 +18,7 @@ class BasePickerInput(get_base_input()):
1818 'options' : {} # final merged options
1919 }
2020 options = {} # options extended by user
21- options_parameter = {} # options passed as parameter
21+ options_param = {} # options passed as parameter
2222 _default_options = {
2323 'showClose' : True ,
2424 'showClear' : True ,
@@ -71,31 +71,33 @@ def format_js2py(cls, datetime_format):
7171 datetime_format = datetime_format .replace (js_format , py_format )
7272 return datetime_format
7373
74- def __init__ (self , attrs = {}, format = None , options = {}):
74+ def __init__ (self , attrs = None , format = None , options = None ):
75+ self .format_param = format
76+ self .options_param = options if options else {}
7577 self .config = self ._default_config .copy ()
7678 self .config ['id' ] = DatePickerDictionary .generate_id ()
7779 self .config ['picker_type' ] = self .picker_type
78- self .config ['options' ] = self ._calculate_options (options )
79- # Configure Format
80- self .format_parameter = format
81- if format is None :
82- format = self .format
83- if self .config ['options' ].get ('format' ):
84- format = self .format_js2py (self .config ['options' ].get ('format' ))
85- else :
86- self .config ['options' ]['format' ] = self .format_py2js (format )
87- # Initilize
80+ self .config ['options' ] = self ._calculate_options ()
81+ attrs = attrs if attrs else {}
8882 if 'class' not in attrs :
8983 attrs ['class' ] = 'form-control'
90- super ().__init__ (attrs , format )
84+ super ().__init__ (attrs , self . _calculate_format () )
9185
92- def _calculate_options (self , options ):
93- self .options_parameter = options
86+ def _calculate_options (self ):
9487 _options = self ._default_options .copy ()
9588 _options .update (self .options )
96- _options .update (self .options_parameter )
89+ if self .options_param :
90+ _options .update (self .options_param )
9791 return _options
9892
93+ def _calculate_format (self ):
94+ _format = self .format_param if self .format_param else self .format
95+ if self .config ['options' ].get ('format' ):
96+ _format = self .format_js2py (self .config ['options' ].get ('format' ))
97+ else :
98+ self .config ['options' ]['format' ] = self .format_py2js (_format )
99+ return _format
100+
99101 def get_context (self , name , value , attrs ):
100102 context = super ().get_context (
101103 name , value , attrs )
@@ -125,8 +127,8 @@ def end_of(self, event_id, import_options=True):
125127 if import_options :
126128 backup_moment_format = self .config ['options' ]['format' ]
127129 self .config ['options' ].update (linked_picker .config ['options' ])
128- self .config ['options' ].update (self .options_parameter )
129- if self .format_parameter or 'format' in self .options_parameter :
130+ self .config ['options' ].update (self .options_param )
131+ if self .format_param or 'format' in self .options_param :
130132 self .config ['options' ]['format' ] = backup_moment_format
131133 else :
132134 self .format = linked_picker .format
0 commit comments