Gibt es eine Standardlösung zum Einfügen einer feincms MediaFile in ein RichTextContent-Formularelement (ckeditor oder tinyMCE)? Ich konnte keine in der Dokumentation finden ... Jetzt müssen die Benutzer kopieren eine URL in die medialib einfügen, dann auf die Seite verschieben und einfügen ...Feincms MediaFile in RichTextContent
Antwort
Sie werden Ihre eigene Implementierung für diese haben zu erstellen. Das Überschreiben von "ablehnen" RelatedLookupPopup ist ein bisschen hackisch, aber Django scheint keine Unterstützung für eine bessere Lösung zu haben.
UPDATE: Diese ticket beschreibt das Popup-Problem.
Erstellen Sie in Ihrem statischen Ordner, in dem 'ckeditor' lebt, ein Plugin, z.
/app/
/static/
/app/
/js/
/ckeditor/
/plugins/
/feincms/
/images/
mediaFile.png
plugin.js
plugin.js
/**
* Basic sample plugin inserting a feincms mediaFile into the CKEditor editing area.
*/
// Register the plugin with the editor.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.plugins.html
CKEDITOR.plugins.add('feincms',
{
// The plugin initialization logic goes inside this method.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.pluginDefinition.html#init
init: function(editor)
{
// Define an editor command that inserts a feincms.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#addCommand
editor.addCommand('insertMediaFile',
{
// Define a function that will be fired when the command is executed.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.commandDefinition.html#exec
exec : function(editor)
{
// Define your callback function
function insertMediaFile(imageUrl) {
// Insert the imageUrl into the document. Style represents some standard props.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
editor.insertHtml('<img src="/media/' + imageUrl + '" style="float:left;margin-right:10px;margin-bottom:10px;width:200px;" />');
}
var imageUrl;
window.dismissRelatedLookupPopup = function (win, chosenId) {
imageUrl = $(win.document.body).find('#_refkey_' + chosenId).val();
insertMediaFile(imageUrl);
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
if (elem) {
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + chosenId;
} else {
document.getElementById(name).value = chosenId;
}
}
win.close();
};
var win = window.open('/admin/medialibrary/mediafile/?pop=1', 'id_image', 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
}
});
// Create a toolbar button that executes the plugin command.
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.html#addButton
editor.ui.addButton('feincms',
{
// Toolbar button tooltip.
label: 'Insert MediaFile',
// Reference to the plugin command name.
command: 'insertMediaFile',
// Button's icon file path.
icon: this.path + 'images/mediaFile.png'
});
}
});
Stellen Sie sicher, das Plugin auf den ckeditor Init-Skript hinzufügen, zum Beispiel
{ name: 'insert', items : [ 'feincms','HorizontalRule','SpecialChar' ] },
Nicht, dass ich weiß. Wenn Sie immer (oder manchmal) benötigen einen Mediafile mit einem RichTextContent verbunden sind, geben Sie Ihren eigenen Content-Type:
from feincms.module.medialibrary.fields import MediaFileForeignKey
from feincms.content.richtext.models import RichTextContent
class RichTextAndMFContent(RichTextContent):
mf = MediaFileForeignKey(MediaFile)
class Meta:
abstract = True
def render(self, **kwargs):
...
Danke, aber das ist nicht wirklich eine Antwort auf die Frage – user2298943
Das ist über was ich kam ... – user2298943