From 768bc688aab844cf9fdf9809b9381aaf0042f2fc Mon Sep 17 00:00:00 2001
From: Dan McGee
Date: Wed, 2 May 2012 10:21:30 -0500
Subject: Flagging related cleanups and improvements
Touch up the style slightly on the flag help popup to match the main
site style more closely.
When a logged-in user is flagging a package out of date, we have no need
for them to fill in the email field since we already have an email
address on file.
Signed-off-by: Dan McGee
---
packages/views/flag.py | 34 ++++++++++++++++++++++++----------
templates/packages/flaghelp.html | 20 +++++++++-----------
2 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/packages/views/flag.py b/packages/views/flag.py
index 0d2f9009..7fa2d508 100644
--- a/packages/views/flag.py
+++ b/packages/views/flag.py
@@ -6,16 +6,13 @@
from django.shortcuts import get_object_or_404, redirect
from django.template import loader, Context
from django.views.generic.simple import direct_to_template
-from django.views.decorators.cache import never_cache
+from django.views.decorators.cache import cache_page, never_cache
from ..models import FlagRequest
from main.models import Package
from main.utils import utc_now
-def flaghelp(request):
- return direct_to_template(request, 'packages/flaghelp.html')
-
class FlagForm(forms.Form):
email = forms.EmailField(label='E-mail Address')
message = forms.CharField(label='Message To Developer',
@@ -26,6 +23,20 @@ class FlagForm(forms.Form):
widget=forms.TextInput(attrs={'style': 'display:none;'}),
required=False)
+ def __init__(self, *args, **kwargs):
+ # we remove the 'email' field if this form is being shown to a
+ # logged-in user, e.g., a developer.
+ auth = kwargs.pop('authenticated', False)
+ super(FlagForm, self).__init__(*args, **kwargs)
+ if auth:
+ del self.fields['email']
+
+
+@cache_page(3600)
+def flaghelp(request):
+ return direct_to_template(request, 'packages/flaghelp.html')
+
+
@never_cache
def flag(request, name, repo, arch):
pkg = get_object_or_404(Package,
@@ -41,8 +52,10 @@ def flag(request, name, repo, arch):
repo__staging=pkg.repo.staging).order_by(
'pkgname', 'repo__name', 'arch__name')
+ authenticated = request.user.is_authenticated()
+
if request.POST:
- form = FlagForm(request.POST)
+ form = FlagForm(request.POST, authenticated=authenticated)
if form.is_valid() and form.cleaned_data['website'] == '':
# save the package list for later use
flagged_pkgs = list(pkgs)
@@ -54,9 +67,12 @@ def flag(request, name, repo, arch):
else:
version = ''
- email = form.cleaned_data['email']
message = form.cleaned_data['message']
ip_addr = request.META.get('REMOTE_ADDR')
+ if authenticated:
+ email = request.user.email
+ else:
+ email = form.cleaned_data['email']
@transaction.commit_on_success
def perform_updates():
@@ -68,7 +84,7 @@ def perform_updates():
ip_address=ip_addr, pkgbase=pkg.pkgbase,
version=version, repo=pkg.repo,
num_packages=len(flagged_pkgs))
- if request.user.is_authenticated():
+ if authenticated:
flag_request.user = request.user
flag_request.save()
@@ -106,9 +122,7 @@ def perform_updates():
arch=arch)
else:
initial = {}
- if request.user.is_authenticated():
- initial['email'] = request.user.email
- form = FlagForm(initial=initial)
+ form = FlagForm(authenticated=authenticated)
context = {
'package': pkg,
diff --git a/templates/packages/flaghelp.html b/templates/packages/flaghelp.html
index 819a2f01..399b7e01 100644
--- a/templates/packages/flaghelp.html
+++ b/templates/packages/flaghelp.html
@@ -1,20 +1,19 @@
-
+{% load static from staticfiles %}
Flagging Packages
-
-
Flagging Packages
-
If you notice that a package is out-of-date (i.e., there is a newer
stable release available), then please notify us by
using the Flag button in the Package Details
@@ -29,8 +28,7 @@
Flagging Packages
with your additional text.
Note: Please do not use this facility if the
- package is broken! Use the bugtracker instead.
-
--
cgit v1.2.3-54-g00ecf