This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #951 from liqd/ka-2019-08-custom-image-for-wagtail
Ka 2019 08 custom image for wagtail
- Loading branch information
Showing
23 changed files
with
438 additions
and
34 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
apps/cms/contacts/migrations/0004_formpage_custom_contact_person_image.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,32 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 09:41 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def set_custom_image_id(apps, schema_editor): | ||
CustomImage = apps.get_model('a4_candy_cms_images', 'CustomImage') | ||
FormPage = apps.get_model('a4_candy_cms_contacts', 'FormPage') | ||
|
||
for page in FormPage.objects.all(): | ||
if page.contact_person_image: | ||
image = page.contact_person_image | ||
page.custom_contact_person_image_id = CustomImage.objects.get(id=image.id) | ||
page.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_images', '0002_copy_images'), | ||
('a4_candy_cms_contacts', '0003_add_contact_person_data'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='formpage', | ||
name='custom_contact_person_image', | ||
field=models.ForeignKey(blank=True, help_text='The Image will be shown besides the name of the contact person', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='a4_candy_cms_images.CustomImage', verbose_name='Image of contact person'), | ||
), | ||
migrations.RunPython(set_custom_image_id), | ||
] |
17 changes: 17 additions & 0 deletions
17
apps/cms/contacts/migrations/0005_remove_formpage_contact_person_image.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,17 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 11:19 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_contacts', '0004_formpage_custom_contact_person_image'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='formpage', | ||
name='contact_person_image', | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
apps/cms/contacts/migrations/0006_rename_customimage_to_image.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,18 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 11:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_contacts', '0005_remove_formpage_contact_person_image'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='formpage', | ||
old_name='custom_contact_person_image', | ||
new_name='contact_person_image', | ||
), | ||
] |
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 @@ | ||
default_app_config = 'apps.cms.images.apps.Config' |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class Config(AppConfig): | ||
name = 'apps.cms.images' | ||
label = 'a4_candy_cms_images' |
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,64 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 08:07 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import taggit.managers | ||
import wagtail.core.models | ||
import wagtail.images.models | ||
import wagtail.search.index | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('taggit', '0002_auto_20150616_2121'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CustomImage', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255, verbose_name='title')), | ||
('file', models.ImageField(height_field='height', upload_to=wagtail.images.models.get_upload_to, verbose_name='file', width_field='width')), | ||
('width', models.IntegerField(editable=False, verbose_name='width')), | ||
('height', models.IntegerField(editable=False, verbose_name='height')), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='created at')), | ||
('focal_point_x', models.PositiveIntegerField(blank=True, null=True)), | ||
('focal_point_y', models.PositiveIntegerField(blank=True, null=True)), | ||
('focal_point_width', models.PositiveIntegerField(blank=True, null=True)), | ||
('focal_point_height', models.PositiveIntegerField(blank=True, null=True)), | ||
('file_size', models.PositiveIntegerField(editable=False, null=True)), | ||
('file_hash', models.CharField(blank=True, editable=False, max_length=40)), | ||
('caption_en', models.CharField(blank=True, max_length=255)), | ||
('caption_de', models.CharField(blank=True, max_length=255)), | ||
('collection', models.ForeignKey(default=wagtail.core.models.get_root_collection_id, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailcore.Collection', verbose_name='collection')), | ||
('tags', taggit.managers.TaggableManager(blank=True, help_text=None, through='taggit.TaggedItem', to='taggit.Tag', verbose_name='tags')), | ||
('uploaded_by_user', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='uploaded by user')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=(wagtail.search.index.Indexed, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name='CustomRendition', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('filter_spec', models.CharField(db_index=True, max_length=255)), | ||
('file', models.ImageField(height_field='height', upload_to=wagtail.images.models.get_rendition_upload_to, width_field='width')), | ||
('width', models.IntegerField(editable=False)), | ||
('height', models.IntegerField(editable=False)), | ||
('focal_point_key', models.CharField(blank=True, default='', editable=False, max_length=16)), | ||
('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='renditions', to='a4_candy_cms_images.CustomImage')), | ||
], | ||
options={ | ||
'unique_together': {('image', 'filter_spec', 'focal_point_key')}, | ||
}, | ||
), | ||
] |
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,41 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 09:16 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def copy_images(apps, schema_editor): | ||
CustomImage = apps.get_model('a4_candy_cms_images', 'CustomImage') | ||
Image = apps.get_model('wagtailimages', 'Image') | ||
|
||
for image in Image.objects.all(): | ||
CustomImage.objects.create( | ||
id = image.id, | ||
title = image.title, | ||
file = image.file, | ||
width = image.width, | ||
height = image.height, | ||
created_at = image.created_at, | ||
focal_point_x = image.focal_point_x, | ||
focal_point_y = image.focal_point_y, | ||
uploaded_by_user = image.uploaded_by_user, | ||
file_size = image.file_size, | ||
collection_id = image.collection_id | ||
) | ||
|
||
|
||
def delete_images(apps, schema_editor): | ||
CustomImage = apps.get_model('a4_candy_cms_images', 'CustomImage') | ||
|
||
CustomImage.objects.all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_images', '0001_initial'), | ||
('wagtailimages', '0019_delete_filter') | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_images, delete_images), | ||
] |
Empty file.
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,29 @@ | ||
from django.db import models | ||
from wagtail.images.models import AbstractImage | ||
from wagtail.images.models import AbstractRendition | ||
from wagtail.images.models import Image | ||
|
||
from apps.contrib.translations import TranslatedField | ||
|
||
|
||
class CustomImage(AbstractImage): | ||
|
||
caption_en = models.CharField(max_length=255, blank=True) | ||
caption_de = models.CharField(max_length=255, blank=True) | ||
|
||
admin_form_fields = Image.admin_form_fields + ( | ||
'caption_en', 'caption_de' | ||
) | ||
|
||
caption = TranslatedField('caption_de', 'caption_en') | ||
|
||
|
||
class CustomRendition(AbstractRendition): | ||
image = models.ForeignKey(CustomImage, | ||
related_name='renditions', | ||
on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
unique_together = ( | ||
('image', 'filter_spec', 'focal_point_key'), | ||
) |
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,32 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 09:41 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def set_custom_image_id(apps, schema_editor): | ||
CustomImage = apps.get_model('a4_candy_cms_images', 'CustomImage') | ||
NewsPage = apps.get_model('a4_candy_cms_news', 'NewsPage') | ||
|
||
for page in NewsPage.objects.all(): | ||
if page.image: | ||
image = page.image | ||
page.custom_image_id = CustomImage.objects.get(id=image.id) | ||
page.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_images', '0002_copy_images'), | ||
('a4_candy_cms_news', '0003_add_translatable_image_caption'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='newspage', | ||
name='custom_image', | ||
field=models.ForeignKey(blank=True, help_text='The Image that is shown on the news item page and the news index page', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='a4_candy_cms_images.CustomImage', verbose_name='News Header Image'), | ||
), | ||
migrations.RunPython(set_custom_image_id), | ||
] |
25 changes: 25 additions & 0 deletions
25
apps/cms/news/migrations/0005_remove_newspage_image_and_caption.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,25 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 11:19 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_news', '0004_newspage_custom_image'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='newspage', | ||
name='image', | ||
), | ||
migrations.RemoveField( | ||
model_name='newspage', | ||
name='image_caption_de', | ||
), | ||
migrations.RemoveField( | ||
model_name='newspage', | ||
name='image_caption_en', | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
apps/cms/news/migrations/0006_rename_customimage_to_image.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,18 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 11:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_news', '0005_remove_newspage_image_and_caption'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='newspage', | ||
old_name='custom_image', | ||
new_name='image', | ||
), | ||
] |
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,32 @@ | ||
# Generated by Django 2.2.4 on 2019-08-22 09:41 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def set_custom_image_id(apps, schema_editor): | ||
CustomImage = apps.get_model('a4_candy_cms_images', 'CustomImage') | ||
HomePage = apps.get_model('a4_candy_cms_pages', 'HomePage') | ||
|
||
for page in HomePage.objects.all(): | ||
if page.image: | ||
image = page.image | ||
page.custom_image_id = CustomImage.objects.get(id=image.id) | ||
page.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('a4_candy_cms_images', '0002_copy_images'), | ||
('a4_candy_cms_pages', '0019_auto_20190812_1458'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='homepage', | ||
name='custom_image', | ||
field=models.ForeignKey(blank=True, help_text='The Image that is shown on top of the page', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='a4_candy_cms_images.CustomImage', verbose_name='Header Image'), | ||
), | ||
migrations.RunPython(set_custom_image_id), | ||
] |
Oops, something went wrong.