diff --git a/apps/school/templates/school/livelesson_detail_unauth.html b/apps/school/templates/school/livelesson_detail_unauth.html
index 4493928f..8ca10e74 100644
--- a/apps/school/templates/school/livelesson_detail_unauth.html
+++ b/apps/school/templates/school/livelesson_detail_unauth.html
@@ -9,10 +9,10 @@
{% if livelesson.cover and livelesson.cover.image %}http://{{request.META.HTTP_HOST}}{{ livelesson.cover.image.url }}{% else %}{{ block.super }}{% endif %}
{% endblock ogimage %}
{% block ogimage-width %}
- {% if livelesson.cover and livelesson.cover.image %}{{ livelesson.cover.image.width }}{% else %}{{ block.super }}{% endif %}
+ {% if livelesson.cover and livelesson.cover.image %}{{ livelesson.cover.image.width|default:'1024' }}{% else %}{{ block.super }}{% endif %}
{% endblock ogimage-width %}
{% block ogimage-height %}
- {% if livelesson.cover and livelesson.cover.image %}{{ livelesson.cover.image.height }}{% else %}{{ block.super }}{% endif %}
+ {% if livelesson.cover and livelesson.cover.image %}{{ livelesson.cover.image.height|default:'512' }}{% else %}{{ block.super }}{% endif %}
{% endblock ogimage-height %}
{% block content %}
diff --git a/apps/user/models.py b/apps/user/models.py
index 7a774998..2b07118c 100644
--- a/apps/user/models.py
+++ b/apps/user/models.py
@@ -19,6 +19,7 @@ from django.urls import reverse
from api.v1 import serializers
from apps.notification.utils import send_email
from apps.user.tasks import user_to_mixpanel
+from project.utils.db import SafeImageField
class UserManager(BaseUserManager):
@@ -79,7 +80,10 @@ class User(AbstractUser):
is_email_proved = models.BooleanField(
'Верифицирован по email', default=False
)
- photo = models.ImageField('Фото', null=True, blank=True, upload_to='users')
+ if settings.DEV_SERVER:
+ photo = SafeImageField('Фото', null=True, blank=True, upload_to='users')
+ else:
+ photo = models.ImageField('Фото', null=True, blank=True, upload_to='users')
show_in_mainpage = models.BooleanField('Показывать на главной странице', default=False)
trial_lesson = models.URLField(default='', null=True, blank=True)
slug = models.SlugField(
diff --git a/docker/.env.review b/docker/.env.review
index dc0ff7ab..54d6c94e 100644
--- a/docker/.env.review
+++ b/docker/.env.review
@@ -1,4 +1,5 @@
DEBUG=True
+DEV_SERVER=True
ALLOWED_HOSTS=*
PORT=8000
CORS_ORIGIN_WHITELIST=lilcity.9ev.ru:8080
diff --git a/project/settings.py b/project/settings.py
index 211a732b..9572ee2b 100644
--- a/project/settings.py
+++ b/project/settings.py
@@ -30,6 +30,7 @@ SECRET_KEY = os.getenv(
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False)
+DEV_SERVER = os.getenv('DEV_SERVER', False)
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '*').split(',')
MAIN_HOST = os.getenv('MAIN_HOST', 'lil.school')
@@ -253,8 +254,6 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
RESOURCES_ROOT = os.path.join(BASE_DIR, 'resources')
-IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = 'imagekit.cachefiles.strategies.Optimistic'
-
LOGIN_URL = '/'
# Email
# https://github.com/anymail/django-anymail
@@ -374,14 +373,6 @@ else:
# Mixpanel settings
MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd')
-# CORS settings
-
-if DEBUG:
- CORS_ORIGIN_ALLOW_ALL = True
-else:
- CORS_ORIGIN_WHITELIST = os.getenv(
- 'CORS_ORIGIN_WHITELIST', 'lilcity.9ev.ru:8080').split(',')
-
# Swagger doc settings
SWAGGER_SETTINGS = {
@@ -412,3 +403,14 @@ try:
from .local_settings import *
except ImportError:
pass
+
+# CORS settings
+
+if DEBUG:
+ CORS_ORIGIN_ALLOW_ALL = True
+else:
+ CORS_ORIGIN_WHITELIST = os.getenv(
+ 'CORS_ORIGIN_WHITELIST', 'lilcity.9ev.ru:8080').split(',')
+
+if DEV_SERVER:
+ IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = 'imagekit.cachefiles.strategies.Optimistic'
diff --git a/project/utils/db.py b/project/utils/db.py
index 4a31f79a..eb772fb8 100644
--- a/project/utils/db.py
+++ b/project/utils/db.py
@@ -1,5 +1,28 @@
from django.db.models.base import ModelBase
from django.db import connection
+from django.db import models
+from django.db.models.fields.files import ImageFieldFile
+
+
+class SafeImageFieldFile(ImageFieldFile):
+
+ @property
+ def width(self):
+ try:
+ return self.width
+ except:
+ return None
+
+ @property
+ def height(self):
+ try:
+ return self.height
+ except:
+ return None
+
+
+class SafeImageField(models.ImageField):
+ attr_class = SafeImageFieldFile
class ModelFieldsNames(object):