Has anyone figured this out? I'm trying to override the default TinyMCE
media browser directory on a per-model basis, and am unable to get
mezzanine to respect formfield_overrides.
I've tried:
class CustomBlogContentWidget(TinyMceWidget):
def __init__(self, *args, **kwargs):
super(CustomBlogContentWidget, self).__init__(*args, **kwargs)
self.attrs["class"] = "mceEditor"
self.attrs["data-filebrowser-dir"] = "blog"
class CustomBlogPostAdmin(BlogPostAdmin):
fieldsets = blogpost_fieldsets
list_display = blogpost_list_display
list_filter = blogpost_list_filter
formfield_overrides = {
mezzanine.core.fields.RichTextField: {'widget':
CustomBlogContentWidget},
}
But the data attribute doesn't appear in the widget. I'd suspect that the
formfield_overrides key is incorrect, but that's what I get if I print the
class name in formfield_for_dbfield.
I can provide a new tinymce_setup.js to receive this data attribute and
send the correct dir path to tinyMCE.activeEditor.windowManager, but
because the directory needs to change for different models, I'd rather
define it in python and send it over to javascript via the data attribute.
There may also be a way to do a lookup based on the window.location.href,
but that feels super-hackish.
On Friday, June 6, 2014 2:31:53 PM UTC-7, John Briere wrote:
>
> I'm curious about the same thing. How to set the TinyMCE options either on
> a per-field basis, or if necessary, by creating a custom field type. But
> I'm guessing that even if I did that, it would be difficult to mix the
> TinyMCE options for different fields on the same page... - John
>
>
> On Fri, Jun 6, 2014 at 9:56 AM, Gary Ian Robertson <[email protected]
> <javascript:>> wrote:
>
>> This post shows a way of doing the above, but does end with a question.
>>
>> I customised the TinyMCE HTML editor in the admins of the mezzanine pages
>> and blog posts. I did this by making a copy of the tinymce_setup.js into my
>> project, customising the copy, then pointing at it using the mezzanine
>> setting TINYMCE_SETUP_JS. This worked fine.
>>
>> I added a new app to my project. It has a model which is unrelated to any
>> of the mezzanine page types. I wanted a text field in this model to have
>> tinyMCE attached to it. I was happy that timyMCE should behave exactly the
>> same as the pages and blog post content fields.
>>
>> *How not to do it*
>>
>> Neither of these worked:
>>
>> 1. Setting the CSS class name of the text field to "mceEditor", in my
>> app's admin.py.
>> 2. In the custom tinyMCE initialisation code, changing mode to
>> "exact" and adding an elements argument containing the CSS ID of my text
>> field.
>>
>> The problem seemed to be that the custom init code simply did not run for
>> my app/model.
>>
>> *A way of doing it*
>>
>> In my app's admin.py
>>
>> from django.contrib import admin
>>> from django.db import models
>>> from mezzanine.core.forms import TinyMceWidget
>>> from .models import MyModel
>>> class MyModelAdmin(admin.ModelAdmin):
>>> formfield_overrides = { models.TextField: {'widget' :
>>> TinyMceWidget}, }
>>> admin.site.register(MyModel, StaffMemberAdmin)
>>
>>
>> No changes to the custom TinyMCE init code were needed.
>>
>> *The Question*
>>
>> I now have another app and model with a text field to which I need to
>> attach TinyMCE. However, this time I need to really restrict what TinyMCE
>> is allowed to do (so the client cannot mess the site up, sigh) so this
>> instance will need to run a different initialisation function i.e. it is
>> now app-specific rather than project-wide.
>>
>> Can anybody suggest a way of doing this which won't cause deployment or
>> maintenance problems?
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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.