Add external image list loading to tinyMCE
This commit is contained in:
		@@ -1,3 +1,4 @@
 | 
			
		||||
 | 
			
		||||
tinyMCE.init({
 | 
			
		||||
    // General options
 | 
			
		||||
    mode : "textareas",
 | 
			
		||||
@@ -17,8 +18,10 @@ tinyMCE.init({
 | 
			
		||||
    theme_advanced_toolbar_align : "left",
 | 
			
		||||
    theme_advanced_statusbar_location : "bottom",
 | 
			
		||||
    theme_advanced_resizing : true,
 | 
			
		||||
    width: "100%",
 | 
			
		||||
    height: "400"
 | 
			
		||||
    width: "60%",
 | 
			
		||||
    height: "400",
 | 
			
		||||
 | 
			
		||||
    external_image_list_url : external_list,
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,9 @@
 | 
			
		||||
 | 
			
		||||
{% block head %}
 | 
			
		||||
<script type="text/javascript" src="/static/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
  var external_list = "/tinyMCEExternalList/post/add/{{ blog_id }}";
 | 
			
		||||
</script>
 | 
			
		||||
<script type="text/javascript" src="/static/js/dynastie.js"></script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,9 @@
 | 
			
		||||
 | 
			
		||||
{% block head %}
 | 
			
		||||
<script type="text/javascript" src="/static/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
  var external_list = "/tinyMCEExternalList/post/edit/{{ post_id }}";
 | 
			
		||||
</script>
 | 
			
		||||
<script type="text/javascript" src="/static/js/dynastie.js"></script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								urls.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								urls.py
									
									
									
									
									
								
							@@ -26,6 +26,8 @@ urlpatterns = patterns('',
 | 
			
		||||
    url(r'^post/delete/(\d+)$','dynastie.views.delete_post', name='delete_post'),
 | 
			
		||||
    url(r'^generate/(\d+)$',      'dynastie.views.generate',     name='generate'),
 | 
			
		||||
    url(r'^preview/(\d+)$',       'dynastie.views.preview',      name='preview'),
 | 
			
		||||
    url(r'^tinyMCEExternalList/post/add/(\d+)$', 'dynastie.views.tinymcelist_add',  name='tinymce'),
 | 
			
		||||
    url(r'^tinyMCEExternalList/post/edit/(\d+)$', 'dynastie.views.tinymcelist_edit',  name='tinymce'),
 | 
			
		||||
    # url(r'^dynastie/', include('dynastie.foo.urls')),
 | 
			
		||||
 | 
			
		||||
    # Uncomment the admin/doc line below to enable admin documentation:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										62
									
								
								views.py
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								views.py
									
									
									
									
									
								
							@@ -2,7 +2,7 @@ import os
 | 
			
		||||
from datetime import datetime, date, time
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.contrib.auth import authenticate, login, logout
 | 
			
		||||
from django.http import HttpResponseRedirect, Http404
 | 
			
		||||
from django.http import HttpResponseRedirect, HttpResponse, Http404
 | 
			
		||||
from django.contrib.auth.decorators import login_required
 | 
			
		||||
from django.forms.models import inlineformset_factory
 | 
			
		||||
from dynastie.models import *
 | 
			
		||||
@@ -406,3 +406,63 @@ def preview(request, blog_id):
 | 
			
		||||
 | 
			
		||||
    return HttpResponseRedirect('http://' + b.name + '/preview.html')
 | 
			
		||||
    # return HttpResponseRedirect('http://' + 'localhost:8080' + '/preview.html')
 | 
			
		||||
 | 
			
		||||
def _tinymcelist(request, b, year, month):
 | 
			
		||||
    ret = 'var tinyMCEImageList = new Array('
 | 
			
		||||
 | 
			
		||||
    b.create_paths()
 | 
			
		||||
     
 | 
			
		||||
    if month < 10:
 | 
			
		||||
        suffix = '/images/' + str(year) + '/0' + str(month)
 | 
			
		||||
    else:
 | 
			
		||||
        suffix = '/images/' + str(year) + '/' + str(month)
 | 
			
		||||
 | 
			
		||||
    path = b.src_path + '/' + suffix
 | 
			
		||||
    # url = 'http://' + 'localhost:8080' + '/' + suffix + '/'
 | 
			
		||||
    url = 'http://' + b.name + '/' + suffix + '/'
 | 
			
		||||
 | 
			
		||||
    if os.path.exists(path):
 | 
			
		||||
        files = ''
 | 
			
		||||
        for p in os.listdir(path):
 | 
			
		||||
            files += '["' + p + '", "' + url + p + '"],'
 | 
			
		||||
        # Remove last comma
 | 
			
		||||
        if len(files) != 0:
 | 
			
		||||
            ret += files[:-1]
 | 
			
		||||
 | 
			
		||||
    ret += ');'
 | 
			
		||||
 | 
			
		||||
    return ret
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def tinymcelist_add(request, blog_id):
 | 
			
		||||
    from datetime import datetime
 | 
			
		||||
 | 
			
		||||
    now = datetime.now()
 | 
			
		||||
    year = now.year
 | 
			
		||||
    month = now.month
 | 
			
		||||
    b = Blog.objects.filter(pk=blog_id).filter(writers=request.user.id)[0]
 | 
			
		||||
    if b is None:
 | 
			
		||||
        return HttpResponse('', content_type='application/x-javascript')
 | 
			
		||||
 | 
			
		||||
    ret = _tinymcelist(request, b, year, month)
 | 
			
		||||
 | 
			
		||||
    print 'Ret1 ' + ret
 | 
			
		||||
 | 
			
		||||
    return HttpResponse(ret, content_type='application/x-javascript')
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def tinymcelist_edit(request, post_id):
 | 
			
		||||
    post = Post.objects.filter(pk=post_id)
 | 
			
		||||
    if post is None:
 | 
			
		||||
        return HttpResponse('', content_type='application/x-javascript')
 | 
			
		||||
    b = Blog.objects.filter(pk=post.blog).filter(writers=request.user.id)[0]
 | 
			
		||||
    if b is None:
 | 
			
		||||
        return HttpResponse('', content_type='application/x-javascript')
 | 
			
		||||
    year = post.creation_date.year()
 | 
			
		||||
    month = post.creation_date.month()
 | 
			
		||||
 | 
			
		||||
    ret = _tinymcelist(request, b, year, month)
 | 
			
		||||
 | 
			
		||||
    print 'Ret2 ' + ret
 | 
			
		||||
 | 
			
		||||
    return HttpResponse(ret, content_type='application/x-javascript')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user