@@ -1065,20 +1065,20 @@ def __init__(self, validations, size=False, mimes=False, messages={}, raises={})
1065
1065
def message (self , attribute ):
1066
1066
messages = []
1067
1067
if not self .file_check :
1068
- messages .append ("The {} is not a valid file." .format (attribute ))
1068
+ messages .append ("The {} is not a valid file." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ))
1069
1069
1070
1070
if not self .size_check :
1071
1071
from hfilesize import FileSize
1072
1072
1073
1073
messages .append (
1074
1074
"The {} file size exceeds {:.02fH}." .format (
1075
- attribute , FileSize (self .size )
1075
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , FileSize (self .size )
1076
1076
)
1077
1077
)
1078
1078
if not self .mimes_check :
1079
1079
messages .append (
1080
1080
"The {} mime type is not valid. Allowed formats are {}." .format (
1081
- attribute , "," .join (self .allowed_extensions )
1081
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , "," .join (self .allowed_extensions )
1082
1082
)
1083
1083
)
1084
1084
@@ -1093,13 +1093,13 @@ def negated_message(self, attribute):
1093
1093
1094
1094
messages .append (
1095
1095
"The {} file size is less or equal than {:.02fH}." .format (
1096
- attribute , FileSize (self .size )
1096
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , FileSize (self .size )
1097
1097
)
1098
1098
)
1099
1099
if self .mimes_check :
1100
1100
messages .append (
1101
1101
"The {} mime type is in {}." .format (
1102
- attribute , "," .join (self .allowed_extensions )
1102
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , "," .join (self .allowed_extensions )
1103
1103
)
1104
1104
)
1105
1105
return messages
@@ -1120,14 +1120,14 @@ def __init__(self, validations, size=False, messages={}, raises={}):
1120
1120
def message (self , attribute ):
1121
1121
messages = []
1122
1122
if not self .file_check :
1123
- messages .append ("The {} is not a valid file." .format (attribute ))
1123
+ messages .append ("The {} is not a valid file." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ))
1124
1124
1125
1125
if not self .size_check :
1126
1126
from hfilesize import FileSize
1127
1127
1128
1128
messages .append (
1129
1129
"The {} file size exceeds {:.02fH}." .format (
1130
- attribute , FileSize (self .size )
1130
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , FileSize (self .size )
1131
1131
)
1132
1132
)
1133
1133
@@ -1176,7 +1176,7 @@ def __init__(self, validations, size=False, messages={}, raises={}):
1176
1176
def message (self , attribute ):
1177
1177
messages = []
1178
1178
if not self .file_check :
1179
- messages .append ("The {} is not a valid file." .format (attribute ))
1179
+ messages .append ("The {} is not a valid file." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ))
1180
1180
1181
1181
if not self .size_check :
1182
1182
from hfilesize import FileSize
@@ -1239,6 +1239,8 @@ def __init__(self, validations, locale, messages={}, raises={}):
1239
1239
self .patterns_example .append (pattern_dict ["example" ])
1240
1240
1241
1241
def passes (self , attribute , key , dictionary ):
1242
+ self .key = key
1243
+ self .dictionary = dictionary
1242
1244
for pattern in self .patterns :
1243
1245
# check that at least one pattern match attribute
1244
1246
if re .compile (r"{}" .format (pattern )).match (attribute ):
@@ -1247,7 +1249,7 @@ def passes(self, attribute, key, dictionary):
1247
1249
1248
1250
def message (self , attribute ):
1249
1251
return "The {} is not a valid {} postal code. Valid {} {}." .format (
1250
- attribute ,
1252
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ,
1251
1253
"," .join (self .locales ),
1252
1254
"examples are" if len (self .locales ) > 1 else "example is" ,
1253
1255
"," .join (self .patterns_example ),
@@ -1265,17 +1267,19 @@ def __init__(self, validations, other_field, messages={}, raises={}):
1265
1267
self .other_field = other_field
1266
1268
1267
1269
def passes (self , attribute , key , dictionary ):
1270
+ self .key = key
1271
+ self .dictionary = dictionary
1268
1272
other_value = dictionary .get (self .other_field , None )
1269
1273
return attribute != other_value
1270
1274
1271
1275
def message (self , attribute ):
1272
1276
return "The {} value must be different than {} value." .format (
1273
- attribute , self .other_field
1277
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .other_field
1274
1278
)
1275
1279
1276
1280
def negated_message (self , attribute ):
1277
1281
return "The {} value be the same as {} value." .format (
1278
- attribute , self .other_field
1282
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .other_field
1279
1283
)
1280
1284
1281
1285
@@ -1291,6 +1295,8 @@ def __init__(self, validations, version=4, messages={}, raises={}):
1291
1295
self .uuid_type = "UUID {0}" .format (self .version )
1292
1296
1293
1297
def passes (self , attribute , key , dictionary ):
1298
+ self .key = key
1299
+ self .dictionary = dictionary
1294
1300
from uuid import UUID
1295
1301
1296
1302
try :
@@ -1300,10 +1306,10 @@ def passes(self, attribute, key, dictionary):
1300
1306
return False
1301
1307
1302
1308
def message (self , attribute ):
1303
- return "The {} value must be a valid {}." .format (attribute , self .uuid_type )
1309
+ return "The {} value must be a valid {}." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .uuid_type )
1304
1310
1305
1311
def negated_message (self , attribute ):
1306
- return "The {} value must not be a valid {}." .format (attribute , self .uuid_type )
1312
+ return "The {} value must not be a valid {}." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .uuid_type )
1307
1313
1308
1314
1309
1315
class required_if (BaseValidation ):
@@ -1316,19 +1322,21 @@ def __init__(self, validations, other_field, value, messages={}, raises={}):
1316
1322
self .value = value
1317
1323
1318
1324
def passes (self , attribute , key , dictionary ):
1325
+ self .key = key
1326
+ self .dictionary = dictionary
1319
1327
if dictionary .get (self .other_field , None ) == self .value :
1320
- return required .passes (self , attribute , key , dictionary )
1328
+ return required .passes (self , attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , key , dictionary )
1321
1329
1322
1330
return True
1323
1331
1324
1332
def message (self , attribute ):
1325
1333
return "The {} is required because {}={}." .format (
1326
- attribute , self .other_field , self .value
1334
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .other_field , self .value
1327
1335
)
1328
1336
1329
1337
def negated_message (self , attribute ):
1330
1338
return "The {} is not required because {}={} or {} is not present." .format (
1331
- attribute , self .other_field , self .value , self .other_field
1339
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) , self .other_field , self .value , self .other_field
1332
1340
)
1333
1341
1334
1342
@@ -1347,6 +1355,8 @@ def __init__(self, validations, other_fields, messages={}, raises={}):
1347
1355
self .other_fields = other_fields
1348
1356
1349
1357
def passes (self , attribute , key , dictionary ):
1358
+ self .key = key
1359
+ self .dictionary = dictionary
1350
1360
for field in self .other_fields :
1351
1361
if field in dictionary :
1352
1362
return required .passes (self , attribute , key , dictionary )
@@ -1356,15 +1366,15 @@ def passes(self, attribute, key, dictionary):
1356
1366
def message (self , attribute ):
1357
1367
fields = "," .join (self .other_fields )
1358
1368
return "The {} is required because {} is present." .format (
1359
- attribute ,
1369
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ,
1360
1370
"one in {}" .format (fields )
1361
1371
if len (self .other_fields ) > 1
1362
1372
else self .other_fields [0 ],
1363
1373
)
1364
1374
1365
1375
def negated_message (self , attribute ):
1366
1376
return "The {} is not required because {} {} is not present." .format (
1367
- attribute ,
1377
+ attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) ,
1368
1378
"none of" if len (self .other_fields ) > 1 else "" ,
1369
1379
"," .join (self .other_fields ),
1370
1380
)
@@ -1375,14 +1385,16 @@ class distinct(BaseValidation):
1375
1385
duplicate values."""
1376
1386
1377
1387
def passes (self , attribute , key , dictionary ):
1388
+ self .key = key
1389
+ self .dictionary = dictionary
1378
1390
# check if list contains duplicates
1379
1391
return len (set (attribute )) == len (attribute )
1380
1392
1381
1393
def message (self , attribute ):
1382
- return "The {} field has duplicate values." .format (attribute )
1394
+ return "The {} field has duplicate values." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) )
1383
1395
1384
1396
def negated_message (self , attribute ):
1385
- return "The {} field has only different values." .format (attribute )
1397
+ return "The {} field has only different values." .format (attribute . replace ( "*" , str ( missing_key ( self . dictionary , self . key ))) )
1386
1398
1387
1399
1388
1400
class Validator :
0 commit comments