From 75077b8b4161fcc861fb33d37466e462de5a9035 Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Tue, 14 Jan 2020 20:12:24 +0100 Subject: [PATCH] Let JS function return a full script --- calendarweek/django.py | 24 ++++++++++++++---------- pyproject.toml | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/calendarweek/django.py b/calendarweek/django.py index 0692ff3..db3c645 100644 --- a/calendarweek/django.py +++ b/calendarweek/django.py @@ -2,7 +2,7 @@ import json import locale from typing import Tuple -from django.http import HttpRequest, JsonResponse +from django.http import HttpRequest, HttpResponse from django.utils.encoding import DEFAULT_LOCALE_ENCODING from django.utils.functional import lazy from django.utils.translation import get_language, to_locale @@ -78,17 +78,21 @@ def i18n_month_abbr_choices() -> Tuple[Tuple[int, str]]: return enumerate(i18n_month_abbrs()) -def i18n_json_data(request: HttpRequest) -> JsonResponse: - """ Deliver a JSON file containing JS representations of the current locale's +def i18n_js(request: HttpRequest) -> HttpResponse: + """ Deliver a JS file containing JS representations of the current locale's calendar translations. """ - return JsonResponse( - { - "day_names": i18n_day_names(), - "day_abbrs": i18n_day_abbrs(), - "month_names": i18n_month_names(), - "month_abbrs": i18n_month_abbrs(), - } + return HttpResponse( + "var calendarweek_i18n = " + + json.dumps( + { + "day_names": i18n_day_names(), + "day_abbrs": i18n_day_abbrs(), + "month_names": i18n_month_names(), + "month_abbrs": i18n_month_abbrs(), + } + ), + content_type="text/javascript", ) diff --git a/pyproject.toml b/pyproject.toml index ea5270e..6c10d04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "calendarweek" -version = "0.2.0" +version = "0.2.1" description = "Utilities for working with calendar weeks in Python and Django" authors = ["Dominik George <nik@naturalnet.de>", "Jonathan Weth <git@jonathanweth.de>"] license = "MIT" -- GitLab