Actually I've just realised that for this to work correctly, it would need to happen on the fly and not on save - if we do replacement on save and store the thumbnail path directly in the HTML before saving, further resizing of the image would be very awkward - the thumbnail itself would be resized rather than the original image.
So, let's forget performance - in production these things should be cached anyway. Perhaps we can also move the bleach/clean phase to a richtext filter as well. That would mean the original HTML source would always be stored in the DB and only cleaned on output, so the developer could modify the filtering level etc to restore any HTML that had been saved and cleaned already. On Tue, Jun 3, 2014 at 5:47 PM, Stephen McDonald <[email protected]> wrote: > Another option I'd consider - using Python's built-in HTMLParser class to > do the work. This would remove the need for any dependencies. The only > problem is that it will choke on bad HTML. In that case I think we can just > handle an exception, and not perform thumbnail generation - TinyMCE and > others should produce valid HTML. Again this would fall under the "slow" > camp that would need to occur on save. > > > On Tue, Jun 3, 2014 at 5:25 PM, Stephen McDonald <[email protected]> wrote: > >> That would be clean but I'm worried about performance. I can't see any >> other way of making this working without introducing lxml or BeautifulSoup >> - either of those will parse the HTML, replacing img src attributes with >> results from the thumbnail template tag (btw I imagined width/height would >> simply be extracted from the img tags too). >> >> As I understand lxml is much better from a performance perspective, and >> if we were using it then perhaps parsing HTML on every request would be OK. >> But it isn't a pure Python lib, and I fear introducing installation >> headaches if we include it as a dependency. Believe me, it will break for >> someone somewhere, and we have to support that. Alternatively we can >> introduce pure-Python BeautifulSoup as the dependency, but it's much slower >> and so it'd make more sense for the thumbnail replacement to occur on save >> of the model, rather than on the fly in templates. >> >> >> >> >> >> >> >> >> >> >> On Tue, Jun 3, 2014 at 3:13 PM, Ahmad Khayyat <[email protected]> wrote: >> >>> Now that `RICHTEXT_FILTERS` is plural, perhaps this is simply a matter >>> of shipping a filter in Mezzanine that calls >>> `mezzanine.core.templatetags.mezzanine_tags.thumbnail`, or at least >>> documenting this procedure. The thumbnail size (and any other parameters >>> accepted by `thumbnail`) can be set in a custom filter or as settings. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Mezzanine Users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Stephen McDonald >> http://jupo.org >> > > > > -- > Stephen McDonald > http://jupo.org > -- Stephen McDonald http://jupo.org -- You received this message because you are subscribed to the Google Groups "Mezzanine Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
