File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Paths for Utilities App."""
2
+
3
+ from django .utils .text import slugify
4
+
5
+
6
+ def image_path (instance , filename ):
7
+ """Generates storage path for associated model images."""
8
+ # appname = apps.contents.models
9
+ appname = instance .__class__ .__module__ .split ("." )[1 ]
10
+ modelname = instance .__class__ .__name__ .lower ()
11
+ extension = filename .split ("." )[- 1 ]
12
+ name_slug = slugify (instance .name )[:50 ]
13
+ filename = f"{ name_slug } .{ extension } "
14
+
15
+ return f"{ appname } /{ modelname } /{ filename } "
Original file line number Diff line number Diff line change
1
+ """"Validators for Drivers App."""
2
+
3
+ from datetime import date
4
+ from django .core .exceptions import ValidationError
5
+ from django .core .validators import RegexValidator
6
+
7
+
8
+ def validate_phone (value ):
9
+ """Validate a phone number according to the Chilean format."""
10
+ validator = RegexValidator (
11
+ regex = r'^\+56\d{9}$' ,
12
+ message = "Invalid phone number." ,
13
+ code = "invalid_name"
14
+ )
15
+ validator (value )
16
+
17
+
18
+ def validate_birth_date (value ):
19
+ """Validate that the person is at least 18 years old."""
20
+ if (date .today () - value ).days < 6570 : # 6570 days = 18 years
21
+ raise ValidationError (
22
+ "You must be at least 18 years old to register as a driver."
23
+ )
You can’t perform that action at this time.
0 commit comments