summaryrefslogtreecommitdiff
path: root/packages/views
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-14 22:44:27 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-14 22:44:27 -0500
commit64f6dd9cb41ddbc84376549f558ed7d52d9e600a (patch)
tree81f31f1ceb5fc6e4d94508d273003996e036191c /packages/views
parentbc432a1ff0e69bf45c5f3b97077a13952611196d (diff)
parentb2b5c1a064d5d3c33f4c4fc119bd67cf9ca1b7ba (diff)
Merge tag 'release_2012-01-11'
Pkgbase view in todos, other changes related to caching Conflicts: public/views.py
Diffstat (limited to 'packages/views')
-rw-r--r--packages/views/__init__.py8
-rw-r--r--packages/views/flag.py41
-rw-r--r--packages/views/signoff.py2
3 files changed, 33 insertions, 18 deletions
diff --git a/packages/views/__init__.py b/packages/views/__init__.py
index 573e0c72..e66da179 100644
--- a/packages/views/__init__.py
+++ b/packages/views/__init__.py
@@ -1,10 +1,10 @@
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
+from django.contrib.auth.models import User
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect
from django.utils import simplejson
-from django.views.decorators.cache import never_cache
from django.views.decorators.http import require_POST
from django.views.decorators.vary import vary_on_headers
from django.views.generic.simple import direct_to_template
@@ -27,7 +27,8 @@ from .signoff import signoffs, signoff_package, signoff_options, signoffs_json
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' ]
+ 'installed_size', 'build_date', 'last_update', 'flag_date',
+ 'maintainers', 'packager' ]
def default(self, obj):
if hasattr(obj, '__iter__'):
@@ -43,6 +44,8 @@ class PackageJSONEncoder(DjangoJSONEncoder):
return obj.directory + filename
if isinstance(obj, (Repo, Arch, PackageGroup)):
return obj.name.lower()
+ elif isinstance(obj, User):
+ return obj.username
return super(PackageJSONEncoder, self).default(obj)
def opensearch(request):
@@ -244,7 +247,6 @@ 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')
diff --git a/packages/views/flag.py b/packages/views/flag.py
index 2f5c9933..f74a718a 100644
--- a/packages/views/flag.py
+++ b/packages/views/flag.py
@@ -4,6 +4,7 @@ from django import forms
from django.conf import settings
from django.contrib.auth.decorators import permission_required
from django.core.mail import send_mail
+from django.db import transaction
from django.shortcuts import get_object_or_404, redirect
from django.template import loader, Context
from django.views.generic.simple import direct_to_template
@@ -46,17 +47,31 @@ def flag(request, name, repo, arch):
if form.is_valid() and form.cleaned_data['website'] == '':
# save the package list for later use
flagged_pkgs = list(pkgs)
- pkgs.update(flag_date=datetime.utcnow())
-
- # store our flag request
- flag_request = FlagRequest(user_email=form.cleaned_data['email'],
- ip_address=request.META.get('REMOTE_ADDR', '127.0.0.1'),
- pkgbase=pkg.pkgbase, repo=pkg.repo,
- num_packages=len(flagged_pkgs),
- message=form.cleaned_data['message'])
- if request.user.is_authenticated():
- flag_request.user = request.user
- flag_request.save()
+
+ # find a common version if there is one available to store
+ versions = set(pkg.full_version for pkg in flagged_pkgs)
+ if len(versions) == 1:
+ version = versions.pop()
+ else:
+ version = ''
+
+ email = form.cleaned_data['email']
+ message = form.cleaned_data['message']
+ ip_addr = request.META.get('REMOTE_ADDR')
+
+ @transaction.commit_on_success
+ def perform_updates():
+ pkgs.update(flag_date=datetime.utcnow())
+ # store our flag request
+ flag_request = FlagRequest(user_email=email, message=message,
+ ip_address=ip_addr, pkgbase=pkg.pkgbase,
+ version=version, repo=pkg.repo,
+ num_packages=len(flagged_pkgs))
+ if request.user.is_authenticated():
+ flag_request.user = request.user
+ flag_request.save()
+
+ perform_updates()
maints = pkg.maintainers
if not maints:
@@ -75,8 +90,8 @@ def flag(request, name, repo, arch):
# send notification email to the maintainers
tmpl = loader.get_template('packages/outofdate.txt')
ctx = Context({
- 'email': form.cleaned_data['email'],
- 'message': form.cleaned_data['message'],
+ 'email': email,
+ 'message': message,
'pkg': pkg,
'packages': flagged_pkgs,
})
diff --git a/packages/views/signoff.py b/packages/views/signoff.py
index e57b4d9a..e3daf0dd 100644
--- a/packages/views/signoff.py
+++ b/packages/views/signoff.py
@@ -18,7 +18,6 @@ from ..utils import (get_signoff_groups, approved_by_signoffs,
PackageSignoffGroup)
@permission_required('main.change_package')
-@never_cache
def signoffs(request):
signoff_groups = sorted(get_signoff_groups(), key=attrgetter('pkgbase'))
for group in signoff_groups:
@@ -178,7 +177,6 @@ class SignoffJSONEncoder(DjangoJSONEncoder):
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 = {