diff --git a/lock_tokens/admin.py b/lock_tokens/admin.py index 7c6faf2..92c06dd 100644 --- a/lock_tokens/admin.py +++ b/lock_tokens/admin.py @@ -2,6 +2,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied from django.db.models import Count +from django.utils.translation import gettext as _ from lock_tokens.exceptions import AlreadyLockedError from lock_tokens.sessions import ( @@ -13,8 +14,14 @@ class LockableModelAdmin(admin.ModelAdmin): + def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): + # use custom template in change view, but use default in add view, as lock is not used there + self.change_form_template = 'admin/lock_tokens_change_form.html' + if add: + self.change_form_template = None - change_form_template = 'admin/lock_tokens_change_form.html' + return super(LockableModelAdmin, self).render_change_form(request, context, add, change, + form_url, obj) def change_view(self, request, object_id, form_url="", extra_context=None): extra_context = extra_context or {} @@ -32,22 +39,25 @@ def change_view(self, request, object_id, form_url="", extra_context=None): lock_for_session(obj, request.session, force_new=force_new_session_lock) extra_context["lock_token"] = request.session[get_session_key(obj)] except AlreadyLockedError: - messages.add_message(request, messages.ERROR, "You cannot edit this " - "object, it has been locked. Come back later.") + messages.add_message( + request, + messages.ERROR, + _("You cannot edit this object, it has been locked. Come back later.") + ) return super(LockableModelAdmin, self).change_view(request, object_id, form_url, extra_context) def save_model(self, request, obj, form, change): if change: if not check_for_session(obj, request.session): - raise PermissionDenied("Invalid lock, cannot save.") + raise PermissionDenied(_("Invalid lock, cannot save.")) try: # Renew lock to make sure it is still valid when saving lock_for_session(obj, request.session) except AlreadyLockedError: # Race condition: lock expired just after the check_for_session call and # someone else locked the object before the lock_for_session call - raise PermissionDenied("Lock has expired, cannot save.") + raise PermissionDenied(_("Lock has expired, cannot save.")) super(LockableModelAdmin, self).save_model(request, obj, form, change) if change: unlock_for_session(obj, request.session) diff --git a/lock_tokens/locale/de/LC_MESSAGES/django.mo b/lock_tokens/locale/de/LC_MESSAGES/django.mo new file mode 100755 index 0000000..692db1b Binary files /dev/null and b/lock_tokens/locale/de/LC_MESSAGES/django.mo differ diff --git a/lock_tokens/locale/de/LC_MESSAGES/django.po b/lock_tokens/locale/de/LC_MESSAGES/django.po new file mode 100755 index 0000000..852b7e5 --- /dev/null +++ b/lock_tokens/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,22 @@ +msgid "" +msgstr "" +"Project-Id-Version: lock_tokens\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-03-08 08:38-0600\n" +"PO-Revision-Date: 2021-03-08 09:06+0100\n" +"Last-Translator: Liip\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language-Team: \n" +"X-Generator: Poedit 2.3\n" + +msgid "You cannot edit this object, it has been locked. Come back later." +msgstr "Sie können dieses Objekt nicht bearbeiten, es wurde gesperrt. Versuchen Sie es später erneut." + +msgid "Invalid lock, cannot save." +msgstr "Ungültige Sperre, kann nicht gespeichert werden." + +msgid "Lock has expired, cannot save." +msgstr "Die Sperre ist abgelaufen, kann nicht gespeichert werden." diff --git a/lock_tokens/templates/api/load_client.html b/lock_tokens/templates/api/load_client.html index 7f8886b..edc086a 100644 --- a/lock_tokens/templates/api/load_client.html +++ b/lock_tokens/templates/api/load_client.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} {% if csrf %}{% csrf_token %}{% endif %}