summaryrefslogtreecommitdiff
path: root/releng/views.py
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-05-25 19:34:21 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-05-25 19:34:21 -0400
commit1a1fd4a3d6aa7f6b2338f7751f5f97a30a059a04 (patch)
treef608874663d24f19ecf175ec556f2a330d47a726 /releng/views.py
parent747a562ddca10e29dd003e8b3c59f8f384d1bc8d (diff)
parentcd7222047b41ac3efa389a22fdd22148d03c1d61 (diff)
Merge tag 'release_2014-03-22' into archweb-generic
Fix long filenames; local storage for filter prefs Conflicts: templates/public/download.html
Diffstat (limited to 'releng/views.py')
-rw-r--r--releng/views.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/releng/views.py b/releng/views.py
index bc7ddb34..af25b966 100644
--- a/releng/views.py
+++ b/releng/views.py
@@ -1,7 +1,10 @@
from base64 import b64decode
+import json
from django import forms
from django.conf import settings
+from django.core.serializers.json import DjangoJSONEncoder
+from django.core.urlresolvers import reverse
from django.db.models import Count, Max
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
@@ -238,4 +241,46 @@ def release_torrent(request, version):
response['Content-Disposition'] = 'attachment; filename=%s' % filename
return response
+
+class ReleaseJSONEncoder(DjangoJSONEncoder):
+ release_attributes = ('release_date', 'version', 'kernel_version',
+ 'created', 'md5_sum', 'sha1_sum')
+
+ def default(self, obj):
+ if hasattr(obj, '__iter__'):
+ # mainly for queryset serialization
+ return list(obj)
+ if isinstance(obj, Release):
+ data = {attr: getattr(obj, attr) or None
+ for attr in self.release_attributes}
+ data['available'] = obj.available
+ data['iso_url'] = '/' + obj.iso_url()
+ data['magnet_uri'] = obj.magnet_uri()
+ data['torrent_url'] = reverse('releng-release-torrent', args=[obj.version])
+ data['info'] = obj.info_html()
+ torrent_data = obj.torrent()
+ if torrent_data:
+ torrent_data.pop('url_list', None)
+ data['torrent'] = torrent_data
+ return data
+ return super(ReleaseJSONEncoder, self).default(obj)
+
+
+def releases_json(request):
+ releases = Release.objects.all()
+ try:
+ latest_version = Release.objects.filter(available=True).values_list(
+ 'version', flat=True).latest()
+ except Release.DoesNotExist:
+ latest_version = None
+
+ data = {
+ 'version': 1,
+ 'releases': releases,
+ 'latest_version': latest_version,
+ }
+ to_json = json.dumps(data, ensure_ascii=False, cls=ReleaseJSONEncoder)
+ response = HttpResponse(to_json, content_type='application/json')
+ return response
+
# vim: set ts=4 sw=4 et: