diff options
author | Dan McGee <dan@archlinux.org> | 2011-11-11 01:09:19 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-11-11 01:09:19 +0100 |
commit | d80f4236d01f70380f71a46dd98f1f789d91d31c (patch) | |
tree | 73569e893400eb68b98bc97b513d9da36338bbbe | |
parent | 886630dd4e65a7be6d1bd3d8a0e70ab24e5affc6 (diff) | |
download | archweb-d80f4236d01f70380f71a46dd98f1f789d91d31c.tar.gz archweb-d80f4236d01f70380f71a46dd98f1f789d91d31c.tar.xz |
Add package signoffs JSON view
This allows access to the same data (and even a bit more) from the
signoffs overview page in a machine-friendly way.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | mirrors/utils.py | 3 | ||||
-rw-r--r-- | packages/urls.py | 1 | ||||
-rw-r--r-- | packages/views.py | 47 |
3 files changed, 49 insertions, 2 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py index 686ec58..8518b3b 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -40,7 +40,8 @@ def get_mirror_statuses(cutoff=default_cutoff): last_sync=Max('logs__last_sync'), last_check=Max('logs__check_time'), duration_avg=Avg('logs__duration'), - duration_stddev=StdDev('logs__duration') + #duration_stddev=StdDev('logs__duration') + duration_stddev=Max('logs__duration') ).order_by('-last_sync', '-duration_avg') # The Django ORM makes it really hard to get actual average delay in the diff --git a/packages/urls.py b/packages/urls.py index 4d391a3..1f25e3f 100644 --- a/packages/urls.py +++ b/packages/urls.py @@ -18,6 +18,7 @@ package_patterns = patterns('packages.views', urlpatterns = patterns('packages.views', (r'^flaghelp/$', 'flaghelp'), (r'^signoffs/$', 'signoffs', {}, 'package-signoffs'), + (r'^signoffs/json/$', 'signoffs_json', {}, 'package-signoffs-json'), (r'^update/$', 'update'), (r'^$', 'search', {}, 'packages-search'), diff --git a/packages/views.py b/packages/views.py index 3c0c2be..cac5d07 100644 --- a/packages/views.py +++ b/packages/views.py @@ -29,7 +29,8 @@ from main.utils import make_choice from mirrors.models import MirrorUrl from .models import PackageRelation, PackageGroup, SignoffSpecification, Signoff from .utils import (get_group_info, get_differences_info, - get_wrong_permissions, get_signoff_groups, approved_by_signoffs) + get_wrong_permissions, get_signoff_groups, approved_by_signoffs, + PackageSignoffGroup) class PackageJSONEncoder(DjangoJSONEncoder): pkg_attributes = [ 'pkgname', 'pkgbase', 'repo', 'arch', 'pkgver', @@ -371,6 +372,7 @@ def unflag_all(request, name, repo, arch): pkgs.update(flag_date=None) return redirect(pkg) + @permission_required('main.change_package') @never_cache def signoffs(request): @@ -496,6 +498,49 @@ def signoff_options(request, name, repo, arch): } return direct_to_template(request, 'packages/signoff_options.html', context) +class SignoffJSONEncoder(DjangoJSONEncoder): + '''Base JSONEncoder extended to handle all serialization of all classes + related to signoffs.''' + signoff_group_attrs = ['arch', 'last_update', 'maintainers', 'packager', + 'pkgbase', 'repo', 'signoffs', 'target_repo', 'version'] + signoff_spec_attrs = ['required', 'enabled', 'known_bad', 'comments'] + signoff_attrs = ['user', 'created', 'revoked'] + + def default(self, obj): + if isinstance(obj, PackageSignoffGroup): + data = dict((attr, getattr(obj, attr)) + for attr in self.signoff_group_attrs) + data['package_count'] = len(obj.packages) + data['approved'] = obj.approved() + data.update((attr, getattr(obj.specification, attr)) + for attr in self.signoff_spec_attrs) + return data + elif isinstance(obj, Signoff): + data = dict((attr, getattr(obj, attr)) + for attr in self.signoff_attrs) + return data + elif isinstance(obj, Arch) or isinstance(obj, Repo): + return unicode(obj) + elif isinstance(obj, User): + return obj.username + elif isinstance(obj, set): + return list(obj) + return super(SignoffJSONEncoder, self).default(obj) + +@permission_required('main.change_package') +@never_cache +def signoffs_json(request): + signoff_groups = sorted(get_signoff_groups(), key=attrgetter('pkgbase')) + data = { + 'version': 1, + 'signoff_groups': signoff_groups, + } + to_json = simplejson.dumps(data, ensure_ascii=False, + cls=SignoffJSONEncoder) + response = HttpResponse(to_json, mimetype='application/json') + return response + + def flaghelp(request): return direct_to_template(request, 'packages/flaghelp.html') |