From b2b5c1a064d5d3c33f4c4fc119bd67cf9ca1b7ba Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 10 Jan 2012 23:31:11 -0600 Subject: Add old version string to saved flag requests 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 --- packages/views/flag.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'packages/views') 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.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, }) -- cgit v1.2.3-54-g00ecf