cache the button popups for a long time (bug 562231)

This commit is contained in:
Jeff Balogh 2010-04-28 09:02:41 -07:00
Родитель 1be791de06
Коммит 878beaecdc
5 изменённых файлов: 28 добавлений и 6 удалений

Просмотреть файл

@ -1,4 +1,5 @@
from django.db.models import Q
from django.views.decorators.cache import cache_page
import jingo
import jinja2
@ -199,6 +200,8 @@ class Link(object):
self.text, self.url, self.os, self.file = text, url, os, file
# Cache it for a year.
@cache_page(60 * 60 * 24 * 365)
def js(request):
return jingo.render(request, 'addons/popups.html',
content_type='text/javascript')

Просмотреть файл

@ -1,3 +1,6 @@
from datetime import datetime
from django import test
from django.conf import settings
from django.core.cache import cache
@ -172,8 +175,8 @@ class TestDetailPage(test_utils.TestCase):
"""
addon = Addon.objects.get(id=3615)
comp_app = addon.compatible_apps.keys()[0]
not_comp_app = [ a for a in amo.APP_USAGE if a not in
addon.compatible_apps.keys() ][0]
not_comp_app = [a for a in amo.APP_USAGE
if a not in addon.compatible_apps.keys()][0]
# no SeaMonkey version => redirect
prefixer = amo.urlresolvers.get_url_prefix()
@ -282,6 +285,7 @@ class TestDetailPage(test_utils.TestCase):
ret = _details_collections_dropdown(request, profile, addon)
eq_(len(ret), 1)
class TestTagsBox(test_utils.TestCase):
fixtures = ['base/addontag']
@ -290,3 +294,11 @@ class TestTagsBox(test_utils.TestCase):
r = self.client.get(reverse('addons.detail', args=[8680]), follow=True)
doc = pq(r.content)
eq_('SEO', doc('#tags ul').children().text())
def test_button_caching():
"""The button popups should be cached for a long time."""
response = test.Client().get(reverse('addons.buttons.js'), follow=True)
fmt = '%a, %d %b %Y %H:%M:%S GMT'
expires = datetime.strptime(response['Expires'], fmt)
assert (expires - datetime.now()).days >= 365

Просмотреть файл

@ -1,7 +1,7 @@
from django.conf import settings
from jingo import register
from jinja2 import Markup
from jingo import register, env
try:
@ -9,6 +9,7 @@ try:
except ImportError:
BUILD_ID_CSS = BUILD_ID_JS = 'dev'
def _build_html(items, wrapping):
"""
Wrap `items` in wrapping.
@ -44,3 +45,8 @@ def css(bundle, media="screen,projection,tv", debug=settings.TEMPLATE_DEBUG):
return _build_html(items,
"""<link rel="stylesheet" media="%s" href="%%s" />""" % media)
def build_ids(request):
"""A context processor for injecting the css/js build ids."""
return {'BUILD_ID_CSS': BUILD_ID_CSS, 'BUILD_ID_JS': BUILD_ID_JS}

Просмотреть файл

@ -135,12 +135,14 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'amo.context_processors.app',
'amo.context_processors.i18n',
'amo.context_processors.global_settings',
'minify.helpers.build_ids',
)
TEMPLATE_DIRS = (
path('templates'),
)
def JINJA_CONFIG():
import jinja2
from django.conf import settings
@ -160,7 +162,6 @@ def JINJA_CONFIG():
return config
MIDDLEWARE_CLASSES = (
'commonware.log.ThreadRequestMiddleware',
# AMO URL middleware comes first so everyone else sees nice URLs.
@ -284,7 +285,7 @@ MINIFY_BUNDLES = {
),
'zamboni/discovery-pane': (
'css/zamboni/discovery-pane.css',
)
),
},
'js': {
# JS files common to the entire site.

Просмотреть файл

@ -71,7 +71,7 @@
{# js #}
<script src="{{ url('django.views.i18n.javascript_catalog') }}"></script>
{{ js('common') }}
<script async defer src="{{ url('addons.buttons.js') }}"></script>
<script async defer src="{{ url('addons.buttons.js') }}?build={{ BUILD_ID_JS }}"></script>
{% block js %}{% endblock %}
{% include "footer.html" %}
{# Webtrends Stats Tracking #}