-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/project/observations/migrations/0002_alter_observationsubtype_pictogram_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.0.6 on 2024-07-03 15:04 | ||
|
||
import project.utils.db.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("observations", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="observationsubtype", | ||
name="pictogram", | ||
field=project.utils.db.fields.SVGFileField( | ||
upload_to="observation_types", verbose_name="Pictogram" | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="observationtype", | ||
name="pictogram", | ||
field=project.utils.db.fields.SVGFileField( | ||
upload_to="observation_types", verbose_name="Pictogram" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db import models | ||
|
||
from project.utils.db.validators import ( | ||
validate_svg_file_content, | ||
validate_svg_file_extension, | ||
) | ||
|
||
|
||
class SVGFileField(models.FileField): | ||
default_validators = [validate_svg_file_extension, validate_svg_file_content] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.core.validators import FileExtensionValidator | ||
|
||
|
||
def validate_svg_file_extension(value): | ||
return FileExtensionValidator(allowed_extensions=["svg"])(value) | ||
|
||
|
||
# write django validator that check if http://www.w3.org/2000/svg is in file content | ||
def validate_svg_file_content(value): | ||
content = str(value.read()) | ||
if "http://www.w3.org/2000/svg" not in content: | ||
raise ValidationError("File is not an SVG file") |