[extensions-web] Require a logged in user to add a comment



commit 0fd265f7ae3f597908faddfc577366c151eaed8f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Oct 31 17:05:25 2011 -0400

    Require a logged in user to add a comment

 .../extensions/templates/extensions/comments.html  |    6 ++++++
 sweettooth/ratings/admin.py                        |    2 +-
 sweettooth/ratings/forms.py                        |    8 ++++----
 sweettooth/ratings/models.py                       |    6 ++++++
 sweettooth/static/css/sweettooth.css               |    2 +-
 5 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/sweettooth/extensions/templates/extensions/comments.html b/sweettooth/extensions/templates/extensions/comments.html
index 2003aa2..618eaf3 100644
--- a/sweettooth/extensions/templates/extensions/comments.html
+++ b/sweettooth/extensions/templates/extensions/comments.html
@@ -24,6 +24,7 @@
 <div id="new-comment-form">
   <div>
     <h4>Your opinion</h4>
+    {% if request.user.is_authenticated %}
     <div class="report rating">
       <span class="txt">It worked, and...</span>
       {% render_comment_form for extension %}
@@ -36,5 +37,10 @@
         helps extension authors be known about bugs in their extension!
       </p>
     </div>
+    {% else %}
+    <p class="unauthenticated">
+      Unfortunately, to help prevent spam, we require that you <a href="{% url auth-login %}">log in to GNOME Shell Extensions</a> in order to post a comment or report an error. You understand, right?
+    </p>
+    {% endif %}
   </div>
 </div>
diff --git a/sweettooth/ratings/admin.py b/sweettooth/ratings/admin.py
index f42255a..44baca8 100644
--- a/sweettooth/ratings/admin.py
+++ b/sweettooth/ratings/admin.py
@@ -11,7 +11,7 @@ class RatingCommentsAdmin(CommentsAdmin):
            {'fields': ('content_type', 'object_pk', 'site')}
         ),
         (_('Content'),
-           {'fields': ('user', 'user_name', 'user_email', 'rating', 'comment')}
+           {'fields': ('user', 'rating', 'comment')}
         ),
         (_('Metadata'),
            {'fields': ('submit_date', 'ip_address', 'is_public', 'is_removed')}
diff --git a/sweettooth/ratings/forms.py b/sweettooth/ratings/forms.py
index 937abf8..000884d 100644
--- a/sweettooth/ratings/forms.py
+++ b/sweettooth/ratings/forms.py
@@ -10,7 +10,7 @@ from django.utils.safestring import mark_safe
 
 from ratings.models import RatingComment
 
-CHOICES = zip(range(5), (str(r) for r in range(1, 6)))
+CHOICES = [(i, str(i+1)) for i in range(5)]
 
 class NoLabelRadioInput(widgets.RadioInput):
     """
@@ -57,8 +57,6 @@ class RatingCommentForm(CommentForm):
         return dict(
             content_type = ContentType.objects.get_for_model(self.target_object),
             object_pk    = force_unicode(self.target_object._get_pk_val()),
-            user_name    = self.cleaned_data["name"],
-            user_email   = self.cleaned_data["email"],
             comment      = self.cleaned_data["comment"],
             rating       = self.cleaned_data["rating"],
             submit_date  = datetime.datetime.now(),
@@ -67,5 +65,7 @@ class RatingCommentForm(CommentForm):
             is_removed   = False,
         )
 
-# Remove the URL field, we don't want it.
+# Remove the URL, name and email fields. We don't want them.
 RatingCommentForm.base_fields.pop('url')
+RatingCommentForm.base_fields.pop('name')
+RatingCommentForm.base_fields.pop('email')
diff --git a/sweettooth/ratings/models.py b/sweettooth/ratings/models.py
index 31316de..964cf36 100644
--- a/sweettooth/ratings/models.py
+++ b/sweettooth/ratings/models.py
@@ -1,6 +1,12 @@
 
 from django.db import models
 from django.contrib.comments.models import Comment
+from django.contrib.comments.signals import comment_will_be_posted
 
 class RatingComment(Comment):
     rating = models.PositiveIntegerField()
+
+def make_sure_user_was_authenticated(sender, comment, request, **kwargs):
+    return request.user.is_authenticated()
+
+comment_will_be_posted.connect(make_sure_user_was_authenticated)
diff --git a/sweettooth/static/css/sweettooth.css b/sweettooth/static/css/sweettooth.css
index b48f60c..302ad74 100644
--- a/sweettooth/static/css/sweettooth.css
+++ b/sweettooth/static/css/sweettooth.css
@@ -337,7 +337,7 @@ li.extension:last-child {
     line-height: 1.7em;
 }
 
-.extension .report.error {
+.extension .report.error, .extension .unauthenticated {
     background: #EEEEEC;
     border: 1px solid #BABDB6;
     border-radius: 8px;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]