summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-11-13 10:03:55 -0600
committerDan McGee <dan@archlinux.org>2012-11-13 10:21:02 -0600
commit45d81a9578e846062550335495dbceb82f16a1a0 (patch)
treeb05565820bf55ec9d0f0fa05bb672e5c0e507a02
parent5d468b2f7b42f71da7cbd475d20dd422f0bfffc5 (diff)
Move JSON keys view to public/ app
This seems like a more appropriate place, and now the visualization is done here anyway so we should move the data backing it. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--public/views.py53
-rw-r--r--templates/public/keys.html2
-rw-r--r--urls.py1
-rw-r--r--visualize/urls.py1
-rw-r--r--visualize/views.py51
5 files changed, 58 insertions, 50 deletions
diff --git a/public/views.py b/public/views.py
index 42f2f345..96120761 100644
--- a/public/views.py
+++ b/public/views.py
@@ -1,12 +1,13 @@
from datetime import datetime
+import json
from operator import attrgetter
from django.conf import settings
from django.contrib.auth.models import User
from django.db.models import Count, Q
-from django.http import Http404
+from django.http import Http404, HttpResponse
from django.shortcuts import render
-from django.views.decorators.cache import cache_control
+from django.views.decorators.cache import cache_control, cache_page
from devel.models import MasterKey, PGPSignature
from main.models import Arch, Repo, Donor
@@ -14,6 +15,7 @@ from mirrors.models import MirrorUrl
from news.models import News
from .utils import get_recent_updates
+
@cache_control(max_age=300)
def index(request):
if request.user.is_authenticated():
@@ -44,6 +46,7 @@ USER_LISTS = {
},
}
+
@cache_control(max_age=300)
def userlist(request, user_type='devs'):
users = User.objects.order_by(
@@ -63,6 +66,7 @@ def userlist(request, user_type='devs'):
context['users'] = users
return render(request, 'public/userlist.html', context)
+
@cache_control(max_age=300)
def donate(request):
context = {
@@ -70,6 +74,7 @@ def donate(request):
}
return render(request, 'public/donate.html', context)
+
@cache_control(max_age=300)
def download(request):
mirror_urls = MirrorUrl.objects.select_related('mirror').filter(
@@ -84,6 +89,7 @@ def download(request):
}
return render(request, 'public/download.html', context)
+
@cache_control(max_age=300)
def feeds(request):
repos = Repo.objects.all()
@@ -95,6 +101,7 @@ def feeds(request):
}
return render(request, 'public/feeds.html', context)
+
@cache_control(max_age=300)
def keys(request):
users = User.objects.filter(is_active=True).select_related(
@@ -132,4 +139,46 @@ def keys(request):
}
return render(request, 'public/keys.html', context)
+
+@cache_page(1800)
+def keys_json(request):
+ node_list = []
+
+ users = User.objects.filter(is_active=True).select_related('userprofile')
+ node_list.extend({
+ 'name': dev.get_full_name(),
+ 'key': dev.userprofile.pgp_key,
+ 'group': 'dev'
+ } for dev in users.filter(groups__name='Developers'))
+ node_list.extend({
+ 'name': tu.get_full_name(),
+ 'key': tu.userprofile.pgp_key,
+ 'group': 'tu'
+ } for tu in users.filter(groups__name='Trusted Users').exclude(
+ groups__name='Developers'))
+
+ master_keys = MasterKey.objects.select_related('owner').filter(
+ revoked__isnull=True)
+ node_list.extend({
+ 'name': 'Master Key (%s)' % key.owner.get_full_name(),
+ 'key': key.pgp_key,
+ 'group': 'master'
+ } for key in master_keys)
+
+ node_list.append({
+ 'name': 'CA Cert Signing Authority',
+ 'key': 'A31D4F81EF4EBD07B456FA04D2BB0D0165D0FD58',
+ 'group': 'cacert',
+ })
+
+ not_expired = Q(expires__gt=datetime.utcnow) | Q(expires__isnull=True)
+ signatures = PGPSignature.objects.filter(not_expired, valid=True)
+ edge_list = [{ 'signee': sig.signee, 'signer': sig.signer }
+ for sig in signatures]
+
+ data = { 'nodes': node_list, 'edges': edge_list }
+
+ to_json = json.dumps(data, ensure_ascii=False)
+ return HttpResponse(to_json, mimetype='application/json')
+
# vim: set ts=4 sw=4 et:
diff --git a/templates/public/keys.html b/templates/public/keys.html
index 81713efb..9af491e2 100644
--- a/templates/public/keys.html
+++ b/templates/public/keys.html
@@ -149,7 +149,7 @@ $(document).ready(function() {
});
});
$(document).ready(function() {
- developer_keys("#visualize-keys", "{% url 'visualize-pgp_keys' %}");
+ developer_keys("#visualize-keys", "{% url 'pgp-keys-json' %}");
});
</script>
{% endblock %}
diff --git a/urls.py b/urls.py
index fd5ff7cf..1bdf1a58 100644
--- a/urls.py
+++ b/urls.py
@@ -67,6 +67,7 @@ urlpatterns += patterns('public.views',
(r'^donate/$', 'donate', {}, 'page-donate'),
(r'^download/$', 'download', {}, 'page-download'),
(r'^master-keys/$', 'keys', {}, 'page-keys'),
+ (r'^master-keys/json/$', 'keys_json', {}, 'pgp-keys-json'),
)
urlpatterns += patterns('retro.views',
diff --git a/visualize/urls.py b/visualize/urls.py
index 907f6a22..8c3ea06a 100644
--- a/visualize/urls.py
+++ b/visualize/urls.py
@@ -4,7 +4,6 @@ urlpatterns = patterns('visualize.views',
(r'^$', 'index', {}, 'visualize-index'),
(r'^by_arch/$', 'by_arch', {}, 'visualize-byarch'),
(r'^by_repo/$', 'by_repo', {}, 'visualize-byrepo'),
- (r'^pgp_keys/$', 'pgp_keys', {}, 'visualize-pgp_keys'),
)
# vim: set ts=4 sw=4 et:
diff --git a/visualize/views.py b/visualize/views.py
index 44e60472..8d878937 100644
--- a/visualize/views.py
+++ b/visualize/views.py
@@ -1,18 +1,17 @@
-from datetime import datetime
import json
-from django.contrib.auth.models import User
-from django.db.models import Count, Sum, Q
+from django.db.models import Count, Sum
from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from main.models import Package, Arch, Repo
-from devel.models import MasterKey, PGPSignature
+
def index(request):
return render(request, 'visualize/index.html')
+
def arch_repo_data():
qs = Package.objects.select_related().values(
'arch__name', 'repo__name').annotate(
@@ -58,58 +57,18 @@ def arch_repo_data():
}
return data
+
@cache_page(1800)
def by_arch(request):
data = arch_repo_data()
to_json = json.dumps(data['by_arch'], ensure_ascii=False)
return HttpResponse(to_json, mimetype='application/json')
+
@cache_page(1800)
def by_repo(request):
data = arch_repo_data()
to_json = json.dumps(data['by_repo'], ensure_ascii=False)
return HttpResponse(to_json, mimetype='application/json')
-
-@cache_page(1800)
-def pgp_keys(request):
- node_list = []
-
- users = User.objects.filter(is_active=True).select_related('userprofile')
- node_list.extend({
- 'name': dev.get_full_name(),
- 'key': dev.userprofile.pgp_key,
- 'group': 'dev'
- } for dev in users.filter(groups__name='Developers'))
- node_list.extend({
- 'name': tu.get_full_name(),
- 'key': tu.userprofile.pgp_key,
- 'group': 'tu'
- } for tu in users.filter(groups__name='Trusted Users').exclude(
- groups__name='Developers'))
-
- master_keys = MasterKey.objects.select_related('owner').filter(
- revoked__isnull=True)
- node_list.extend({
- 'name': 'Master Key (%s)' % key.owner.get_full_name(),
- 'key': key.pgp_key,
- 'group': 'master'
- } for key in master_keys)
-
- node_list.append({
- 'name': 'CA Cert Signing Authority',
- 'key': 'A31D4F81EF4EBD07B456FA04D2BB0D0165D0FD58',
- 'group': 'cacert',
- })
-
- not_expired = Q(expires__gt=datetime.utcnow) | Q(expires__isnull=True)
- signatures = PGPSignature.objects.filter(not_expired, valid=True)
- edge_list = [{ 'signee': sig.signee, 'signer': sig.signer }
- for sig in signatures]
-
- data = { 'nodes': node_list, 'edges': edge_list }
-
- to_json = json.dumps(data, ensure_ascii=False)
- return HttpResponse(to_json, mimetype='application/json')
-
# vim: set ts=4 sw=4 et: