Настроить на DEV нормальную работу курсов

remotes/origin/ga-ecommerce-gleb
gzbender 6 years ago
parent 694a3d6d82
commit c87a7a1689
  1. 13
      apps/content/models.py
  2. 4
      apps/course/templates/course/_items.html
  3. 12
      apps/course/templates/course/course.html
  4. 4
      apps/school/templates/school/livelesson_detail_unauth.html
  5. 6
      apps/user/models.py
  6. 1
      docker/.env.review
  7. 22
      project/settings.py
  8. 23
      project/utils/db.py

@ -9,15 +9,19 @@ from django.utils import timezone
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from imagekit.models import ImageSpecField from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToCover from imagekit.processors import ResizeToCover
from polymorphic.models import PolymorphicModel from polymorphic.models import PolymorphicModel
from project.utils.db import SafeImageField
User = get_user_model() User = get_user_model()
class ImageObject(models.Model): class ImageObject(models.Model):
image = models.ImageField('Изображение', upload_to='content/imageobject') if settings.DEV_SERVER:
image = SafeImageField('Изображение', upload_to='content/imageobject')
else:
image = models.ImageField('Изображение', upload_to='content/imageobject')
image_thumbnail = ImageSpecField(source='image', image_thumbnail = ImageSpecField(source='image',
processors=[ResizeToCover(300, 200, False)], processors=[ResizeToCover(300, 200, False)],
format='JPEG', format='JPEG',
@ -158,7 +162,6 @@ class Banner(models.Model):
text = models.TextField(blank=True, default='') text = models.TextField(blank=True, default='')
button_text = models.CharField(max_length=50, blank=True, default='') button_text = models.CharField(max_length=50, blank=True, default='')
url = models.URLField(blank=True, default='') url = models.URLField(blank=True, default='')
image = models.ImageField()
use = models.BooleanField(default=False) use = models.BooleanField(default=False)
color = models.CharField(max_length=7, blank=True, default='') color = models.CharField(max_length=7, blank=True, default='')
color2 = models.CharField(max_length=7, blank=True, default='') color2 = models.CharField(max_length=7, blank=True, default='')
@ -168,6 +171,10 @@ class Banner(models.Model):
update_at = models.DateTimeField(auto_now=True) update_at = models.DateTimeField(auto_now=True)
pages = ArrayField(models.IntegerField(choices=PAGE_CHOICES), default=[], blank=True) pages = ArrayField(models.IntegerField(choices=PAGE_CHOICES), default=[], blank=True)
main_banner = ArrayField(models.IntegerField(choices=PAGE_CHOICES), default=[], blank=True) main_banner = ArrayField(models.IntegerField(choices=PAGE_CHOICES), default=[], blank=True)
if settings.DEV_SERVER:
image = SafeImageField()
else:
image = models.ImageField()
class Meta: class Meta:
verbose_name = 'Банер' verbose_name = 'Банер'

@ -9,9 +9,9 @@
> >
<a class="courses__preview" href="{% if course.status <= 1 %}{% url 'course_edit' course.id %}{% else %}{{ course.url }}{% endif %}"> <a class="courses__preview" href="{% if course.status <= 1 %}{% url 'course_edit' course.id %}{% else %}{{ course.url }}{% endif %}">
{% if course.cover and course.cover.image_thumbnail %} {% if course.cover and course.cover.image_thumbnail %}
<img class="courses__pic" src="{{ course.cover.image_thumbnail.url }}" width="300px" /> <img class="courses__pic" src="{{ course.cover.image_thumbnail.url }}" />
{% else %} {% else %}
<img class="courses__pic" src="{% static 'img/no_cover.png' %}" width="300px" /> <img class="courses__pic" src="{% static 'img/no_cover.png' %}" />
{% endif %} {% endif %}
{% if course.is_featured %} {% if course.is_featured %}
<div class="courses__label courses__label_fav"></div> <div class="courses__label courses__label_fav"></div>

@ -10,13 +10,13 @@
{% block ogurl %}{{ request.build_absolute_uri }}{% endblock ogurl %} {% block ogurl %}{{ request.build_absolute_uri }}{% endblock ogurl %}
{% block ogimage %} {% block ogimage %}
http://{{request.META.HTTP_HOST}}{% if course.cover and course.cover.image %}{{ course.cover.image.url }}{% else %}{% static 'img/og_courses.jpg' %}{% endif %} http://{{request.META.HTTP_HOST}}{% if course.cover %}{{ course.cover.image.url }}{% else %}{% static 'img/og_courses.jpg' %}{% endif %}
{% endblock ogimage %} {% endblock ogimage %}
{% block ogimage-width %} {% block ogimage-width %}
{% if course.cover and course.cover.image %}{{ course.cover.image.width }}{% else %}1024{% endif %} {% if course.cover %}{{ course.cover.image.width|default:'1024' }}{% else %}1024{% endif %}
{% endblock ogimage-width %} {% endblock ogimage-width %}
{% block ogimage-height %} {% block ogimage-height %}
{% if course.cover and course.cover.image %}{{ course.cover.image.height }}{% else %}512{% endif %} {% if course.cover %}{{ course.cover.image.height|default:'512' }}{% else %}512{% endif %}
{% endblock ogimage-height %} {% endblock ogimage-height %}
@ -212,10 +212,8 @@
{% endif %} {% endif %}
</div> </div>
<a class="course__video video" href="#"> <a class="course__video video" href="#">
{% if course.cover and course.cover.image %} {% if course.cover %}
<img class="video__pic" src="{{ course.cover.image.url }}"/> <img class="video__pic" src="{{ course.cover.image.url }}"/>
{% else %}
{% endif %} {% endif %}
{% if course.is_deferred_start %} {% if course.is_deferred_start %}
<div class="video__soon"> <div class="video__soon">
@ -272,7 +270,7 @@
{% endif %} {% endif %}
<div <div
class="course course_promo" class="course course_promo"
style="background-image: url({% if course.cover and course.cover.image %}{{ course.cover.image.url }}{% else %}{% static 'img/no_cover.png' %}{% endif %});" style="background-image: url({% if course.cover %}{{ course.cover.image.url }}{% else %}{% static 'img/no_cover.png' %}{% endif %});"
> >
<div class="course__center center center_sm"> <div class="course__center center center_sm">
<div class="course__head"> <div class="course__head">

@ -9,10 +9,10 @@
{% if livelesson.cover and livelesson.cover.image %}http://{{request.META.HTTP_HOST}}{{ livelesson.cover.image.url }}{% else %}{{ block.super }}{% endif %} {% if livelesson.cover and livelesson.cover.image %}http://{{request.META.HTTP_HOST}}{{ livelesson.cover.image.url }}{% else %}{{ block.super }}{% endif %}
{% endblock ogimage %} {% endblock ogimage %}
{% block ogimage-width %} {% 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 %} {% endblock ogimage-width %}
{% block ogimage-height %} {% 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 %} {% endblock ogimage-height %}
{% block content %} {% block content %}

@ -19,6 +19,7 @@ from django.urls import reverse
from api.v1 import serializers from api.v1 import serializers
from apps.notification.utils import send_email from apps.notification.utils import send_email
from apps.user.tasks import user_to_mixpanel from apps.user.tasks import user_to_mixpanel
from project.utils.db import SafeImageField
class UserManager(BaseUserManager): class UserManager(BaseUserManager):
@ -79,7 +80,10 @@ class User(AbstractUser):
is_email_proved = models.BooleanField( is_email_proved = models.BooleanField(
'Верифицирован по email', default=False 'Верифицирован по 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) show_in_mainpage = models.BooleanField('Показывать на главной странице', default=False)
trial_lesson = models.URLField(default='', null=True, blank=True) trial_lesson = models.URLField(default='', null=True, blank=True)
slug = models.SlugField( slug = models.SlugField(

@ -1,4 +1,5 @@
DEBUG=True DEBUG=True
DEV_SERVER=True
ALLOWED_HOSTS=* ALLOWED_HOSTS=*
PORT=8000 PORT=8000
CORS_ORIGIN_WHITELIST=lilcity.9ev.ru:8080 CORS_ORIGIN_WHITELIST=lilcity.9ev.ru:8080

@ -30,6 +30,7 @@ SECRET_KEY = os.getenv(
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False) DEBUG = os.getenv('DEBUG', False)
DEV_SERVER = os.getenv('DEV_SERVER', False)
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '*').split(',') ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '*').split(',')
MAIN_HOST = os.getenv('MAIN_HOST', 'lil.school') 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') RESOURCES_ROOT = os.path.join(BASE_DIR, 'resources')
IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = 'imagekit.cachefiles.strategies.Optimistic'
LOGIN_URL = '/' LOGIN_URL = '/'
# Email # Email
# https://github.com/anymail/django-anymail # https://github.com/anymail/django-anymail
@ -374,14 +373,6 @@ else:
# Mixpanel settings # Mixpanel settings
MIX_TOKEN = os.getenv('MIXPANEL_TOKEN', '79bd6bfd98667ed977737e6810b8abcd') 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 doc settings
SWAGGER_SETTINGS = { SWAGGER_SETTINGS = {
@ -412,3 +403,14 @@ try:
from .local_settings import * from .local_settings import *
except ImportError: except ImportError:
pass 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'

@ -1,5 +1,28 @@
from django.db.models.base import ModelBase from django.db.models.base import ModelBase
from django.db import connection 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): class ModelFieldsNames(object):

Loading…
Cancel
Save