Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai

Showing 1-20 of 20 messages
Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/1/11 5:46 AM
I propose deprecating the hacky and buggy PlaceholderMediaMiddleware (and plugins_media) template tag in 2.2 in favor of django-sekizai and removing it in 2.3.

In 2.2, all core plugins should be changed to use django-sekizai (using 'js' and 'css' sekizai namespaces as convention), the plugins should internally all fall back to populate the 'cmsplugins-media' sekizai namespace using the existing python APIs to add media, plugins_media should then be a de-facto alias for 'render_block "cmsplugins-media"'.

Jonas
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Martin 2/1/11 7:05 AM
Do I understand correctly that this enables us to write a CMSPlugin and tell the plugin that it should add some special CSS / JS files to the <head> of the page, if it is getting rendered on this page? At the moment I add super hacky <script> tags to the .html template of the plugin.

If so, big +1 !!

How does this play together with django-css (https://github.com/dziegler/django-css) and all the other media combiners / compressors?

Best regards,
Martin
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/1/11 7:43 AM
This would mean you can:

* Define your css/js/whatever needs in the templates, as opposed to your python code. Your frontend engineers will love it!
* Add css to the TOP of the page (eg: head)
* Add js to the BOTTOM of the page (eg: before </body>)
* Add stuff wherever you want
* Be sure that your scripts and stylesheets will only be there once! (sekizai bits are always unique!)


Jonas
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai benzkji 2/1/11 1:45 PM
+1

after having a quick look, this should work perfect with media combiners/compressors.

ben
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/1/11 1:54 PM
I will most certainly consider re-enabling 'filters/postprocessors' for sekizai-namespaces. There used to be such a feature, but it was overcomplicated and unsuable.

This might be slightly OT, but my idea is to allow something like this: "{% render_block mynamespace firstfilter secondfilter %}" where those two are filters registered somewhere (where?) and postprocess the contents. Those could be used for example to compress javascript.
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai benzkji 2/1/11 2:01 PM
so this would do the same (more or less) as
{% load compress %}
{% compress js %}
<script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">obj.value = "value";</script>
{% endcompress %}

when using this:
https://github.com/dziegler/django-css#readme

or have you something more advanced in your mind (beside the fact that your template's way shorter...)?

Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Øyvind Saltvik 2/1/11 3:07 PM
I am all for switching to sekizai, but have a few issues. Say you have
two plugins using the same js lib/css how can you avoid loading them
twice. Only a whitespace difference or having a different order of
script tags is enough for getting it included twice. So needs to
document best practices when using common libs, maybe add some
templates that can be included for jquery/jquery ui.
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/2/11 9:28 AM
sekizai is *not* a compressor.

It's "asymetrical template rendering". Meaning you can access data from the bottom of the page from a tag at the top of the page and vice versa. This is especially useful for CMS Plugins, as you can insert your CSS into the top of the page and add your javascript at the bottom of the page from your plugin's template. Also you can be sure that if you use a library in your plugin that it's only loaded once, no matter how many times you put the plugin on your page.

I do however consider adding support for 'filters', which could be used to for example compress javascript.
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/2/11 9:29 AM
Yes you're right, we need to document best practices for CMS Plugins. I hope this is a good start: http://django-sekizai.readthedocs.org/en/latest/usage.html#sekizai-data-is-unique
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai benzkji 2/2/11 10:49 AM
sure, got this one. I asked wether the filters would do more or less the same as the common compress tools that are already available - benefits/drawbacks?
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jannis Leidel 2/2/11 10:51 AM

I'd like to encourage you to try out django_compressor for filtering purposes (the 0.6a10 from Github which is slated for release soon [1]).

http://django_compressor.rtfd.org/

Jannis

1: https://github.com/jezdez/django_compressor/tree/0.6a10

Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/2/11 10:53 AM
I'm currently thinking about something along the lines of:

{% render_block "js" "mymodule.myfilterfunction" %}

So you basically give 'import paths' as additional (optional) argument(s) to render block.

I don't plan on shipping any filters actually.
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/2/11 10:54 AM
Absolutely, I don't plan on re-implementing that functionality
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Øyvind Saltvik 2/2/11 6:56 PM
Ah. :)

Got my +1

On Feb 2, 6:29 pm, Jonas Obrist <ojiido...@gmail.com> wrote:
> Yes you're right, we need to document best practices for CMS Plugins. I hope
> this is a good start:http://django-sekizai.readthedocs.org/en/latest/usage.html#sekizai-da...
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Angelo Dini 2/4/11 12:36 AM
+1 how can fronteers work without it!
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/4/11 2:53 PM

Looking at the desolate and inconsistent state the current plugins media framework is right now and how most plugins either dont use it or use it improperly, i propose a non-backwards compatible change to happen in 2.2, rather than 2.3, by dropping the existing media framework now.

My proposed sekizai implementation would require users to provide at least the "js" and "css" sekizai-namespaces. This would of course be thoroughly documented.

Thoughts?

Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai ChrisGlass 2/5/11 3:05 AM

I don't like the idea of having to define stuff in your templates for the cms to work at all, butI see how useful it is: I guess it requires at least extremely good error messages ("you don't have a css block defined, please define one as per <link to docs>"...).

Do we have a way to check templates for correctness on server startup for instance? Just throwing ideas here, even if it sounds impractical.

---
Sent from my Android mobile

Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/5/11 6:23 AM
Well you already now need to define stuff in your templates for the CMS to work properly ({% placeholder ...%}).

I so far have no way to make sure that a certain namespace is used in a template, due to the way sekizai works. The only way I see is something similar to placeholder-detecting, where we lex the template and check the nodes.

The issue is: The way we do it now (injecting from a middleware or hacking something together in a template tag) simply does not work. The cms-placeholder rendering even does it different than placeholder rendering and on top of that, most core plugins don't even use that old way anymore and just have their javascript files in their templates.

Jonas
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jannis Leidel 2/7/11 2:13 AM
Jonas Obrist schrieb:
> Looking at the desolate and inconsistent state the current plugins media
> framework is right now and how most plugins either dont use it or use it
> improperly, i propose a non-backwards compatible change to happen in 2.2,
> rather than 2.3, by dropping the existing media framework now.
>
> My proposed sekizai implementation would require users to provide at least
> the "js" and "css" sekizai-namespaces. This would of course be thoroughly
> documented.
>
> Thoughts?

+1 It's a good idea and totally reasonable to ask CMS template authors
to provide those blocks. In doubt you could only raise a UserWarning
instead of throwing an exception if the block isn't found.

Jannis
Re: Proposal: Deprecate PlaceholderMediaMiddleware/plugins_media in favor of django-sekizai Jonas Obrist 2/19/11 5:55 AM
I've got the backend part of it pretty far now and would welcome anyone to review my patch: