Skip to content

Commit

Permalink
get language code from html attribute bcz of missing cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
yaghoubi committed Feb 23, 2025
1 parent 8c47e9f commit 4467907
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions django_daisy/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.core.files.storage import FileSystemStorage
from django.db import models
Expand Down Expand Up @@ -107,6 +108,7 @@ def each_context(self, request):
"change_language_url": change_language_url,
'logo': self.get_logo(request),
'can_delete_popup': '',
'use_i18n': getattr(settings, 'USE_I18N', False)
}

def get_logo(self, request):
Expand Down
13 changes: 7 additions & 6 deletions django_daisy/static/admin/fields/json-editor/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ $(document).ready(function () {
"defaultUploadHandler": function (jseditor, type, file, cbs) {
// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();
let django_lang = getCookie("django_language")
let url = ""
if (django_lang) {
url = `/${django_lang}/admin/json-editor-upload-handler/`
} else {
url = '/admin/json-editor-upload-handler/'
const htmlElement = document.documentElement;
let url = '/admin/json-editor-upload-handler/'
if (htmlElement.hasAttribute('data-use-i18n') && htmlElement.getAttribute('data-use-i18n') === "1") {
const djangoLang = htmlElement.getAttribute('lang');
if (djangoLang) {
url = `/${djangoLang}${url}`;
}
}

// Configure it to send a POST request to the server endpoint
Expand Down
2 changes: 1 addition & 1 deletion django_daisy/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}

<!DOCTYPE html>
<html data-theme="" class="custom-scrollbars" lang="{{ LANGUAGE_CODE|default:"en-us" }}"
<html data-use-i18n="{{ use_i18n|yesno:'1,0' }}" data-theme="" class="custom-scrollbars" lang="{{ LANGUAGE_CODE|default:"en-us" }}"
{% if LANGUAGE_BIDI %}dir="rtl"
{% else %}dir="ltr"{% endif %}>

Expand Down

0 comments on commit 4467907

Please sign in to comment.