@@ -107,27 +107,30 @@ def project_badge(request, project_slug):
107
107
"""Return a sweet badge for the project"""
108
108
version_slug = request .GET .get ('version' , LATEST )
109
109
style = request .GET .get ('style' , 'flat' )
110
+ # Default to 24 hour cache lifetime
111
+ max_age = request .GET .get ('maxAge' , 86400 )
110
112
try :
111
113
version = Version .objects .public (request .user ).get (
112
114
project__slug = project_slug , slug = version_slug )
113
115
except Version .DoesNotExist :
114
116
url = (
115
- 'https://img.shields.io/badge/docs-unknown%20version-yellow.svg?style={style}'
116
- .format (style = style ))
117
+ 'https://img.shields.io/badge/docs-unknown%20version-yellow.svg?style={style}&maxAge={max_age} '
118
+ .format (style = style , max_age = max_age ))
117
119
return HttpResponseRedirect (url )
118
120
version_builds = version .builds .filter (type = 'html' , state = 'finished' ).order_by ('-date' )
119
121
if not version_builds .exists ():
120
122
url = (
121
- 'https://img.shields.io/badge/docs-no%20builds-yellow.svg?style={style}'
122
- .format (style = style ))
123
+ 'https://img.shields.io/badge/docs-no%20builds-yellow.svg?style={style}&maxAge={max_age} '
124
+ .format (style = style , max_age = max_age ))
123
125
return HttpResponseRedirect (url )
124
126
last_build = version_builds [0 ]
125
127
if last_build .success :
126
128
color = 'brightgreen'
127
129
else :
128
130
color = 'red'
129
- url = 'https://img.shields.io/badge/docs-%s-%s.svg?style=%s' % (
130
- version .slug .replace ('-' , '--' ), color , style )
131
+ url = ('https://img.shields.io/badge/docs-{version}-{color}.svg?style={style}&maxAge={max_age}'
132
+ .format (version = version .slug .replace ('-' , '--' ), color = color ,
133
+ style = style , max_age = max_age ))
131
134
return HttpResponseRedirect (url )
132
135
133
136
0 commit comments