added temporary potential bug (change auto_crop_images dict names for News)

This commit is contained in:
Anatoly 2019-11-17 20:39:03 +03:00
parent c2c182e992
commit 62c4ab8d74

View File

@ -10,6 +10,7 @@ from rating.models import Rating, ViewCount
from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin,
ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin) ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin)
from utils.querysets import TranslationQuerysetMixin from utils.querysets import TranslationQuerysetMixin
from django.conf import settings
class Agenda(ProjectBaseMixin, TranslatedFieldsMixin): class Agenda(ProjectBaseMixin, TranslatedFieldsMixin):
@ -248,6 +249,48 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin):
count_value = self.views_count.count count_value = self.views_count.count
return count_value return count_value
# todo: remove in future
@property
def crop_gallery(self):
if hasattr(self, 'gallery'):
gallery = []
images = self.gallery.all()
model_name = self._meta.model_name.lower()
crop_parameters = [p for p in settings.SORL_THUMBNAIL_ALIASES
if p.startswith(model_name)]
for image in images:
d = {
'id': image.id,
'title': image.title,
'original_url': image.image.url,
'orientation_display': image.get_orientation_display(),
'auto_crop_images': {},
}
for crop in crop_parameters:
d['auto_crop_images'].update(
{crop[len(f'{model_name}_'):]: image.get_image_url(crop)})
gallery.append(d)
return gallery
@property
def crop_main_image(self):
if hasattr(self, 'main_image') and self.main_image:
image = self.main_image
model_name = self._meta.model_name.lower()
image_property = {
'id': image.id,
'title': image.title,
'original_url': image.image.url,
'orientation_display': image.get_orientation_display(),
'auto_crop_images': {},
}
crop_parameters = [p for p in settings.SORL_THUMBNAIL_ALIASES
if p.startswith(self._meta.model_name.lower())]
for crop in crop_parameters:
image_property['auto_crop_images'].update(
{crop[len(f'{model_name}_'):]: image.get_image_url(crop)})
return image_property
class NewsGallery(IntermediateGalleryModelMixin): class NewsGallery(IntermediateGalleryModelMixin):