Skip to content

Commit

Permalink
Fixed a bug which breaks plugin addition on monolingual sites (django…
Browse files Browse the repository at this point in the history
…-cms#164)

More accurate error response for POSTs with invalid languages

JavaScript fallback for determining the language - the original check
fails when settings.LANGUAGES only has one language.
  • Loading branch information
acdha committed Sep 24, 2009
1 parent 279c990 commit cf78bee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cms/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponse, Http404
from django.http import HttpResponse, Http404, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.translation import ugettext_lazy as _
from django.template.context import RequestContext
Expand Down Expand Up @@ -68,7 +68,11 @@ def add_plugin(request):
position = None

if not page.has_change_permission(request):
raise Http404
return HttpResponseForbidden(_("You do not have permission to change this page"))

# Sanity check to make sure we're not getting bogus values from JavaScript:
if not language or not language in [ l[0] for l in settings.LANGUAGES ]:
return HttpResponseBadRequest(_("Language must be set to a supported language!"))

plugin = CMSPlugin(page=page, language=language, plugin_type=plugin_type, position=position, placeholder=placeholder)

Expand Down
10 changes: 10 additions & 0 deletions cms/media/cms/js/plugin_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ $(document).ready(function() {
var placeholder = $(this).parent().parent().parent().children("label").attr("for").split("id_")[1];
var splits = window.location.href.split("/");
var page_id = splits[splits.length-2];

var language = $('input.language_button.selected').attr('name');

if (!language) {
language = $('input[name=language]').attr("value");
}

if (!language) {
alert("Unable to determine the correct language for this plugin! Please report the bug!");
}

var target_div = $(this).parent().parent().parent().children('div.plugin-editor');
if (pluginvalue) {
var pluginname = select.children('[selected]').text();
Expand Down

0 comments on commit cf78bee

Please sign in to comment.