Created
March 4, 2011 11:42
-
-
Save runekaagaard/854500 to your computer and use it in GitHub Desktop.
Fixes some bugs in the django-locking module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: locking/admin.py | |
=================================================================== | |
--- locking/admin.py (revision 6319) | |
+++ locking/admin.py (working copy) | |
@@ -1,42 +1,26 @@ | |
# encoding: utf-8 | |
+import os | |
from datetime import datetime | |
- | |
from django.contrib import admin | |
from django.conf import settings | |
from django.core.urlresolvers import reverse | |
from django.utils.translation import ugettext as _ | |
from django import forms | |
- | |
from locking import LOCK_TIMEOUT, views | |
class LockableAdmin(admin.ModelAdmin): | |
- @property | |
- def media(self): | |
- # because reverse() doesn't yet work when this module is first loaded | |
- # (the urlconf still has to load at that point) the media definition | |
- # has to be dynamic, and we can't simply add a Media class to the | |
- # ModelAdmin as you usually would. | |
- # | |
- # Doing so would result in an ImproperlyConfigured exception, stating | |
- # "The included urlconf doesn't have any patterns in it." | |
- # | |
- # See http://docs.djangoproject.com/en/dev/topics/forms/media/#media-as-a-dynamic-property | |
- # for more information about dynamic media definitions. | |
+ class Media(): | |
css = { | |
'all': ('locking/css/locking.css',) | |
} | |
js = ( | |
- #'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', | |
'locking/js/jquery.url.packed.js', | |
- #reverse('django.views.i18n.javascript_catalog'), | |
- reverse('locking_variables'), | |
+ os.path.join('/', settings.LOCKING_URL, 'variables.js'), | |
'locking/js/admin.locking.js', | |
) | |
- return forms.Media(css=css, js=js) | |
- | |
def changelist_view(self, request, extra_context=None): | |
# we need the request objects in a few places where it's usually not present, | |
# so we're tacking it on to the LockableAdmin class | |
Index: locking/media/locking/js/admin.locking.js | |
=================================================================== | |
--- locking/media/locking/js/admin.locking.js (revision 6319) | |
+++ locking/media/locking/js/admin.locking.js (working copy) | |
@@ -4,45 +4,44 @@ | |
more wide-spread, we could make a lot of this javascript superfluous | |
*/ | |
-var app = $.url.segment(1) | |
-var model = $.url.segment(2) | |
-var id = $.url.segment(3) | |
-var base_url = locking.base_url + "/" + [app, model, id].join("/") | |
+var app = $.url.segment(1); | |
+var model = $.url.segment(2); | |
+var id = $.url.segment(3); | |
+var base_url = locking.base_url + "/" + [app, model, id].join("/"); | |
function warning () { | |
- var minutes = locking.timeout/60; | |
- alert(interpolate(gettext("Your lock on this content will expire in a bit less than five minutes. Please save your content and navigate back to this edit page to close the content again for another %s minutes."), minutes)) | |
+ var minutes = [locking.timeout/60]; | |
+ alert(interpolate(gettext("Your lock on this content will expire in a bit less than five minutes. Please save your content and navigate back to this edit page to close the content again for another %s minutes."), minutes)); | |
} | |
function locking_mechanism () { | |
// locking is pointless when the user is adding a new piece of content | |
- if (id == 'add') return | |
+ if (id == 'add') return; | |
// we disable all input fields pre-emptively, and subsequently check if the content | |
// is or is not available for editing | |
$(":input").attr("disabled", "disabled") | |
$.getJSON(base_url + "/is_locked/", function(lock, status) { | |
if (lock.applies && status != '404') { | |
- var notice = interpolate(gettext('<p class="is_locked">This content is currently being edited by <em>%(for_user)s</em>. You can read it but not edit it.</p>'), lock, true) | |
- $("#content-main").prepend(notice) | |
+ var notice = interpolate(gettext('<p class="is_locked">This content is currently being edited by <em>%(for_user)s</em>. You can read it but not edit it.</p>'), lock, true); | |
+ $("#content-main").prepend(notice); | |
} else { | |
- $(":input").removeAttr("disabled") | |
- $.get(base_url + "/lock/") | |
+ // We give users a warning that their lock is about to expire, | |
+ // five minutes before it actually does. | |
+ setTimeout('warning()', 1000 * (locking.timeout - 300)); | |
+ $(":input").removeAttr("disabled"); | |
+ $.get(base_url + "/lock/"); | |
$(window).unload(function(){ | |
// We have to assure that our unlock request actually gets | |
// through before the user leaves the page, so it shouldn't | |
// run asynchronously. | |
$.ajax({'url': base_url + "/unlock/", 'async': false}) | |
- }) | |
+ }); | |
} | |
}) | |
- | |
- // We give users a warning that their lock is about to expire, | |
- // five minutes before it actually does. | |
- setTimeout(1000*(locking.timeout-300), warning) | |
} | |
$(document).ready(function(){ | |
if ($("body").hasClass("change-form")) { | |
- locking_mechanism() | |
+ locking_mechanism(); | |
} | |
}) | |
\ No newline at end of file | |
Index: locking/views.py | |
=================================================================== | |
--- locking/views.py (revision 6319) | |
+++ locking/views.py (working copy) | |
@@ -49,7 +49,7 @@ | |
@log | |
@user_may_change_model | |
@is_lockable | |
-def is_locked(request, app, model, id): | |
+def is_locked(request, app, model, id): | |
obj = utils.gather_lockable_models()[app][model].objects.get(pk=id) | |
response = simplejson.dumps({ | |
@@ -65,4 +65,4 @@ | |
'base_url': "/".join(request.path.split('/')[:-1]), | |
'timeout': LOCK_TIMEOUT, | |
}) | |
- return HttpResponse(response) | |
\ No newline at end of file | |
+ return HttpResponse(response, mimetype='application/javascript') | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment