summaryrefslogtreecommitdiff
path: root/packages/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/views.py')
-rw-r--r--packages/views.py64
1 files changed, 46 insertions, 18 deletions
diff --git a/packages/views.py b/packages/views.py
index 73594507..adf6c0af 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -18,6 +18,7 @@ from django.views.generic.simple import direct_to_template
from datetime import datetime
import string
+from urllib import urlencode
from main.models import Package, PackageFile
from main.models import Arch, Repo, Signoff
@@ -84,7 +85,8 @@ def update(request):
def details(request, name='', repo='', arch=''):
if all([name, repo, arch]):
try:
- pkg = Package.objects.get(pkgname=name,
+ pkg = Package.objects.select_related(
+ 'arch', 'repo', 'packager').get(pkgname=name,
repo__name__iexact=repo, arch__name=arch)
return direct_to_template(request, 'packages/details.html',
{'pkg': pkg, })
@@ -107,8 +109,14 @@ def details(request, name='', repo='', arch=''):
return direct_to_template(request, 'packages/packages_list.html',
context)
else:
- return redirect("/packages/?arch=%s&repo=%s&q=%s" % (
- arch.lower(), repo.title(), name))
+ pkg_data = [
+ ('arch', arch.lower()),
+ ('repo', repo.lower()),
+ ('q', name),
+ ]
+ # only include non-blank values in the query we generate
+ pkg_data = [(x, y) for x, y in pkg_data if y]
+ return redirect("/packages/?%s" % urlencode(pkg_data))
def groups(request, arch=None):
arches = []
@@ -163,7 +171,7 @@ class LimitTypedChoiceField(forms.TypedChoiceField):
try:
coerce_limit_value(value)
return True
- except ValueError, TypeError:
+ except (ValueError, TypeError):
return False
class PackageSearchForm(forms.Form):
@@ -218,7 +226,7 @@ def search(request, page=None):
packages = packages.filter(pkgbase__in=inner_q)
if form.cleaned_data['flagged'] == 'Flagged':
- packages=packages.filter(flag_date__isnull=False)
+ packages = packages.filter(flag_date__isnull=False)
elif form.cleaned_data['flagged'] == 'Not Flagged':
packages = packages.filter(flag_date__isnull=True)
@@ -359,18 +367,21 @@ class FlagForm(forms.Form):
def flag(request, name, repo, arch):
pkg = get_object_or_404(Package,
pkgname=name, repo__name__iexact=repo, arch__name=arch)
- context = {'pkg': pkg}
if pkg.flag_date is not None:
# already flagged. do nothing.
- return direct_to_template(request, 'packages/flagged.html', context)
+ 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(
+ pkgbase=pkg.pkgbase, flag_date__isnull=True,
+ repo__testing=pkg.repo.testing).order_by(
+ 'pkgname', 'repo__name', 'arch__name')
if request.POST:
form = FlagForm(request.POST)
if form.is_valid() and form.cleaned_data['website'] == '':
- # find all packages from (hopefully) the same PKGBUILD
- pkgs = Package.objects.filter(
- pkgbase=pkg.pkgbase, repo__testing=pkg.repo.testing)
- pkgs.update(flag_date=datetime.now())
+ # save the package list for later use
+ flagged_pkgs = list(pkgs)
+ pkgs.update(flag_date=datetime.utcnow())
maints = pkg.maintainers
if not maints:
@@ -386,13 +397,13 @@ def flag(request, name, repo, arch):
toemail.append(maint.email)
if toemail:
- # send notification email to the maintainer
+ # send notification email to the maintainers
t = loader.get_template('packages/outofdate.txt')
c = Context({
'email': form.cleaned_data['email'],
'message': form.cleaned_data['usermessage'],
'pkg': pkg,
- 'weburl': pkg.get_full_url(),
+ 'packages': flagged_pkgs,
})
send_mail(subject,
t.render(c),
@@ -400,14 +411,30 @@ def flag(request, name, repo, arch):
toemail,
fail_silently=True)
- context['confirmed'] = True
+ return redirect('package-flag-confirmed', name=name, repo=repo,
+ arch=arch)
else:
form = FlagForm()
- context['form'] = form
-
+ context = {
+ 'package': pkg,
+ 'packages': pkgs,
+ 'form': form
+ }
return direct_to_template(request, 'packages/flag.html', context)
+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(
+ pkgbase=pkg.pkgbase, flag_date=pkg.flag_date,
+ repo__testing=pkg.repo.testing).order_by(
+ 'pkgname', 'repo__name', 'arch__name')
+
+ context = {'package': pkg, 'packages': pkgs}
+
+ return direct_to_template(request, 'packages/flag_confirmed.html', context)
+
def download(request, name, repo, arch):
pkg = get_object_or_404(Package,
pkgname=name, repo__name__iexact=repo, arch__name=arch)
@@ -418,13 +445,13 @@ def download(request, name, repo, arch):
if pkg.arch.agnostic:
# grab the first non-any arch to fake the download path
arch = Arch.objects.exclude(agnostic=True)[0].name
- details = {
+ values = {
'host': mirrorurl.url,
'arch': arch,
'repo': pkg.repo.name.lower(),
'file': pkg.filename,
}
- url = string.Template('${host}${repo}/os/${arch}/${file}').substitute(details)
+ url = string.Template('${host}${repo}/os/${arch}/${file}').substitute(values)
return redirect(url)
def arch_differences(request):
@@ -440,6 +467,7 @@ def arch_differences(request):
return direct_to_template(request, 'packages/differences.html', context)
@permission_required('main.change_package')
+@never_cache
def stale_relations(request):
relations = PackageRelation.objects.select_related('user')
pkgbases = Package.objects.all().values('pkgbase')