wagtail | A Django content management system focused on flexibility and user experience | Content Management System library
kandi X-RAY | wagtail Summary
kandi X-RAY | wagtail Summary
A Django content management system focused on flexibility and user experience
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Register core features .
- Register core logging actions .
- Copy a single page .
- Parse fields parameter .
- Returns the root page of the given page .
- Render external link chooser form .
- Create an alias .
- Publish a page revision
- Update aliases .
- Send notification notifications to all threads .
wagtail Key Features
wagtail Examples and Code Snippets
class CategoryPage(Page):
description_meta = models.CharField(max_length=500, null=True, blank=True)
template = models.CharField(max_length=500, null=True, blank=True, default='_nixaTemplate/category/default.html')
image = mode
class HomePage(Page):
# ...
def get_template(self, request, *args, **kwargs):
if request.user.is_authenticated:
return "home/home_page.html"
else:
return "home/not_authenticated.html"
code_text = models.TextField(blank=True)
{{ header.code_text|safe }}
class MyPage(Page):
body = StreamField([('Snippet', SnippetChooserBlock(
target_model='web.Advert', template='blocks/advert.html')])
{{ value.text }}
<
{% for item in menu_items %}
... {{ item.link_page.title}} ...
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import PropertyPage
@receiver(post_save)
def set_number_and_slug_after_property_page_created(sender, instance, created, **kwargs):
if i
/**
* Remove all of the COLOR_ styles from the current selection.
* This is to ensure only one COLOR_ style is applied per range of text.
* Replicated from https://github.com/thibaudcolas/draftjs-filters/blob/f997416a0c076eb6e850f13addc
from unidecode import unidecode
from django.template import defaultfilters
class HomePage(Page):
date_published = models.DateField(blank=True, null=True)
content = .....
def clean(self):
super().clean()
date
def some_date_method(self):
return datetime.datetime.now()
def save(self, *args, **kwargs):
self.slug = f"{slugify(self.title)}-{self.some_date_method()}"
super().save(*args, **kwargs)
def __init__(self, folder=None, **kwargs):
super().__init__(**kwargs)
template_block = blocks.ChoiceBlock(choices=get_designs(folder), label=_('Select a template'), required=False)
template_block.set_name('template')
self.c
Community Discussions
Trending Discussions on wagtail
QUESTION
I am working on wagtail upgrade on a site from version 1.13.4 . Was mostly following this post https://wagtail.org/blog/upgrading-wagtail/ . However, since the first update to wagtail 2.0 snippet titles are wrong. I could sort it out on the templated front end pages, but they still appear wrong on the admin panel.
How titles are displayed on the admin panel And this same issue is with fields that link to those snippets
I got as far as updating wagtail to 2.4, since the blog post said that it should support python 3.7, but issue still persists. As far as I can tell, there are no error messages on the terminal output, migrations run without any issues. Any clue where I should start looking?
This should be the relevant artist snippet declaration from the project
...ANSWER
Answered 2022-Apr-11 at 11:13When upgrading from Python 2 to 3, you should replace the __unicode__
method with __str__
: https://docs.djangoproject.com/en/1.10/topics/python3/#str-and-unicode-methods
QUESTION
I tried to dockerize my Wagtail Web Application and this error Occurred.
I tried docker-compose build
there was no errors.
after that i tried docker-compose up
then this error occurred
I really need help on this error.
Error-
ANSWER
Answered 2022-Apr-10 at 15:46You didn't mention wagtail versions or if this is an upgrade. But that error sounds like this: https://docs.wagtail.org/en/stable/releases/2.11.3.html#run-before-declaration-needed-in-initial-homepage-migration
QUESTION
I have a Snippet model(SampleSnippet) with fields field_a, field_b, and field_c. And I am using it in a StructBlock like:
...ANSWER
Answered 2022-Mar-04 at 10:42This is going to be quite difficult, since in current Wagtail versions (>=2.13) the StreamField editing UI is populated client-side in Javascript - as such, there are some extra steps to make the necessary data available to the client-side code, and the standard Django form / template mechanisms won't be available.
A simple workaround, if the fields aren't too long, would be to define the snippet's __str__
method to include the desired data - this will then display any time the snippet is shown in the admin.
For a full solution, I'd suggest this approach:
Set up a custom
elements to contain your additional data.form_template
for your StructBlock as detailed in Custom editing interfaces for StructBlock, with placeholderOverride the StructBlock's
get_form_state
so that the returned dict (which will be used to populate the form template on the client side) includes your additional fields - something like:
QUESTION
I have previously been using path("", include(wagtail_urls))
for my home_page url which displays the template at home/home_page.html correctly
I wish to however display different pages depending on whether a user is logged in or not so have changed this to:
...ANSWER
Answered 2022-Mar-03 at 09:36The include(wagtail_urls)
pulls in Wagtail's page handling logic for selecting which page should be returned for a given URL. If you swap that line out with your own code, you're effectively swapping out all of Wagtail...
First, consider whether you're reinventing the page privacy feature that Wagtail already provides. If you want the site as a whole to require a login, and non-logged-in users to be given a blanket generic login form, you can enable this using the Privacy control under the Settings tab (or in the top right corner on older Wagtail releases) when editing the homepage, and set WAGTAIL_FRONTEND_LOGIN_TEMPLATE = "home/not_authenticated.html"
in your project settings file.
If you just want to swap the template for the homepage specifically, you can do that by defining a get_template
method on your HomePage model:
QUESTION
My current Wagtail project has a very simple structure with some generic pages that have just a body RichTextField
. These are just basic CMS type pages where an editor will edit some content in the rich text editor and publish.
One of the pages (and probably more in time) is a "Help Wanted" page and uses an external javascript snippet from a third-party service that lists current job openings with links to the applications that are hosted by them.
Since adding a
ANSWER
Answered 2022-Feb-28 at 22:44This is a result of the Django template language's auto-escaping behaviour, and can be overridden by adding a |safe
filter:
QUESTION
I'm trying to direct wagtail
to use a template in a centralised location at the top of the project tree. So for example:
ANSWER
Answered 2022-Jan-29 at 18:23Below is how I organize templates and static assets. I have a themes
folder that is located in the main project folder with named theme subfolders within the themes
folder. I then have the following in settings/base.py
:
QUESTION
I have a case that uses Page ID as a slug, after creating a new Page, Wagtail provides us a "View live" button but when we click on that button, it provides a wrong URL
The right URL should be ".../property-list/"
I have searched on stack overflow, found this thread but the answer is still a mystery: Wrong 'View live' url in Wagtail admin message after page creation when using id as slug
I have followed the Wagtail official document, using Wagtail Hooks to manipulate data. However, no success yet. This is my code:
...ANSWER
Answered 2022-Jan-26 at 14:39The after_create_page
hook doesn't work for this, as it's one of the last things to run during the Wagtail admin's page creation view, and the confirmation message (including the old URL) has already been constructed by that point. This can be remedied by using the post_save
signal provided by Django instead - being a more low-level mechanism, it's more closely tied to the act of saving the database record, without Wagtail's admin logic getting in the way.
(It's also a bit more future-proof: Wagtail's after_create_page
hook is designed to only be called when a user goes through the page creation area of the Wagtail admin, so that it can be used to customise that user's path through the admin if appropriate. If there's ever any other route by which a page might be created - like, say, a data import, or using translation tools for a multi-language site - then after_create_page
will be bypassed, but the post_save
signal will still be triggered.)
Assuming your project has a properties
app where you're defining a PropertyPage model, your code can be rewritten to use post_save
as follows - in properties/signals.py
:
QUESTION
I'm attempting to run some unit tests on a StructBlock, which is composed of normal block fields and a StreamBlock.
The problem I'm running into is that I can construct a test that renders the block, but I cannot test the StreamBlock validation (i.e., I can't test the block's clean()
)
Stack
- Python 3.9.6
- Django 3.2
- Wagtail 2.13
- pytest 6.2
- pytest-django 4.4
Block Definitions
MyStructBlock
...ANSWER
Answered 2021-Dec-29 at 15:02Every block type has a corresponding 'native' data type for the data it expects to work with - for the simpler blocks, this data type is what you'd expect (e.g. a string for CharBlock, an Image instance for ImageChooserBlock) but for a few of the more complex ones, there's a custom type defined:
- for RichTextBlock, the native type is
wagtail.core.rich_text.RichText
(which behaves similarly to a string, but also has asource
property where e.g. page IDs in page links are kept intact) - for StreamBlock, the native type is
wagtail.core.blocks.StreamValue
(a sequence type, where each item is a StreamValue withblock_type
andvalue
properties).
The render
method will generally be quite forgiving if you use the wrong types (such as a string for RichTextBlock or a list of dicts for StreamBlock), since it's really just invoking your own template code. The clean
method will be more picky, since it's running Python logic specific to each block.
Unfortunately the correct types to use for each block aren't really formally documented, and some of them are quite fiddly to construct (e.g. a StructValue needs to be passed a reference to the corresponding StructBlock) - outside of test code, there isn't much need to create these objects from scratch, because the data will usually be coming from some outside source instead (e.g. a form submission or the database), and each block will be responsible for converting that to its native type.
With that in mind, I'd recommend that you construct your data by piggybacking on the to_python
method, which converts the JSON representation as stored in the database (consisting of just simple Python data types - integers, strings, lists, dicts) into the native data types:
QUESTION
I need to add a string based unique ID to Wagtail’s image model. These IDs are a relatively short combination of letters, numbers and punctuation, e.g. "AS.M-1.001". So I am using a custom image model with Django’s standard CharField
for that with the argument unique=True
. But the editing form unfortunately does not check if the ID is unique. So I can use the same ID for multiple images. This check for uniqueness does work in any other standard form in Wagtail, e.g. the Page
model. But not for the image model.
ANSWER
Answered 2021-Dec-02 at 14:36Images in Wagtail don't use WagtailAdminModelForm
or the base_form_class
attribute - these are used by pages, snippets and ModelAdmin to support Wagtail-specific features like inline children and panels, but images work through plain Django models and forms.
You can customise the form by subclassing BaseImageForm and setting WAGTAILIMAGES_IMAGE_FORM_BASE in your project settings. As long as you define your form class somewhere outside of models.py (e.g. in a separate forms.py module), you'll avoid the circular dependency that leads to the "Models aren't loaded yet" error.
QUESTION
ANSWER
Answered 2021-Nov-03 at 17:36The errors in the browser console show that the Javascript files included in the wagtail.contrib.table_block
app are not loading. Most likely, these are missing from your S3 file hosting (S3 returns 403 Forbidden for missing files).
After adding wagtail.contrib.table_block
to INSTALLED_APPS and deploying to your server, you'll need to re-run ./manage.py collectstatic
to ensure these JS files are uploaded to S3.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wagtail
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page