summaryrefslogtreecommitdiff
path: root/packages/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/views.py')
-rw-r--r--packages/views.py96
1 files changed, 26 insertions, 70 deletions
diff --git a/packages/views.py b/packages/views.py
index df0359d2..2a77be53 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -3,11 +3,11 @@ from django.shortcuts import get_object_or_404
from django.core.mail import send_mail
from django.template import Context, loader
from django.core import validators
-from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
-from archweb_dev.lib.utils import validate, render_response
from datetime import datetime
-from archweb_dev.packages.models import Package, PackageFile, Repo, Category
+from archweb_dev.main.utils import validate, render_response
+from archweb_dev.main.models import Package, PackageFile, PackageDepend
+from archweb_dev.main.models import Arch, Repo
from django.core.exceptions import ObjectDoesNotExist
@@ -37,7 +37,7 @@ def update(request):
def details(request, pkgid=0, name='', repo=''):
if pkgid == 0:
p = Package.objects.filter(pkgname=name)
- if repo: p = p.filter(repo__name__exact=repo)
+ if repo: p = p.filter(repo__name__iexact=repo)
# if more then one result, send to the search view
if len(p) > 1: return search(request, name)
if len(p) < 1: return render_response(request, 'error_page.html',
@@ -45,18 +45,7 @@ def details(request, pkgid=0, name='', repo=''):
pkgid = p[0].id
pkg = get_object_or_404(Package, id=pkgid)
- origin_repo = None
- if pkg.repo.name == 'Testing':
- try:
- origin_repo = Package.objects.filter(
- pkgname__exact = pkg.pkgname).exclude(
- repo__name__exact = pkg.repo.name).get().repo.name
- except ObjectDoesNotExist:
- origin_repo = None
- return render_response(
- request,
- 'packages/details.html',
- {'pkg': pkg, 'origin_repo': origin_repo})
+ return render_response(request, 'packages/details.html', {'pkg': pkg})
def search(request, query=''):
if request.GET.has_key('q'):
@@ -65,19 +54,20 @@ def search(request, query=''):
# fetch the form vars
repo = request.GET.get('repo', 'all')
- category = request.GET.get('category', 'all')
+ arch = request.GET.get('arch', 'all')
lastupdate = request.GET.get('lastupdate', '')
limit = int(request.GET.get('limit', '50'))
skip = int(request.GET.get('skip', '0'))
sort = request.GET.get('sort', '')
maint = request.GET.get('maint', 'all')
+ flagged_only = request.GET.get('flagged_only', 'n')
# build the form lists
- repos = Repo.objects.order_by('name')
- cats = Category.objects.order_by('category')
+ repos = Repo.objects.all()
+ arches = Arch.objects.all()
# copy GET data over and add the lists
c = request.GET.copy()
- c['repos'], c['categories'] = repos, cats
+ c['repos'], c['arches'] = repos, arches
c['limit'], c['skip'] = limit, skip
c['lastupdate'] = lastupdate
c['sort'] = sort
@@ -99,19 +89,27 @@ def search(request, query=''):
results = res1 | res2
else:
results = Package.objects.all()
- if repo != 'all': results = results.filter(repo__name__exact=repo)
- if category != 'all': results = results.filter(category__category__exact=category)
- if maint != 'all': results = results.filter(maintainer=maint)
- if lastupdate: results = results.filter(last_update__gte=datetime(int(lastupdate[0:4]),int(lastupdate[5:7]),int(lastupdate[8:10])))
- # select_related() shouldn't be needed -- we're working around a Django bug
- #results = results.select_related().order_by('repos.name', 'category', 'pkgname')
+ if repo != 'all' and repo in [x.name for x in repos]:
+ results = results.filter(repo__name__iexact=repo)
+ if arch != 'all' and arch in [x.name for x in arches]:
+ results = results.filter(arch__name__iexact=arch)
+ if maint != 'all':
+ results = results.filter(maintainer=maint)
+ if flagged_only != 'n':
+ results = results.filter(needupdate=1)
+ if lastupdate:
+ results = results.filter(
+ last_update__gte=datetime(
+ int(lastupdate[0:4]),
+ int(lastupdate[5:7]),
+ int(lastupdate[8:10])))
# sort results
if sort == '':
- results = results.order_by('repo', 'category', 'pkgname')
+ results = results.order_by('repo', 'arch', '-last_update', 'pkgname')
else:
# duplicate sort fields shouldn't hurt anything
- results = results.order_by(sort, 'repo', 'category', 'pkgname')
+ results = results.order_by(sort, 'repo', 'arch', 'pkgname')
qs = request.GET.copy()
# build pagination urls
@@ -137,50 +135,8 @@ def files(request, pkgid):
files = PackageFile.objects.filter(pkg=pkgid)
return render_response(request, 'packages/files.html', {'pkg':pkg,'files':files})
-def flaghelp(request):
- return render_response(request, 'packages/flaghelp.html')
-
-def flag(request, pkgid):
- pkg = get_object_or_404(Package, id=pkgid)
- context = {'pkg': pkg}
- if request.POST.has_key('confirmemail'):
- email = request.POST['confirmemail']
- if request.POST.has_key('usermessage'):
- message = request.POST['usermessage']
- else:
- message = None
- # validate
- errors = {}
- validate(errors, 'Email Address', email, validators.isValidEmail, False, request)
- if errors:
- context['errors'] = errors
- return render_response(request, 'packages/flag.html', context)
-
- context['confirmemail'] = email
- pkg.needupdate = 1
- pkg.save()
- if pkg.maintainer_id > 0:
- # send notification email to the maintainer
- t = loader.get_template('packages/outofdate.txt')
- c = Context({
- 'email': request.POST['confirmemail'],
- 'message': message,
- 'pkgname': pkg.pkgname,
- 'weburl': 'http://www.archlinux.org/packages/' + str(pkg.id) + '/'
- })
- send_mail('arch: Package [%s] marked out-of-date' % pkg.pkgname,
- t.render(c),
- 'Arch Website Notification <nobody@archlinux.org>',
- [pkg.maintainer.email],
- fail_silently=True)
- return render_response(request, 'packages/flag.html', context)
-
-@login_required
def unflag(request, pkgid):
pkg = get_object_or_404(Package, id=pkgid)
- if pkg.maintainer_id == 0 or \
- pkg.maintainer.username != request.user.username:
- return render_response(request, 'error_page.html', {'errmsg': 'You do not own this package.'})
pkg.needupdate = 0
pkg.save()
return HttpResponseRedirect('/packages/%d/' % (pkg.id))