img valid
This commit is contained in:
parent
27c3a44e78
commit
fe5167f8f4
|
@ -80,62 +80,6 @@
|
||||||
"detail": "django.db",
|
"detail": "django.db",
|
||||||
"documentation": {}
|
"documentation": {}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "migrations",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "migrations",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "models",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "migrations",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "models",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "migrations",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "models",
|
|
||||||
"importPath": "django.db",
|
|
||||||
"description": "django.db",
|
|
||||||
"isExtraImport": true,
|
|
||||||
"detail": "django.db",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "models",
|
"label": "models",
|
||||||
"importPath": "django.db",
|
"importPath": "django.db",
|
||||||
|
@ -562,6 +506,22 @@
|
||||||
"detail": "object.models",
|
"detail": "object.models",
|
||||||
"documentation": {}
|
"documentation": {}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Image",
|
||||||
|
"importPath": "PIL",
|
||||||
|
"description": "PIL",
|
||||||
|
"isExtraImport": true,
|
||||||
|
"detail": "PIL",
|
||||||
|
"documentation": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "ValidationError",
|
||||||
|
"importPath": "django.core.exceptions",
|
||||||
|
"description": "django.core.exceptions",
|
||||||
|
"isExtraImport": true,
|
||||||
|
"detail": "django.core.exceptions",
|
||||||
|
"documentation": {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "django_filters",
|
"label": "django_filters",
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
|
@ -1066,42 +1026,6 @@
|
||||||
"detail": "back.object.migrations.0001_initial",
|
"detail": "back.object.migrations.0001_initial",
|
||||||
"documentation": {}
|
"documentation": {}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "Migration",
|
|
||||||
"kind": 6,
|
|
||||||
"importPath": "back.object.migrations.0002_remove_clickablearea_tergetname",
|
|
||||||
"description": "back.object.migrations.0002_remove_clickablearea_tergetname",
|
|
||||||
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('object', '0001_initial'),\n ]\n operations = [\n migrations.RemoveField(\n model_name='clickablearea',\n name='tergetName',\n ),\n ]",
|
|
||||||
"detail": "back.object.migrations.0002_remove_clickablearea_tergetname",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Migration",
|
|
||||||
"kind": 6,
|
|
||||||
"importPath": "back.object.migrations.0003_clickablearea_target_name",
|
|
||||||
"description": "back.object.migrations.0003_clickablearea_target_name",
|
|
||||||
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('object', '0002_remove_clickablearea_tergetname'),\n ]\n operations = [\n migrations.AddField(\n model_name='clickablearea',\n name='target_name',\n field=models.CharField(default='name', max_length=200),\n preserve_default=False,",
|
|
||||||
"detail": "back.object.migrations.0003_clickablearea_target_name",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Migration",
|
|
||||||
"kind": 6,
|
|
||||||
"importPath": "back.object.migrations.0004_alter_clickablearea_target_name",
|
|
||||||
"description": "back.object.migrations.0004_alter_clickablearea_target_name",
|
|
||||||
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('object', '0003_clickablearea_target_name'),\n ]\n operations = [\n migrations.AlterField(\n model_name='clickablearea',\n name='target_name',\n field=models.CharField(blank=True, max_length=200, null=True),\n ),",
|
|
||||||
"detail": "back.object.migrations.0004_alter_clickablearea_target_name",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Migration",
|
|
||||||
"kind": 6,
|
|
||||||
"importPath": "back.object.migrations.0005_scene3d_hdr_gainmap_scene3d_hdr_json_and_more",
|
|
||||||
"description": "back.object.migrations.0005_scene3d_hdr_gainmap_scene3d_hdr_json_and_more",
|
|
||||||
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('object', '0004_alter_clickablearea_target_name'),\n ]\n operations = [\n migrations.AddField(\n model_name='scene3d',\n name='hdr_gainmap',\n field=models.FileField(blank=True, null=True, upload_to=''),\n ),",
|
|
||||||
"detail": "back.object.migrations.0005_scene3d_hdr_gainmap_scene3d_hdr_json_and_more",
|
|
||||||
"documentation": {}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Scene3DAdmin",
|
"label": "Scene3DAdmin",
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
|
@ -1156,6 +1080,15 @@
|
||||||
"detail": "back.object.models",
|
"detail": "back.object.models",
|
||||||
"documentation": {}
|
"documentation": {}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "maximum_size_validator",
|
||||||
|
"kind": 2,
|
||||||
|
"importPath": "back.object.models",
|
||||||
|
"description": "back.object.models",
|
||||||
|
"peekOfCode": "def maximum_size_validator(image):\n max_width = 512\n max_height = 512\n img = Image.open(image)\n fw, fh = img.size\n if fw > max_width or fh > max_height:\n raise ValidationError(\"Height or Width is larger than what is allowed\")\nclass ClickableArea(models.Model):\n name = models.CharField(\"название\", max_length=255)\n description = models.TextField(\"описание\")",
|
||||||
|
"detail": "back.object.models",
|
||||||
|
"documentation": {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "logger",
|
"label": "logger",
|
||||||
"kind": 5,
|
"kind": 5,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
from PIL import Image
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger("root")
|
logger = logging.getLogger("root")
|
||||||
|
@ -21,6 +23,7 @@ class Element3D(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Scene3D(models.Model):
|
class Scene3D(models.Model):
|
||||||
filter_horizontal = ("elements",)
|
filter_horizontal = ("elements",)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
|
@ -47,6 +50,14 @@ class Scene3D(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
def maximum_size_validator(image):
|
||||||
|
max_width = 512
|
||||||
|
max_height = 512
|
||||||
|
img = Image.open(image)
|
||||||
|
fw, fh = img.size
|
||||||
|
if fw > max_width or fh > max_height:
|
||||||
|
raise ValidationError("Height or Width is larger than what is allowed")
|
||||||
|
|
||||||
|
|
||||||
class ClickableArea(models.Model):
|
class ClickableArea(models.Model):
|
||||||
name = models.CharField("название", max_length=255)
|
name = models.CharField("название", max_length=255)
|
||||||
|
@ -68,15 +79,15 @@ class ClickableArea(models.Model):
|
||||||
Element3D,
|
Element3D,
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
image = models.ImageField('Картинка', upload_to='images', blank=True, null=True)
|
image = models.ImageField(
|
||||||
|
"Картинка",
|
||||||
# def image_size_validator_factory(min_w=600, min_h=600, field_name='image'):
|
upload_to=group_based_upload_to,
|
||||||
# def validator(image):
|
validators=[
|
||||||
# if image.width < min_w or image.height < min_h:
|
maximum_size_validator,
|
||||||
# raise ValidationError(
|
],
|
||||||
# {field_name: f'Размер картинки от {min_w}х{min_h} пикселей. '}
|
blank=True,
|
||||||
# )
|
null=True,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
Loading…
Reference in New Issue