added colors
This commit is contained in:
Binary file not shown.
BIN
home/__pycache__/wagtail_hooks.cpython-310.pyc
Normal file
BIN
home/__pycache__/wagtail_hooks.cpython-310.pyc
Normal file
Binary file not shown.
@@ -6,28 +6,29 @@ from wagtail.models import Page
|
||||
from wagtail.fields import RichTextField
|
||||
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
|
||||
|
||||
from saburly.custom_editor import FULL_EDITOR
|
||||
|
||||
class HomePage(Page):
|
||||
|
||||
section_one_title = RichTextField(blank=True)
|
||||
section_one_text = RichTextField(blank=True)
|
||||
section_one_img = RichTextField(blank=True)
|
||||
section_one_title = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_one_text = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_one_img = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
|
||||
section_two_title = RichTextField(blank=True)
|
||||
section_two_text = RichTextField(blank=True)
|
||||
section_two_img = RichTextField(blank=True)
|
||||
section_two_title = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_two_text = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_two_img = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
|
||||
section_three_title = RichTextField(blank=True)
|
||||
section_three_text = RichTextField(blank=True)
|
||||
section_three_img = RichTextField(blank=True)
|
||||
section_three_title = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_three_text = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_three_img = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
|
||||
section_four_title = RichTextField(blank=True)
|
||||
section_four_text = RichTextField(blank=True)
|
||||
section_four_img = RichTextField(blank=True)
|
||||
section_four_title = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_four_text = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_four_img = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
|
||||
section_five_title = RichTextField(blank=True)
|
||||
section_five_text = RichTextField(blank=True)
|
||||
section_five_img = RichTextField(blank=True)
|
||||
section_five_title = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_five_text = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
section_five_img = RichTextField(blank=True, features=FULL_EDITOR)
|
||||
|
||||
content_panels = Page.content_panels + [
|
||||
MultiFieldPanel([
|
||||
|
||||
72
home/wagtail_hooks.py
Normal file
72
home/wagtail_hooks.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from wagtail import hooks
|
||||
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
|
||||
from wagtail.admin.rich_text.converters.html_to_contentstate import BlockElementHandler, InlineStyleElementHandler
|
||||
|
||||
@hooks.register('register_rich_text_features')
|
||||
def register_alignment_feature(features):
|
||||
alignment_features = ['left', 'center', 'right']
|
||||
labels = {
|
||||
'left': 'L',
|
||||
'center': 'C',
|
||||
'right': 'R'
|
||||
}
|
||||
|
||||
for feature in alignment_features:
|
||||
control = {
|
||||
'label': labels[feature],
|
||||
'type': feature,
|
||||
'description': f'Align {feature}',
|
||||
}
|
||||
features.register_editor_plugin(
|
||||
'draftail', feature, draftail_features.BlockFeature(control)
|
||||
)
|
||||
features.register_converter_rule(
|
||||
'contentstate', feature, {
|
||||
'from_database_format': {
|
||||
f'div[style="text-align: {feature}"]': BlockElementHandler(feature)
|
||||
},
|
||||
'to_database_format': {
|
||||
'block_map': {
|
||||
feature: {
|
||||
'element': 'div',
|
||||
'props': {'style': f'text-align: {feature}'}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@hooks.register('register_rich_text_features')
|
||||
def register_color_feature(features):
|
||||
colors = [
|
||||
('black', '#000000', 'CB'),
|
||||
('saburly-blue', '#5763AB', 'CS')
|
||||
]
|
||||
|
||||
for feature_name, color_code, label in colors:
|
||||
control = {
|
||||
'type': feature_name,
|
||||
'label': label,
|
||||
'description': f'Text color: {feature_name}',
|
||||
'style': {'color': color_code},
|
||||
}
|
||||
|
||||
features.register_editor_plugin(
|
||||
'draftail',
|
||||
feature_name,
|
||||
draftail_features.InlineStyleFeature(control),
|
||||
)
|
||||
|
||||
features.register_converter_rule('contentstate', feature_name, {
|
||||
'from_database_format': {
|
||||
f'span[style="color: {color_code}"]': InlineStyleElementHandler(feature_name),
|
||||
},
|
||||
'to_database_format': {
|
||||
'style_map': {
|
||||
feature_name: {
|
||||
'element': 'span',
|
||||
'props': {'style': f'color: {color_code}'}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user