Fix #229 -- Consistent language between django and javascript

This commit is contained in:
Raphael Michel
2016-09-17 22:46:07 +02:00
parent f79e1adf25
commit e29ccca49b
4 changed files with 29 additions and 20 deletions

View File

@@ -0,0 +1,25 @@
from django.utils import timezone
from django.views.decorators.cache import cache_page
from django.views.decorators.http import etag
from django.views.i18n import (
get_javascript_catalog, render_javascript_catalog, to_locale,
)
# Yes, we want to regenerate this every time the module has been imported to
# refresh the cache at least at every code deployment
import_date = timezone.now().strftime("%Y%m%d%H%M")
# This is not a valid Django URL configuration, as the final
# configuration is done by the pretix.multidomain package.
js_info_dict = {
'packages': ('pretix',),
}
@etag(lambda *s, **k: import_date)
@cache_page(3600, key_prefix='js18n-%s' % import_date)
def js_catalog(request, lang):
packages = ['pretix']
catalog, plural = get_javascript_catalog(to_locale(lang), 'djangojs', packages)
return render_javascript_catalog(catalog, plural)

View File

@@ -9,7 +9,7 @@
{% compress css %}
<link rel="stylesheet" type="text/x-scss" href="{% static "pretixcontrol/scss/main.scss" %}" />
{% endcompress %}
<script type="text/javascript" src="{% url "javascript-catalog" %}"></script>
<script type="text/javascript" src="{% url "javascript-catalog" lang=request.LANGUAGE_CODE %}"></script>
{% compress js %}
<script type="text/javascript" src="{% static "jquery/js/jquery-2.1.1.min.js" %}"></script>
<script type="text/javascript" src="{% static "js/jquery.formset.js" %}"></script>

View File

@@ -15,7 +15,7 @@
<link rel="stylesheet" type="text/x-scss" href="{% static "pretixpresale/scss/main.scss" %}"/>
{% endcompress %}
{% endif %}
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' lang=request.LANGUAGE_CODE %}"></script>
{% compress js %}
<script type="text/javascript" src="{% static "jquery/js/jquery-2.1.1.min.js" %}"></script>
<script type="text/javascript" src="{% static "moment/moment-with-locales.js" %}"></script>

View File

@@ -1,24 +1,10 @@
from django.conf import settings
from django.conf.urls import include, url
from django.utils import timezone
from django.views.decorators.cache import cache_page
from django.views.decorators.http import etag
from django.views.i18n import javascript_catalog
import pretix.control.urls
import pretix.presale.urls
from .base.views import cachedfiles, health, redirect
# This is not a valid Django URL configuration, as the final
# configuration is done by the pretix.multidomain package.
js_info_dict = {
'packages': ('pretix',),
}
# Yes, we want to regenerate this every time the module has been imported to
# refresh the cache at least at every code deployment
import_date = timezone.now().strftime("%Y%m%d%H%M")
from .base.views import cachedfiles, health, js_catalog, redirect
base_patterns = [
url(r'^download/(?P<id>[^/]+)/$', cachedfiles.DownloadView.as_view(),
@@ -26,9 +12,7 @@ base_patterns = [
url(r'^healthcheck/$', health.healthcheck,
name='healthcheck'),
url(r'^redirect/$', redirect.redir_view, name='redirect'),
url(r'^jsi18n/$',
etag(lambda *s, **k: import_date)(cache_page(3600, key_prefix='js18n-%s' % import_date)(javascript_catalog)),
js_info_dict, name='javascript-catalog'),
url(r'^jsi18n/(?P<lang>[a-zA-Z-_]+)/$', js_catalog.js_catalog, name='javascript-catalog'),
]
control_patterns = [