def ready(self): unregister_image_format('left') unregister_image_format('right') unregister_image_format('fullwidth') for align in ('centered', 'left', 'right', 'inline'): register_image_format(Format('{}-original'.format(align), '{}, original size'.format(align.capitalize()), 'richtext-image {}'.format(align), 'original')) for size in ('42', '50', '72', '100', '200', '500', '800'): register_image_format( Format('{}-{}'.format(align, size), '{}, {}px'.format(align.capitalize(), size), 'richtext-image {}'.format(align), 'width-{s}'.format(s=size)))
from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.wagtailcore.fields import RichTextField from organisation.models import DepartmentUser '''To add a new size format use the following format register_image_format(Format('name', 'label', 'class_names', 'filter_spec')) These are the Format arguments: name -> unique key used to identify the format label -> label used in the chooser form when inserting the image in the RichTextField class_names -> string to assign to the class attribute of the generated <img> tag. filter_spec -> string specification to create the image rendition. ''' register_image_format( Format('600x600', '600x600', 'richtext-image 600x600', 'max-600x600')) register_image_format( Format('logo_icon', 'Logo_Icon', 'richtext-image logo_icon', 'max-30x30')) register_image_format( Format('original', 'Original', 'richtext-image original', 'original')) class UserSession(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) department_user = models.ForeignKey(DepartmentUser, null=True) session = models.ForeignKey(Session) ip = models.GenericIPAddressField(null=True) @property def shared_id(self): return hashlib.sha256('{}{}{}'.format(
def test_get_image_format(self): register_image_format(self.format) result = get_image_format('test name') self.assertEqual(result, self.format)
# -*- coding: utf-8 -*- from django.utils.translation import ugettext_lazy as _ from wagtail.wagtailimages.formats import Format, register_image_format register_image_format( Format('cosinnus_format_tiny', _('Tiny (50 x *)'), 'richtext-image richtext-image-tiny', 'width-50')) register_image_format( Format('cosinnus_format_very_small', _('Very Small (100 x *)'), 'richtext-image richtext-image-very-small', 'width-100')) register_image_format( Format('cosinnus_format_smaller', _('Smaller (150 x *)'), 'richtext-image richtext-image-smaller', 'width-150')) register_image_format( Format('cosinnus_format_small', _('Small (200 x *)'), 'richtext-image richtext-image-small', 'width-200')) register_image_format( Format('cosinnus_format_mediumer', _('Medium-small (250 x *)'), 'richtext-image richtext-image-mediumer', 'width-250')) register_image_format( Format('cosinnus_format_medium', _('Medium (300 x *)'), 'richtext-image richtext-image-medium', 'width-300')) register_image_format( Format('cosinnus_format_large', _('Large (400 x *)'), 'richtext-image richtext-image-large', 'width-400')) register_image_format( Format('cosinnus_format_larger', _('Larger (500 x *)'), 'richtext-image richtext-image-larger', 'width-500')) register_image_format(
from wagtail.wagtailimages.formats import (Format, register_image_format, unregister_image_format) register_image_format( Format('small_image_left', 'Small Image Left', 'richtext-image small_image_left left', 'width-540')) unregister_image_format('left') unregister_image_format('right')
template='core/blocks/six_column_text.html')), ('call_to_action_area', blocks.StructBlock([ ('title', blocks.CharBlock(required=False)), ('button_label', blocks.CharBlock()), ('button_link', blocks.URLBlock()), ('button2_label', blocks.CharBlock(required=False)), ('button2_link', blocks.URLBlock(required=False)), ], template='core/blocks/call_to_action_area.html')), ('raw_html', blocks.StructBlock([ ('html', blocks.RawHTMLBlock()), ], template='core/blocks/raw_html.html')), ]) settings_panels = BaseFieldsMixin.settings_panels content_panels = BaseFieldsMixin.content_panels + [ StreamFieldPanel('content'), ] class Meta: verbose_name = 'Flexible content page' from wagtail.wagtailimages.formats import register_image_format, Format register_image_format( Format('real-fullwidth', 'Real full width', 'richtext-image real-full-width', 'width-1024'))
def image_to_html(self, image, alt_text, extra_attributes=''): rendition = image.get_rendition(self.filter_spec) if self.classnames: class_attr = 'class="%s" ' % escape(self.classnames) else: class_attr = '' return """<figure %s%s> <img src="%s" width="%d" height="%d" alt="%s" /> <figcaption class="a4">%s</figcaption> </figure>""" % ( extra_attributes, class_attr, escape(rendition.url), rendition.width, rendition.height, alt_text, image.caption_html() ) unregister_image_format('fullwidth') unregister_image_format('left') unregister_image_format('right') register_image_format( CaptionedImageFormat('fullwidth', 'Full width', 'bodytext-image', 'width-750') ) register_image_format( CaptionedImageFormat('left', 'Half width left aligned', 'bodytext-image small left', 'width-400') ) register_image_format( CaptionedImageFormat('right', 'Half width right aligned', 'bodytext-image small right', 'width-400') )
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format unregister_image_format('fullwidth') register_image_format(Format('fullwidth', 'Full width', 'richtext-image full-width img-responsive', 'width-850')) unregister_image_format('left') unregister_image_format('right') register_image_format(Format('center', 'Centered', 'richtext-image img-responsive center-block', 'original')) register_image_format(Format('multiple', 'Multiple Images', 'richtext-image img-responsive multi', 'original')) register_image_format(Format('admin', 'Admin Default', 'richtext-image img-responsive center-block', 'max-600x450'))
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format unregister_image_format('fullwidth') register_image_format( Format('fullwidth', 'Full width', 'richtext-image full-width center-align', 'width-800')) unregister_image_format('left') register_image_format( Format('left', 'Left-aligned', 'richtext-image left left-align', 'width-500')) unregister_image_format('right') register_image_format( Format('right', 'Right-aligned', 'richtext-image right right-align', 'width-500'))
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailimages.formats import Format, register_image_format from wagtail.wagtailimages.models import Image from wagtail.wagtailsearch import index from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel from wagtail.wagtailsnippets.models import register_snippet from .behaviours import Introducable import hashlib import logging logger = logging.getLogger(__name__) register_image_format(Format('left-100', 'Left-aligned 100px', 'richtext-image left', 'width-100')) register_image_format(Format('left-200', 'Left-aligned 200px', 'richtext-image left', 'width-200')) register_image_format(Format('left-300', 'Left-aligned 300px', 'richtext-image left', 'width-300')) register_image_format(Format('left-400', 'Left-aligned 400px', 'richtext-image left', 'width-400')) def _d(str): return str.decode(settings.AC_ENCODING) def _e(str): return str.encode(settings.AC_ENCODING)
def image_to_html(self, image, alt_text, extra_attributes=''): rendition = image.get_rendition(self.filter_spec) if self.classnames: class_attr = 'class="%s" ' % escape(self.classnames) else: class_attr = '' return """<figure %s%s> <img src="%s" width="%d" height="%d" alt="%s" /> <figcaption class="a4">%s</figcaption> </figure>""" % (extra_attributes, class_attr, escape( rendition.url), rendition.width, rendition.height, alt_text, image.caption_html()) unregister_image_format('fullwidth') unregister_image_format('left') unregister_image_format('right') register_image_format( CaptionedImageFormat('fullwidth', 'Full width', 'bodytext-image', 'width-750')) register_image_format( CaptionedImageFormat('left', 'Half width left aligned', 'bodytext-image small left', 'width-400')) register_image_format( CaptionedImageFormat('right', 'Half width right aligned', 'bodytext-image small right', 'width-400'))
try: half_rendition = image.get_rendition('max-512x410') except SourceImageIOError: # Image file is (probably) missing from /media/original_images - generate a dummy # rendition so that we just output a broken image, rather than crashing out completely # during rendering Rendition = image.renditions.model # pick up any custom Image / Rendition classes that may be in use half_rendition = Rendition(image=image, width=0, height=0) half_rendition.file.name = 'not-found' if self.classnames: class_attr = 'class="%s" ' % escape(self.classnames) else: class_attr = '' sizes = "(max-width: 480px) 512w, 100vw" srcset = "%s 512w, %s" % (escape(half_rendition.url), escape(rendition.url)) return ('<img %s%s ' 'width="%d" height="%d" ' 'alt="%s" srcset="%s" sizes="%s">') % ( extra_attributes, class_attr, rendition.width, rendition.height, alt_text, srcset, sizes ) register_image_format(Format('halfwidth', 'Half Width (512px)', 'richtext-image half-width', 'max-512x410')) unregister_image_format("fullwidth") register_image_format(FullWidthImgFormat('fullwidth', 'Full width', 'richtext-image full-width', 'max-1400x1120'))
# image_formats.py from wagtail.wagtailimages.formats import Format, unregister_image_format, register_image_format unregister_image_format('fullwidth') register_image_format(Format('fullwidth', 'Fullwidth', 'richtext-image fullwidth', 'max-1200x1200'))
__author__ = 'pierre' from wagtail.wagtailimages.formats import Format, register_image_format register_image_format(Format('thumbnail', 'Thumbnail', 'richtext-image thumbnail', 'max-120x120')) register_image_format(Format('400pxawww', '400px width', 'richtext-image 400pxawww', 'width-400')) register_image_format(Format('original', 'Original', 'richtext-image original', 'original'))
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailimages.formats import Format, register_image_format from wagtail.wagtailimages.models import Image from wagtail.wagtailsearch import index from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel from wagtail.wagtailsnippets.models import register_snippet from .behaviours import Introducable import hashlib import logging logger = logging.getLogger(__name__) register_image_format(Format('left-100', 'Left-aligned 100px', 'richtext-image left', 'width-100')) register_image_format(Format('left-200', 'Left-aligned 200px', 'richtext-image left', 'width-200')) register_image_format(Format('left-300', 'Left-aligned 300px', 'richtext-image left', 'width-300')) register_image_format(Format('left-400', 'Left-aligned 400px', 'richtext-image left', 'width-400')) def _d(str): return str.decode(settings.AC_ENCODING) def _e(str): return str.encode(settings.AC_ENCODING) def safe_slugify (text, model):
from wagtail.wagtailsearch import index from organisation.models import DepartmentUser '''To add a new size format use the following format register_image_format(Format('name', 'label', 'class_names', 'filter_spec')) These are the Format arguments: name -> unique key used to identify the format label -> label used in the chooser form when inserting the image in the RichTextField class_names -> string to assign to the class attribute of the generated <img> tag. filter_spec -> string specification to create the image rendition. ''' register_image_format(Format('600x600', '600x600', 'richtext-image 600x600', 'max-600x600')) register_image_format(Format('logo_icon', 'Logo_Icon', 'richtext-image logo_icon', 'max-30x30')) register_image_format(Format('original', 'Original', 'richtext-image original', 'original')) class UserSession(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) department_user = models.ForeignKey(DepartmentUser, null=True) session = models.ForeignKey(Session) ip = models.GenericIPAddressField(null=True) @property def shared_id(self): return hashlib.sha256('{}{}{}'.format( timezone.now().month, self.user.email, settings.SECRET_KEY).lower().encode('utf-8')).hexdigest()
('col3_content', blocks.RichTextBlock()), ('col4_content', blocks.RichTextBlock()), ('col5_content', blocks.RichTextBlock()), ('col6_content', blocks.RichTextBlock()), ], template='core/blocks/six_column_text.html')), ('call_to_action_area', blocks.StructBlock([ ('title', blocks.CharBlock(required=False)), ('button_label', blocks.CharBlock()), ('button_link', blocks.URLBlock()), ('button2_label', blocks.CharBlock(required=False)), ('button2_link', blocks.URLBlock(required=False)), ], template='core/blocks/call_to_action_area.html')), ('raw_html', blocks.StructBlock([ ('html', blocks.RawHTMLBlock()), ], template='core/blocks/raw_html.html')), ]) settings_panels = BaseFieldsMixin.settings_panels content_panels = BaseFieldsMixin.content_panels + [ StreamFieldPanel('content'), ] class Meta: verbose_name = 'Flexible content page' from wagtail.wagtailimages.formats import register_image_format, Format register_image_format(Format('real-fullwidth', 'Real full width', 'richtext-image real-full-width', 'width-1024'))
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format # Override default formats unregister_image_format('fullwidth') unregister_image_format('left') unregister_image_format('right') FORMATS = { # Overriden formats 'fullwidth': (_('Full width'), 'richtext-image full-width img-responsive', 'width-1000'), 'left': (_('Left-aligned'), 'richtext-image left img-responsive', 'width-500'), 'right': (_('Right-aligned'), 'richtext-image right img-responsive', 'width-500'), # Extras formats 'centered': (_('Centered'), 'richtext-image full-width img-responsive', 'width-600'), 'centered-portrait': (_('Centered portrait'), 'richtext-image full-width img-responsive', 'height-500'), 'thumbnail': (_('Thumbnail'), 'richtext-image thumbnail', 'max-120x120'), 'big-thumbnail': (_('Big thumbnail'), 'richtext-image thumbnail', 'max-240x240'), } for key, (label, classes, specs) in FORMATS.items(): register_image_format(Format(key, label, classes, specs))
''' Reusable image formats ''' from django.utils.translation import ugettext_lazy as _ from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format # Override default formats unregister_image_format('fullwidth') unregister_image_format('left') unregister_image_format('right') FORMATS = { # Overriden formats 'fullwidth': (_('Full width'), 'richtext-image full-width img-responsive', 'width-1000'), 'left': (_('Left-aligned'), 'richtext-image left img-responsive', 'width-500'), 'right': (_('Right-aligned'), 'richtext-image right img-responsive', 'width-500'), # Extras formats 'centered': (_('Centered'), 'richtext-image full-width img-responsive', 'width-600'), 'centered-portrait': (_('Centered portrait'), 'richtext-image full-width img-responsive', 'height-500'), 'thumbnail': (_('Thumbnail'), 'richtext-image thumbnail', 'max-120x120'), 'big-thumbnail': (_('Big thumbnail'), 'richtext-image thumbnail', 'max-240x240'), } for key, (label, classes, specs) in FORMATS.items(): register_image_format(Format(key, label, classes, specs))
# image_formats.py from wagtail.wagtailimages.formats import Format, register_image_format register_image_format(Format('standard', 'Standard', 'richtext-image standard', 'width-500'))
from wagtail.wagtailimages.formats import Format, register_image_format register_image_format(Format('pull-left', 'Pull Left Wx200', 'pull-left img-responsive img-thumbnail', 'fill-200x250-c100')) register_image_format(Format('pull-right', 'Pull Right Wx200', 'pull-right img-responsive img-thumbnail', 'fill-200x250-c100'))