From df4b0ef5cfe8c12aa3643b7aef149fc1516bfe1a Mon Sep 17 00:00:00 2001 From: Pomax Date: Tue, 11 Feb 2020 11:51:48 -0800 Subject: [PATCH] modeltranslations 10.7 obviates the need for our own l10n shim (#4184) * modeltranslations 10.7 obviates the need for our own l10n shim * forget to save * ugh --- Pipfile | 2 +- Pipfile.lock | 6 +- network-api/networkapi/settings.py | 1 - .../static/css/language_toggles.css | 51 ------ .../static/js/language_toggles.js | 153 ------------------ .../wagtail_hooks.py | 48 ------ 6 files changed, 4 insertions(+), 257 deletions(-) delete mode 100644 network-api/networkapi/wagtail_l10n_customization/static/css/language_toggles.css delete mode 100644 network-api/networkapi/wagtail_l10n_customization/static/js/language_toggles.js delete mode 100644 network-api/networkapi/wagtail_l10n_customization/wagtail_hooks.py diff --git a/Pipfile b/Pipfile index 89a892c78..9391476e8 100644 --- a/Pipfile +++ b/Pipfile @@ -29,7 +29,7 @@ wagtail-factories = "*" wagtail-inventory = "==0.8" wagtail-metadata = "*" whitenoise = "*" -wagtail-modeltranslation = "==0.10.6" +wagtail-modeltranslation = "==0.10.7" "psycopg2-binary" = "==2.8.4" cloudinary = "*" wagtail-experiments = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 965d9fb44..a24eeb5a2 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "117f5ee349f9f4cb49697708a339dc0cc280e71f851bc95a2a71f4e1bc5c0c38" + "sha256": "9e18873c6682dd77c95e01d1554592dec4e9463c445794aad685867ba16408c2" }, "pipfile-spec": 6, "requires": { @@ -511,10 +511,10 @@ }, "wagtail-modeltranslation": { "hashes": [ - "sha256:d3d8e072f9b1a9b81c7ff9c4ca7aa4572ff97d9f6689f80f552d84454cb49b9b" + "sha256:16ca215c5d35837a6cd5ca7e9e7f9f5f91811d6be3c8a9a928915d55ce4a493e" ], "index": "pypi", - "version": "==0.10.6" + "version": "==0.10.7" }, "webencodings": { "hashes": [ diff --git a/network-api/networkapi/settings.py b/network-api/networkapi/settings.py index 36d857e43..e508c16bc 100644 --- a/network-api/networkapi/settings.py +++ b/network-api/networkapi/settings.py @@ -214,7 +214,6 @@ INSTALLED_APPS = list(filter(None, [ 'networkapi.milestones', # wagtail localisation app - 'networkapi.wagtail_l10n_customization', 'wagtail_modeltranslation', 'wagtail_modeltranslation.makemigrations', 'wagtail_modeltranslation.migrate', diff --git a/network-api/networkapi/wagtail_l10n_customization/static/css/language_toggles.css b/network-api/networkapi/wagtail_l10n_customization/static/css/language_toggles.css deleted file mode 100644 index 12cbc34f1..000000000 --- a/network-api/networkapi/wagtail_l10n_customization/static/css/language_toggles.css +++ /dev/null @@ -1,51 +0,0 @@ -form .l10n-hidden { - display: none; -} - -div.locale-picker { - display: block; - text-align: right; - margin-top: 1.5em; - margin-bottom: 0.5em; -} - -form > div.locale-picker { - /* calc, to highlight what we're doing here: - wagtail's header has a 2em margin-bottom, - and so we correct that for the 1.5em - margin-bottom used in the normal definition - for the div.locale-picker, above */ - margin-top: calc(1.5em - 2em); - margin-bottom: 1em; -} - -div.locale-picker h2 { - display: inline; -} - -div.locale-picker ul.locales { - display: inline-block; - margin: auto 1em; -} - -div.locale-picker ul.locales li.locale { - display: inline; - margin: auto 0.5em; -} - -div.locale-picker ul.locales li.locale button.locale-toggle { - background-color: rgba(57, 151, 150, 0.3); - text-transform: uppercase; - outline: none; - border: none; - font-weight: 700; - font-size: 1.2em; - text-decoration: none; - color: #ffffff; - padding: 0.25em; - max-height: 2em; -} - -div.locale-picker ul.locales li.locale button.locale-toggle.showing-locale { - background-color: #43b1b0; -} diff --git a/network-api/networkapi/wagtail_l10n_customization/static/js/language_toggles.js b/network-api/networkapi/wagtail_l10n_customization/static/js/language_toggles.js deleted file mode 100644 index 9c9dbd67c..000000000 --- a/network-api/networkapi/wagtail_l10n_customization/static/js/language_toggles.js +++ /dev/null @@ -1,153 +0,0 @@ -/////////////// -jQuery(() => { - /////////////// - - const tabbedContent = $(`form .tab-content`); - const topLevel = - tabbedContent.length > 0 ? tabbedContent : $(`.content form`); - - if (topLevel.length === 0) { - // obviously, if we don't have an element to attach - // the picker to, we might as well stop right now. - return; - } - - if (topLevel.attr(`class`) && topLevel.attr(`class`).indexOf(`search`) > -1) { - // if the only forms on the page are search forms, - // we're not actually dealing with page/snippets - return; - } - - /** - * ... - */ - function filterForLocale(index, element) { - var tc = element.textContent; - var res = tc.match(/ \[\w\w\]/); - if (res === null) return; - - var code = res[0], - locale = code.replace(/[ \[\]]/g, ""); - - // Verify this is a known locale and not a fluke, - // using the global "langs" variable, which is an - // array of all language codes specified in the - // settings.LANGUAGES variable for Django. - if (langs.indexOf(locale) === -1) return; - - // We do our show/hiding based on list items, - // otherwise we're just "emptying" a list item - // while leaving its spacing CSS intact. - if (element.nodeName !== "LI") { - element = $(element).closest("li")[0]; - } - - // Bootstrap an empty bin if we don't have one. - if (!localisedElements[locale]) { - localisedElements[locale] = []; - } - - // Add this element to our bin, provided it had - // not already been added. - var bin = localisedElements[locale]; - if (bin.indexOf(element) === -1) { - bin.push(element); - element.classList.add(`l10n-hidden`); - - // also note that "field-col" elements may now look horribly - // wrong, due to how Wagtail computes which of "col3"..."col12" - // to use. Because wagtail-modeltranslation introduces many more - // elements to show in an "inline" element, things that were - // "col6" before end up being "col1", looking terribly wrong indeed. - element.classList.remove(...columnCSS); - } - } - - /** - * Build the set of fields-per-locale. Each set will receive - * a button to toggle visibility for all fields in that set, - * with the note that unlocalised content (such as images) - * will always stay visible. - */ - function buildSets() { - $(`li.object, div.field`, topLevel).each(filterForLocale); - } - - /** - * Build a locale picker bar, with buttons that toggle - * visibility for each locale's fields. - */ - function buildLocaleToggler() { - var bar = $( - `

View/edit fields for:

` - ); - var ul = $(``); - bar.append(ul); - - var toggles = {}; - locales.forEach(locale => { - var li = $( - `
  • ` - ); - ul.append(li); - - $(`button.locale-toggle`, li).each((index, toggle) => { - toggle.addEventListener(`click`, e => { - e.preventDefault(); - toggle.classList.toggle(`showing-locale`); - toggleLocale(locale); - }); - - toggles[locale] = toggle; - }); - }); - - bar.prependTo(topLevel); - - return toggles; - } - - /** - * This function allows either blind toggling - * of a field's visibility, or explicitly - * making visible/invisible based on the - * value of `state` (a boolean). - */ - function toggleLocale(locale, state) { - var action = `toggle`; - - if (state !== undefined) { - action = state ? `remove` : `add`; - } - - localisedElements[locale].forEach(element => { - element.classList[action](`l10n-hidden`); - }); - } - - var default_locale = `en`; - var localisedElements = {}; - var columnCSS = [`field-col`]; - for (var i = 1; i <= 12; i++) { - columnCSS.push(`col${i}`); - } - - // Build the sets that track which fields - // belong to which language code. - buildSets(); - - var locales = Object.keys(localisedElements).sort(); - - // If there are no locale sets, then there is - // no locale field picker to build, either. - if (locales.length === 0) return; - - // If there are locale sets, make sure to - // enable at least the default locale after - // building and hiding all locale sets. - var localeToggler = buildLocaleToggler(); - localeToggler[default_locale].click(); - - /////////////// -}); -/////////////// diff --git a/network-api/networkapi/wagtail_l10n_customization/wagtail_hooks.py b/network-api/networkapi/wagtail_l10n_customization/wagtail_hooks.py deleted file mode 100644 index 58608c385..000000000 --- a/network-api/networkapi/wagtail_l10n_customization/wagtail_hooks.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.conf import settings -from django.utils.html import format_html_join -from django.utils.translation import gettext - -from wagtail.core import hooks - - -@hooks.register('insert_global_admin_js') -def language_toggles(): - """ - On any admin page, try to load the l10n code that aggregates - fieldsets per locale, then gives it a button that you can - click to show/hide all those fields. - """ - - js_files = ['js/language_toggles.js'] - - lang_codes = [] - for lang in settings.LANGUAGES: - lang_codes.append("'%s'" % lang[0]) - - js_languages = """ - - """.format( - languages=", ".join(lang_codes), - language_code=settings.LANGUAGE_CODE, - view_edit_string=gettext('View / edit fields for') - ) - - js_includes = format_html_join( - '\n', '', - ((settings.STATIC_URL, filename) for filename in js_files) - ) - - css_files = ['css/language_toggles.css'] - - css_includes = format_html_join( - '\n', '', - ((settings.STATIC_URL, filename) for filename in css_files) - ) - - return js_languages + js_includes + css_includes