On Apr 21, 2008, at 10:44 PM, blis102 wrote:

> p.s. FCKeditor's connector feature, which allows you to browse your
> server to insert images, files, and flash, is highly useful, although
> I have not gotten to get it to work with django yet. There is a google
> code project called fckconnector (http://code.google.com/p/django-
> fckconnector/) that claims to get the connector working for Django but
> I have yet to use it. Anyone using it successfully?

TinyMCE can also be configured to browse your Django site for images  
or files. There's http://code.google.com/p/django-filebrowser/, which  
apparently lets you browse, upload and even edit the images on your  
server, and can integrate with TinyMCE. If you want to do this outside  
of the admin interface, or want more control over which resources are  
made available, it's easy enough to do yourself.

Start with a generic view like this (included at 'blog/admin' in the  
URL conf; assumes your images are in their own model, related to  
others):

url(r'^images/$', 'object_list',  {'queryset': Image.objects.all(),  
'template_name': 'blog/admin/image_list.html', 'template_object_name':  
'image'}, name='blog-entry-images'),

... and the image_list template, thus:

{% load thumbnail %}
<html>
<head>
<title>Blog Images</title>
<script language="javascript" type="text/javascript" src="/static/ 
admin/tiny_mce/tiny_mce_popup.js"></script>
<script type="text/javascript" charset="utf-8">
   function returnImageURL(url) {
     var win = tinyMCEPopup.getWindowArg("window");
      
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value  
= url;
     tinyMCEPopup.close();
   }
</script>
</head>
<body>
   <p>Click on an image to select it and close this window.</p>
   {% if image_list %}
   <table>
     {% for image in image_list %}
       <tr>
         <td style="text-align: center;">
           <img src="{{image.get_image_url|thumbnail:"height=30"}}"
             alt="{{image.title}}"
             onclick="returnImageURL('{{image.get_image_url}}');"/>
         </td>
         <td>{{image.title}}</td>
         <td>{{image.timestamp}}</td>
       </tr>
     {% endfor %}
   </table>
   {% else %}
   <p>No files found.</p>
   <button onclick="tinyMCEPopup.close();">Close</button>
   {% endif %}
</html>

... and this extra bit when configuring TinyMCE:

file_browser_callback: "blogBrowser"

... and finally, the callback function:

function blogBrowser (field_name, url, type, win) {
   var popup = {
     file : "/blog/admin/" + type + "s/",
     title : type[0].toUpperCase() + type.substring(1) + " Browser",
     resizable : "yes",
     inline : "yes",
     width: 600,
     height: 400,
     close_previous : "no"
   }

   tinyMCE.activeEditor.windowManager.open(popup, {window : win,  
input : field_name});
   return false;
}

The 'file' parameter to the popup points to the URL from your URL  
conf. (The view and template for type 'file' will look almost  
identical to those for images.)

For stricter access control, or to limit which images are shown, you'd  
just have to replace the generic view.

Not that I have any strong preference for TinyMCE over FCKeditor,  
other than that I never wanted to have to explain the latter's  
name. ;^) TinyMCE does seem to coexist well with template tags in text  
fields that eventually get rendered.

John


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to