Skip to content
Snippets Groups Projects
Commit 75077b8b authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Let JS function return a full script

parent bdcb0c7a
No related branches found
No related tags found
No related merge requests found
......@@ -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",
)
......
[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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment