Is there any way to set custom label to FieldPanel in Wagtail? I want to do something like:
class BlogPage(Page):
intro = models.CharField(max_length=255)
panels = [
FieldPanel('intro', label = "My custom label")
]
The model field accepts a verbose_name property, which will be picked up for use as a form field label:
class BlogPage(Page):
intro = models.CharField(max_length=255, verbose_name="My custom label")
panels = [
FieldPanel('intro')
]
Related
my code:
from django.core.validators import RegexValidator
URL_VALIDATOR_MESSAGE = 'Not a valid URL'
URL_VALIDATOR = RegexValidator(regex='http\D+', message=URL_VALIDATOR_MESSAGE)
class SezPubBlock(blocks.StructBlock):
sez = blocks.ListBlock(
blocks.StructBlock(
[
("title", blocks.CharBlock(classname="full title", icon="title", required=True)),
("url", blocks.URLBlock(required=True, validators=[URL_VALIDATOR])),
], label="Link", icon="link"
), label="Link sezione"
)
link i need to insert: http://intranet/example/
the link is without dots and match regular expression 'http\D+'
but when i save the page get the default error "Enter a valid URL."
if i add ".com" http://intranet.com/example/, works.
i think the default validator is not overrided
i found a solution. i changed URLblock with CharBlock and it works
class SezPubBlock(blocks.StructBlock):
nome_sezione = blocks.CharBlock(required=True, verbose_name="My custom label")
sez = blocks.ListBlock(
blocks.StructBlock(
[
("title", blocks.CharBlock(classname="full title", icon="title", required=True)),
("url", blocks.CharBlock(required=True, validators=[URL_VALIDATOR], icon="link")),
], label="Link", icon="link"
), label="Link sezione"
)
How can I implement a multiple choice for fields in Wagtail? For example, I would like the user to be able to select h2, h3, or h4 for a field in the Wagtail editorial dashboard. Is this possible?
Define a field with a choices argument:
HEADING_SIZE_CHOICES = [
('h2', 'h2'),
('h3', 'h3'),
('h4', 'h4'),
]
class MyPage(Page):
heading_size = models.CharField(max_length=10, choices=HEADING_SIZE_CHOICES)
content_panels = Page.content_panels + [
FieldPanel('heading_size')
]
This will then display in the page editor as a select dropdown, and can be used like any other field:
<{{ page.heading_size }}>{{ page.title }}</{{ page.heading_size }}>
I have a StructBlock like this:
class JumbotronBlock(blocks.StructBlock):
fullwidth= blocks.BooleanBlock(requried=False, help_text="Full width of the viewport")
heading= blocks.CharBlock(required=True, help_text="Heading for the jumbotron")
lead= blocks.CharBlock(required= False, help_text= "Lead text for Jumbotron")
link= LinkBlock(required=False)
bg_image= ImageChooserBlock(required=False)
bg_color= blocks.CharBlock(required=False, help_text="Hex value for background color")
classes= blocks.CharBlock(required=False, help_text="CSS classes for jumbotron")
styles= blocks.CharBlock(required=False, help_text="Custom style definitions for jumbotron")
class Meta:
template="streams/jumbotron_block.html"
icon= "placeholder"
label= "Jumbotron"
And My HomePage Class model is this:
class HomePage(Page):
template= "home/home_page.html"
header= Jumbotron()
body = StreamField([
('Richtext', RichTextBlock()),
('CTA', CTABlock()),
('Section', SectionBlock()),
])
content_panels = Page.content_panels + [
??which panel here??('header'),
StreamFieldPanel('body'),
]
Which panel should I use to add the Jumbotron to the edit panels? Thanks.
StructBlock is not usable as a model field - it is only valid inside a StreamField. You need to define the fields of your jumbotron block as Django model fields within your HomePage model, and - if you want to group them together visually in the edit view - place them in a MultiFieldPanel.
I've got the situation where a Wagtail snippet is a model that has a FK relationship. I can't figure out how to make that available in the CMS as an inline.
Given:
#register_snippet
class TeamMember(models.Model):
name = models.CharField(max_length=80)
(other fields)
content_panels = [
FieldPanel('name'),
(etc.)
#InlinePanel('tasks', label="Team Tasks")
]
class Task(models.Model):
team_member = ForeignKey('TeamMember', related_name='tasks')
(other fields)
how do I allow Task to be an inline to TeamMember?
Or is this only possible if TeamMember is a Page?
You need to change the ForeignKey to ParentalKey. You may also need to change the TeamMember class to inherit from ClusterableModel.
#register_snippet
class TeamMember(ClusterableModel):
name = models.CharField(max_length=80)
panels = [
FieldPanel('name'),
InlinePanel('tasks', label="Team Tasks")
]
class Task(models.Model):
team_member = ParentalKey('TeamMember', related_name='tasks')
task = models.CharField(max_length=80)
panels = [
FieldPanel('task')
]
I'm looking for the support of i18n in the ExtJS,and have seen in the net about reading the resource bundles and replacing the component's labels depends upon the locale.
Though I've some doubts
How about the data which got stored in the DB as unicode and I want
populate those into ExtJs's component's
Is rendering the labels of the Extjs components into different languages only possible?
There's a extension for this called Ext.ux.Localizer
https://github.com/devotis/Ext.ux.Localizer
With this component you can translate more than just labels through localizableProps:
localizableProps : {
// Ext.button
button : ["text", "tooltip"],
// Ext.form.field
checkboxfield : ["fieldLabel", "boxLabel"],
field : ["fieldLabel"],
filefield : ["fieldLabel", "buttonText"],
radiofield : ["fieldLabel", "boxLabel"],
// Ext.form
checkboxgroup : ["fieldLabel"],
fieldcontainer : ["fieldLabel"],
fieldset : ["title"],
label : ["text"],
// Ext.grid
gridcolumn : ["text"],
panel : ["title"],
tooltip: ["html"],
image: ["src"]
}
You can even translate the data in some columns through localizableColumns:
localizableColumns: [ //add grid column renderers
"status_description", "bounced"
]
It does not translate the values of fields in forms.