-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a VALIDATORS_TO class variable to ImageCollection
- Loading branch information
Showing
7 changed files
with
149 additions
and
33 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
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
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,27 @@ | ||
from typing import Any, Dict | ||
|
||
from ... import validators | ||
|
||
|
||
def validators_to_options(field_validators) -> Dict[str, Any]: | ||
""" | ||
Превращает Django-валидаторы в словарь конфигурации, | ||
который может использоваться для вывода или проверки | ||
на стороне клиента. | ||
""" | ||
config = {} | ||
for v in field_validators: | ||
if isinstance(v, validators.MimeTypeValidator): | ||
config["acceptFiles"] = v.allowed | ||
elif isinstance(v, validators.ExtensionValidator): | ||
config["allowedExtensions"] = v.allowed | ||
elif isinstance(v, validators.MaxSizeValidator): | ||
config["sizeLimit"] = v.limit_value | ||
elif isinstance(v, validators.ImageMinSizeValidator): | ||
config["minImageWidth"] = v.width_limit | ||
config["minImageHeight"] = v.height_limit | ||
elif isinstance(v, validators.ImageMaxSizeValidator): | ||
config["maxImageWidth"] = v.width_limit | ||
config["maxImageHeight"] = v.height_limit | ||
|
||
return config |
42 changes: 42 additions & 0 deletions
42
...ples/collections/validators/migrations/0003_gallery_alter_page_collection_page_gallery.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,42 @@ | ||
# Generated by Django 4.2.8 on 2023-12-21 13:19 | ||
|
||
from django.db import migrations | ||
import django.db.models.deletion | ||
import django.db.models.manager | ||
import paper_uploads.models.fields.collection | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('paper_uploads', '0013_configurableimageitem'), | ||
('validators_collections', '0002_alter_page_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Gallery', | ||
fields=[ | ||
], | ||
options={ | ||
'proxy': True, | ||
'default_permissions': (), | ||
'indexes': [], | ||
'constraints': [], | ||
}, | ||
bases=('paper_uploads.imagecollection',), | ||
managers=[ | ||
('default_mgr', django.db.models.manager.Manager()), | ||
], | ||
), | ||
migrations.AlterField( | ||
model_name='page', | ||
name='collection', | ||
field=paper_uploads.models.fields.collection.CollectionField(on_delete=django.db.models.deletion.SET_NULL, storage=None, to='validators_collections.mixedcollection', upload_to='', verbose_name='mixed collection'), | ||
), | ||
migrations.AddField( | ||
model_name='page', | ||
name='gallery', | ||
field=paper_uploads.models.fields.collection.CollectionField(on_delete=django.db.models.deletion.SET_NULL, storage=None, to='validators_collections.gallery', upload_to='', verbose_name='gallery'), | ||
), | ||
] |
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