-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extensible blocks #305
Comments
I agree - we tried to make these blocks more dynamic at first, but it creates a lot of problems with migrations, because any change to a streamfield must trigger a django migration. I would be interested to see what your solution looks like. Can't guarantee it will be merged but I would definitely give it a thorough review. Up until now we have not come up with a good way to easily add more blocks other than overriding the |
@mwort I'd like to see that PR :-) |
@vsalvino I completely understand the concern, however it is better to give that flexibility to a developer (perhaps with a warning) and leave the choice up to them if they know what they are doing. I imagine a good approach would be to have |
Or something like this?
|
Yes - what you have is exactly right, however the problem is that it breaks Django migrations (it will created endless migrations) due to how the wagtail streamfield blocks are actually part of the database migrations - so they cannot be dynamic. This is the number 1 issue we have struggled with in trying to build coderedcms to be dynamic in any fashion. So further research into the Wagtail streamfield, and Django migrations is required. |
So I am hitting this issue very hard three-fold:
So far the cleanest solution I see is keeping the abstract models in This would keep the blocks definitions inside of the |
Regarding your list:
|
|
For custom blocks, you'd have to define the entire streamfield as so (see 'my_custom_block'). And then set that as the from coderedcms.blocks import *
from 3rd_party.blocks import MyBlock
# Re-implement a mega-streamblock from codered defaults
MY_STREAMBLOCKS = [
('hero', HeroBlock([
('row', GridBlock(CONTENT_STREAMBLOCKS + [('my_custom_block', MyBlock())])),
('cardgrid', CardGridBlock([
('card', CardBlock()),
])),
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))),
])),
('row', GridBlock(CONTENT_STREAMBLOCKS)),
('cardgrid', CardGridBlock([
('card', CardBlock()),
])),
('html', blocks.RawHTMLBlock(icon='code', classname='monospace', label=_('HTML'))),
]
class WebPage(CoderedWebPage):
body = StreamField(MY_STREAMBLOCKS, null=True, blank=True) |
This worked. Combined with |
OK, so what's the latest recommendation to add custom STREAMBLOCKS to non-pages, like snippets and content walls? I'm using https://github.com/labd/wagtailstreamforms with great results and would like to embed them into content walls too. @vsalvino Is it (wagtailstreamforms) something to replace the form pages with? |
I am trying to inherit ContentWall with ContentPopup(ContentWall) and then override content_walls on all my pages, but I got stuck with this:
Any ideas of another solution to be able to add custom streamfield blocks to content walls? 🙇♂️ |
OK, so revisiting this, will open a new issue for wagtailstreamforms, I've been banging my head against the wall for quite some time but any mechanism with EXTRA_*_STREAMFIELD_BLOCKS would lead to unmanageable migrations in each coderedcms installation and breakage on subsequent upgrade. I'm thinking the solution could be moving al the CODEREDCMS streamfield migrations to a separate app or website, haven't given it a deeper think yet, just occurred to me as I type it. I'm really struggling with it because I'd like to use wagtailstreamforms in the snippets (reusable content and content walls) and there's no good solution for it. |
If you are trying to add a form to content wall... I would recommend creating the form page separately, then use the page preview block within the content wall, pointing to your new form page. Yes, you are right about adding custom block types, it does create migration problems. The solution is that coderedcms needs to refactor its concrete models containing a streamfield to be abstract models... this is a design flaw that will unfortunately require a major update to sort out (#56) |
Hello everyone! Thanks for the great boilerplate for Wagtail, vsalvino and crew. Google sent me here when looking for how to integrate a third party block package into the StructBlock provided with coderedcms as
That's precisely what I did when working through similar issues (mainly with integrating third party blocks), I could't think of a better way. Blocks without formatting can just be included (such as alternate editors, markdown, etc) but when I wanted to embed uploaded media, as mentioned in #15, the only way I can think of to include such a block with the In any case all of this will require a migration, so breaking coderedcms out into an app seemed like the most serviceable way to do so. A lot of this seems to be inherent limitations of wagtail, I suppose. There's not a trivial way to add third party integration to the admin like base-Django. FWIW, if other people also stumble here from google and want a way to do this, here's how I did it... The coderedcms In my case, wagtailmedia like so...
The That class, in my case
There's probably a neater way to iterate over the model and generate a context list here, but this works. You need to define a method for each model field for the class you included in the StructBlock's QuerySet that you need access to. You can 'get' the field you created in your StructBlock, and then return the sub-field from the child block's model for the value. You can see what fields are going to be available in the response object from the StructBlock's QuerySet in the wagtailmedia model. The only thing missing here is a method to get at the filename's extension for the html tag defining the controls. A template tag fixes that, in
Then in a block template, you can access your values like so...
You'll have to season the HTML to taste, obviously. Whatever functions you specified in your From here, all you have to do is include the option in the coderedcms StreamField init lists. I'm a few versions back but unless that's changed, they're in the
All of this has triggered a migration for the field you created in the new StructBlock, so you will have to makemigrations/migrate and you are now maintaining a fork of coderedcms. As Ayushin mentioned above I simply broke out the installation into an app to avoid issues. It should also be noted that absent a proper |
Best solution for now would be to create an official doc on how to make your own streamfield (see my comment above). |
Is your feature request related to a problem?
The blocks provided by coderedcms are great but they are difficult to extend consistently. E.g. adding a
code block
to theCONTENT_STREAMBLOCKS
is currently only possible by overriding thebody
in all of the page models where this is required.Describe the solution you'd like
#43 hinted on a solution that has so far not been implemented (correct me if I'm wrong). It would probably require all
*_STREAMBLOCK
globals inblocks/__init__.py
to be converted to functions that will assemble the list of blocks depending on settings during the model construction. The setting could be a dictionary with entries pointing to a module with global list variables, e.g. something like this:Describe alternatives you've considered
See example with
body
above.Additional context
I can give this a go and push a PR if you think this would be the right way to do this.
The text was updated successfully, but these errors were encountered: