summaryrefslogtreecommitdiff
path: root/packages/views/flag.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-01-10 23:31:11 -0600
committerDan McGee <dan@archlinux.org>2012-01-10 23:31:11 -0600
commitb2b5c1a064d5d3c33f4c4fc119bd67cf9ca1b7ba (patch)
treea38535e9024270ea46439cddec81d91d2a7f4803 /packages/views/flag.py
parent6b16b9487a95118a6109a2c5119d430dc1192e80 (diff)
Add old version string to saved flag requestsrelease_2012-01-11
This makes it easier to match up a flag request with the package state at the time of flagging, and might also help to determine if flagging actions were legit. We only store it if it is the same across all packages to be marked. Also, move the various database write activities when flagging packages into a single transaction. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/views/flag.py')
-rw-r--r--packages/views/flag.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/packages/views/flag.py b/packages/views/flag.py
index 4132f9a7..4ee37f6f 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,
})