summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-07-23 21:31:17 -0500
committerDan McGee <dan@archlinux.org>2012-07-23 21:31:17 -0500
commit211340c8bd6ccd6b16f3115a71fce4abedcc4c06 (patch)
tree4c3f77685f3d2f6f5e62284ef3098fd3ef0c4481 /packages
parent374bf53505480eebd675e95f975dc908c485a6fa (diff)
downloadarchweb-211340c8bd6ccd6b16f3115a71fce4abedcc4c06.tar.gz
archweb-211340c8bd6ccd6b16f3115a71fce4abedcc4c06.zip
Ensure package files JS can support corner cases
We should handle the cases dealing with no filelist available, outdated filelist, or a package without files, just as the HTML server-side page does. Add a bit more info to the JSON returned so we can do so. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/views/display.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/packages/views/display.py b/packages/views/display.py
index d5aa2c20..02f5a5b2 100644
--- a/packages/views/display.py
+++ b/packages/views/display.py
@@ -160,10 +160,16 @@ def files_json(request, name, repo, arch):
pkgname=name, repo__name__iexact=repo, arch__name=arch)
# files are inserted in sorted order, so preserve that
fileslist = PackageFile.objects.filter(pkg=pkg).order_by('id')
+ dir_count = sum(1 for f in fileslist if f.is_directory)
+ files_count = len(fileslist) - dir_count
data = {
'pkgname': pkg.pkgname,
'repo': pkg.repo.name.lower(),
'arch': pkg.arch.name.lower(),
+ 'pkg_last_update': pkg.last_update,
+ 'files_last_update': pkg.files_last_update,
+ 'files_count': files_count,
+ 'dir_count': dir_count,
'files': fileslist,
}
to_json = json.dumps(data, ensure_ascii=False, cls=PackageJSONEncoder)