File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,18 +25,29 @@ def validate(self, value):
2525 validate_email (email )
2626
2727def yyyymmdd_to_strftime_format (fmt ):
28- return (fmt
29- .replace ("yyyy" , "%Y" )
30- .replace ("yy" , "%y" )
31- .replace ("mm" , "%m" )
32- .replace ("m" , "%-m" )
33- .replace ("MM" , "%B" )
34- .replace ("M" , "%b" )
35- .replace ("dd" , "%d" )
36- .replace ("d" , "%-d" )
37- .replace ("MM" , "%A" )
38- .replace ("M" , "%a" )
39- )
28+ translation_table = sorted ([
29+ ("yyyy" , "%Y" ),
30+ ("yy" , "%y" ),
31+ ("mm" , "%m" ),
32+ ("m" , "%-m" ),
33+ ("MM" , "%B" ),
34+ ("M" , "%b" ),
35+ ("dd" , "%d" ),
36+ ("d" , "%-d" ),
37+ ], key = lambda t : len (t [0 ]), reverse = True )
38+
39+ res = ""
40+ remaining = fmt
41+ while remaining :
42+ for pattern , replacement in translation_table :
43+ if remaining .startswith (pattern ):
44+ res += replacement
45+ remaining = remaining [len (pattern ):]
46+ break
47+ else :
48+ res += remaining [0 ]
49+ remaining = remaining [1 :]
50+ return res
4051
4152class DatepickerDateField (forms .DateField ):
4253 """DateField with some glue for triggering JS Bootstrap datepicker."""
You can’t perform that action at this time.
0 commit comments