From a5f5557493446bede78adb0584c88208234f874e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 12 May 2012 09:32:30 -0500 Subject: Use python json module directly in place of simplejson As of Python 2.6, this is a builtin module that has all the same functions and capabilities of the Django simplejson module. Additionally simplejson is deprecated in the upcoming Django 1.5 release. Signed-off-by: Dan McGee --- visualize/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'visualize/views.py') diff --git a/visualize/views.py b/visualize/views.py index afc5429d..95f8c314 100644 --- a/visualize/views.py +++ b/visualize/views.py @@ -1,9 +1,9 @@ from datetime import datetime +import json from django.contrib.auth.models import User from django.db.models import Count, Sum, Q from django.http import HttpResponse -from django.utils import simplejson from django.views.decorators.cache import cache_page from django.views.generic.simple import direct_to_template @@ -61,13 +61,13 @@ def arch_repo_data(): @cache_page(1800) def by_arch(request): data = arch_repo_data() - to_json = simplejson.dumps(data['by_arch'], ensure_ascii=False) + 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 = simplejson.dumps(data['by_repo'], ensure_ascii=False) + to_json = json.dumps(data['by_repo'], ensure_ascii=False) return HttpResponse(to_json, mimetype='application/json') @@ -109,7 +109,7 @@ def pgp_keys(request): data = { 'nodes': node_list, 'edges': edge_list } - to_json = simplejson.dumps(data, ensure_ascii=False) + to_json = json.dumps(data, ensure_ascii=False) return HttpResponse(to_json, mimetype='application/json') # vim: set ts=4 sw=4 et: -- cgit v1.2.3-2-g168b From 76c37ce3acc7a4af0271c7535d4a33042f7749b5 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 24 Jul 2012 09:35:55 -0500 Subject: Replace deprecated direct_to_template() with render() shortcut Now that Django actually provides a concise way to use a RequestContext object without instantiating it, we can use that rather than the old function-based generic view that worked well to do the same. Additionally, these function-based generic views will be gone in Django 1.5, so might as well make the move now. Signed-off-by: Dan McGee --- visualize/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'visualize/views.py') diff --git a/visualize/views.py b/visualize/views.py index 95f8c314..44e60472 100644 --- a/visualize/views.py +++ b/visualize/views.py @@ -4,14 +4,14 @@ import json from django.contrib.auth.models import User from django.db.models import Count, Sum, Q from django.http import HttpResponse +from django.shortcuts import render from django.views.decorators.cache import cache_page -from django.views.generic.simple import direct_to_template from main.models import Package, Arch, Repo from devel.models import MasterKey, PGPSignature def index(request): - return direct_to_template(request, 'visualize/index.html', {}) + return render(request, 'visualize/index.html') def arch_repo_data(): qs = Package.objects.select_related().values( -- cgit v1.2.3-2-g168b From 45d81a9578e846062550335495dbceb82f16a1a0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 13 Nov 2012 10:03:55 -0600 Subject: 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 --- visualize/views.py | 51 +++++---------------------------------------------- 1 file changed, 5 insertions(+), 46 deletions(-) (limited to 'visualize/views.py') 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: -- cgit v1.2.3-2-g168b From 6dd4d54bb0adbbb0f8c2b1beaa92b7a58971cf88 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 16 Nov 2012 16:20:11 -0600 Subject: Use Python 2.7 dictionary comprehension syntax Rather than the old idiom of dict((k, v) for <> in <>). Signed-off-by: Dan McGee --- visualize/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'visualize/views.py') diff --git a/visualize/views.py b/visualize/views.py index 8d878937..48e8f86b 100644 --- a/visualize/views.py +++ b/visualize/views.py @@ -33,8 +33,8 @@ def arch_repo_data(): # now transform these results into two mappings: one ordered (repo, arch), # and one ordered (arch, repo). - arch_groups = dict((a, build_map(a, a, None)) for a in arches) - repo_groups = dict((r, build_map(r, None, r)) for r in repos) + arch_groups = {a: build_map(a, a, None) for a in arches} + repo_groups = {r: build_map(r, None, r) for r in repos} for row in qs: arch = row['arch__name'] repo = row['repo__name'] -- cgit v1.2.3-2-g168b From 66850026ca934e5a09238e9033c541cdc5085a42 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 13 Jan 2013 22:34:33 -0600 Subject: Use content_type and not mimetype on HttpResponse() Bug #16519 in Django deprecates mimetype, so update our code accordingly. Signed-off-by: Dan McGee --- visualize/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'visualize/views.py') diff --git a/visualize/views.py b/visualize/views.py index 48e8f86b..9c537c20 100644 --- a/visualize/views.py +++ b/visualize/views.py @@ -62,13 +62,13 @@ def arch_repo_data(): 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') + return HttpResponse(to_json, content_type='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') + return HttpResponse(to_json, content_type='application/json') # vim: set ts=4 sw=4 et: -- cgit v1.2.3-2-g168b