Sfoglia il codice sorgente

[fix] exception if locale doesn't have a date format

marc 8 anni fa
parent
commit
a4c77f88d0
1 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 7
    1
      searx/utils.py

+ 7
- 1
searx/utils.py Vedi File

@@ -206,7 +206,13 @@ def format_date_by_locale(date, locale_string):
206 206
     if locale_string == 'all':
207 207
         locale_string = settings['ui']['default_locale'] or 'en_US'
208 208
 
209
-    return format_date(date, locale=locale_string)
209
+    # to avoid crashing if locale is not supported by babel
210
+    try:
211
+        formatted_date = format_date(date, locale=locale_string)
212
+    except:
213
+        formatted_date = format_date(date, "YYYY-MM-dd")
214
+
215
+    return formatted_date
210 216
 
211 217
 
212 218
 def dict_subset(d, properties):