summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:01:52 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:01:52 -0300
commita8b2fc84ba96c83ec1addf89ac04608fbf572705 (patch)
tree6f54cbe43b8684908f2e80ba311272c06fd0fd08 /packages
parent294bf173236610fc8c308f81d8617e7e0d0e4bff (diff)
parentb0bad20756549df5edf726771c8e6869caba6244 (diff)
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts: templates/base.html
Diffstat (limited to 'packages')
-rw-r--r--packages/urls.py3
-rw-r--r--packages/utils.py2
-rw-r--r--packages/views.py69
3 files changed, 54 insertions, 20 deletions
diff --git a/packages/urls.py b/packages/urls.py
index c02a0ed7..3f0755b3 100644
--- a/packages/urls.py
+++ b/packages/urls.py
@@ -2,8 +2,9 @@ from django.conf.urls.defaults import include, patterns
package_patterns = patterns('packages.views',
(r'^$', 'details'),
+ (r'^json/$', 'details_json'),
(r'^files/$', 'files'),
- (r'^maintainer/$', 'getmaintainer'),
+ (r'^files/json/$', 'files_json'),
(r'^flag/$', 'flag'),
(r'^flag/done/$', 'flag_confirmed', {}, 'package-flag-confirmed'),
(r'^unflag/$', 'unflag'),
diff --git a/packages/utils.py b/packages/utils.py
index 29a3087f..af4675bb 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -108,7 +108,7 @@ SELECT p.id, q.id
# column A will always have a value, column B might be NULL
to_fetch.append(row[0])
# fetch all of the necessary packages
- pkgs = Package.objects.select_related('arch', 'repo').in_bulk(to_fetch)
+ pkgs = Package.objects.normal().in_bulk(to_fetch)
# now build a list of tuples containing differences
differences = []
for row in results:
diff --git a/packages/views.py b/packages/views.py
index adf6c0af..b64beb68 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -5,6 +5,7 @@ from django.contrib.auth.models import User
from django.contrib.auth.decorators import permission_required
from django.conf import settings
from django.core.mail import send_mail
+from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Q
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect
@@ -24,9 +25,30 @@ from main.models import Package, PackageFile
from main.models import Arch, Repo, Signoff
from main.utils import make_choice
from mirrors.models import MirrorUrl
-from .models import PackageRelation
+from .models import PackageRelation, PackageGroup
from .utils import get_group_info, get_differences_info, get_wrong_permissions
+class PackageJSONEncoder(DjangoJSONEncoder):
+ pkg_attributes = [ 'pkgname', 'pkgbase', 'repo', 'arch', 'pkgver',
+ 'pkgrel', 'epoch', 'pkgdesc', 'url', 'filename', 'compressed_size',
+ 'installed_size', 'build_date', 'last_update', 'flag_date' ]
+
+ def default(self, obj):
+ if hasattr(obj, '__iter__'):
+ # mainly for queryset serialization
+ return list(obj)
+ if isinstance(obj, Package):
+ data = dict((attr, getattr(obj, attr))
+ for attr in self.pkg_attributes)
+ data['groups'] = obj.groups.all()
+ return data
+ if isinstance(obj, PackageFile):
+ filename = obj.filename or ''
+ return obj.directory + filename
+ if isinstance(obj, (Repo, Arch, PackageGroup)):
+ return obj.name.lower()
+ return super(PackageJSONEncoder, self).default(obj)
+
def opensearch(request):
if request.is_secure():
domain = "https://%s" % request.META['HTTP_HOST']
@@ -95,9 +117,8 @@ def details(request, name='', repo='', arch=''):
arches = [ arch ]
arches.extend(Arch.objects.filter(agnostic=True))
repo = get_object_or_404(Repo, name__iexact=repo)
- pkgs = Package.objects.filter(pkgbase=name,
- repo__testing=repo.testing, arch__in=arches)
- pkgs = pkgs.select_related('arch', 'repo').order_by('pkgname')
+ pkgs = Package.objects.normal().filter(pkgbase=name,
+ repo__testing=repo.testing, arch__in=arches).order_by('pkgname')
if len(pkgs) == 0:
raise Http404
context = {
@@ -134,8 +155,8 @@ def group_details(request, arch, name):
arch = get_object_or_404(Arch, name=arch)
arches = [ arch ]
arches.extend(Arch.objects.filter(agnostic=True))
- pkgs = Package.objects.filter(groups__name=name, arch__in=arches)
- pkgs = pkgs.select_related('arch', 'repo').order_by('pkgname')
+ pkgs = Package.objects.normal().filter(
+ groups__name=name, arch__in=arches).order_by('pkgname')
if len(pkgs) == 0:
raise Http404
context = {
@@ -146,15 +167,6 @@ def group_details(request, arch, name):
}
return direct_to_template(request, 'packages/packages_list.html', context)
-def getmaintainer(request, name, repo, arch):
- "Returns the maintainers as plaintext."
-
- pkg = get_object_or_404(Package,
- pkgname=name, repo__name__iexact=repo, arch__name=arch)
- names = [m.username for m in pkg.maintainers]
-
- return HttpResponse(str('\n'.join(names)), mimetype='text/plain')
-
def coerce_limit_value(value):
if not value:
return None
@@ -204,7 +216,7 @@ class PackageSearchForm(forms.Form):
def search(request, page=None):
limit = 50
- packages = Package.objects.select_related('arch', 'repo')
+ packages = Package.objects.normal()
if request.GET:
form = PackageSearchForm(data=request.GET)
@@ -287,6 +299,27 @@ def files(request, name, repo, arch):
return direct_to_template(request, template,
{'pkg':pkg, 'files':fileslist})
+def details_json(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ to_json = simplejson.dumps(pkg, ensure_ascii=False,
+ cls=PackageJSONEncoder)
+ return HttpResponse(to_json, mimetype='application/json')
+
+def files_json(request, name, repo, arch):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename')
+ data = {
+ 'pkgname': pkg.pkgname,
+ 'repo': pkg.repo.name.lower(),
+ 'arch': pkg.arch.name.lower(),
+ 'files': fileslist,
+ }
+ to_json = simplejson.dumps(data, ensure_ascii=False,
+ cls=PackageJSONEncoder)
+ return HttpResponse(to_json, mimetype='application/json')
+
@permission_required('main.change_package')
def unflag(request, name, repo, arch):
pkg = get_object_or_404(Package,
@@ -371,7 +404,7 @@ def flag(request, name, repo, arch):
# already flagged. do nothing.
return direct_to_template(request, 'packages/flagged.html', {'pkg': pkg})
# find all packages from (hopefully) the same PKGBUILD
- pkgs = Package.objects.select_related('arch', 'repo').filter(
+ pkgs = Package.objects.normal().filter(
pkgbase=pkg.pkgbase, flag_date__isnull=True,
repo__testing=pkg.repo.testing).order_by(
'pkgname', 'repo__name', 'arch__name')
@@ -426,7 +459,7 @@ def flag(request, name, repo, arch):
def flag_confirmed(request, name, repo, arch):
pkg = get_object_or_404(Package,
pkgname=name, repo__name__iexact=repo, arch__name=arch)
- pkgs = Package.objects.select_related('arch', 'repo').filter(
+ pkgs = Package.objects.normal().filter(
pkgbase=pkg.pkgbase, flag_date=pkg.flag_date,
repo__testing=pkg.repo.testing).order_by(
'pkgname', 'repo__name', 'arch__name')