[extensions-web/filter-sort-ui: 6/20] Move from "ratings" to "discussions"



commit 9df9939124c5b182300a24c25635542e0d3cc8db
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Dec 23 17:53:46 2011 -0500

    Move from "ratings" to "discussions"
    
    See http://youtube-global.blogspot.com/2009/09/five-stars-dominate-ratings.html
    for some discussion of the same problem, talking about YouTube.
    
    Star ratings as a guideline aren't quite useful. The ratings feature was being
    used as a discussion board on the extension's page, rather than a critique of
    an extension. To solve this, follow the YouTube strategy, following a binary
    like/dislike system. The implementation of this system will come later, so
    I'm not gutting the ratings code -- the data migration for it still needs to
    exist.

 sweettooth/discussions/__init__.py                 |    9 +++++++
 sweettooth/discussions/forms.py                    |   24 ++++++++++++++++++++
 sweettooth/discussions/models.py                   |    7 +++++
 sweettooth/discussions/urls.py                     |    7 +++++
 sweettooth/discussions/views.py                    |   10 ++++++++
 .../extensions/templates/extensions/comments.html  |    5 +---
 sweettooth/settings.py                             |    7 +++--
 sweettooth/urls.py                                 |    2 +-
 8 files changed, 63 insertions(+), 8 deletions(-)
---
diff --git a/sweettooth/discussions/__init__.py b/sweettooth/discussions/__init__.py
new file mode 100644
index 0000000..2fe166e
--- /dev/null
+++ b/sweettooth/discussions/__init__.py
@@ -0,0 +1,9 @@
+
+from django.contrib.comments.models import Comment
+from discussions import forms
+
+def get_model():
+    return Comment
+
+def get_form():
+    return forms.DiscussionCommentForm
diff --git a/sweettooth/discussions/forms.py b/sweettooth/discussions/forms.py
new file mode 100644
index 0000000..79e2b94
--- /dev/null
+++ b/sweettooth/discussions/forms.py
@@ -0,0 +1,24 @@
+
+import datetime
+
+from django.conf import settings
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.comments.forms import CommentForm
+from django.utils.encoding import force_unicode
+
+class DiscussionCommentForm(CommentForm):
+    def get_comment_create_data(self):
+        return dict(
+            content_type = ContentType.objects.get_for_model(self.target_object),
+            object_pk    = force_unicode(self.target_object._get_pk_val()),
+            comment      = self.cleaned_data["comment"],
+            submit_date  = datetime.datetime.now(),
+            site_id      = settings.SITE_ID,
+            is_public    = True,
+            is_removed   = False,
+        )
+
+# Remove the URL, name and email fields. We don't want them.
+DiscussionCommentForm.base_fields.pop('url')
+DiscussionCommentForm.base_fields.pop('name')
+DiscussionCommentForm.base_fields.pop('email')
diff --git a/sweettooth/discussions/models.py b/sweettooth/discussions/models.py
new file mode 100644
index 0000000..5f53069
--- /dev/null
+++ b/sweettooth/discussions/models.py
@@ -0,0 +1,7 @@
+
+from django.contrib.comments.signals import comment_will_be_posted
+
+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/discussions/urls.py b/sweettooth/discussions/urls.py
new file mode 100644
index 0000000..2b813d5
--- /dev/null
+++ b/sweettooth/discussions/urls.py
@@ -0,0 +1,7 @@
+
+from django.conf.urls.defaults import patterns, include, url
+from discussions import views
+
+urlpatterns = patterns('',
+    url(r'^posted/$', views.comment_done, name='comments-comment-done'),
+)
diff --git a/sweettooth/discussions/views.py b/sweettooth/discussions/views.py
new file mode 100644
index 0000000..2a910dc
--- /dev/null
+++ b/sweettooth/discussions/views.py
@@ -0,0 +1,10 @@
+
+from django.contrib import comments
+from django.contrib.messages import info
+from django.shortcuts import redirect
+
+def comment_done(request):
+    pk = request.GET['c']
+    comment = comments.get_model().objects.get(pk=pk)
+    info(request, "Thank you for your comment")
+    return redirect(comment.get_content_object_url())
diff --git a/sweettooth/extensions/templates/extensions/comments.html b/sweettooth/extensions/templates/extensions/comments.html
index af82994..96a9d70 100644
--- a/sweettooth/extensions/templates/extensions/comments.html
+++ b/sweettooth/extensions/templates/extensions/comments.html
@@ -2,7 +2,6 @@
   <h4>User comments</h4>
   {% load comments %}
   {% load gravatar %}
-  {% load rating %}
   {% get_comment_list for extension as comments %}
   {% for comment in comments %}
   {% if comment.user == extension.creator %}
@@ -13,9 +12,7 @@
   {% endif %}
     <img src="{% gravatar_url comment.email %}" class="gravatar">
     <div class="rating-author">
-      <div class="rating">
-        {% rating comment.rating 5 %}
-      </div> by
+      Comment by
       <a class="comment-author" href="{% url auth-profile user=comment.user.username %}">{{ comment.user }}</a>
     </div>
     <p>{{ comment.comment }}</p>
diff --git a/sweettooth/settings.py b/sweettooth/settings.py
index 084e164..6b57388 100644
--- a/sweettooth/settings.py
+++ b/sweettooth/settings.py
@@ -116,12 +116,12 @@ LOGIN_URL = '/accounts/login/'
 INSTALLED_APPS = (
     'django.contrib.auth',
 
-    'registration',
-
     # 'ratings' goes before django's comments
     # app so it will find our templates
     'ratings',
 
+    'registration',
+
     'django.contrib.comments',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
@@ -134,6 +134,7 @@ INSTALLED_APPS = (
     'auth',
     'review',
     'errorreports',
+    'discussions',
 
     # Uncomment the next line to enable the admin:
     'django.contrib.admin',
@@ -143,7 +144,7 @@ INSTALLED_APPS = (
     'south',
 )
 
-COMMENTS_APP = 'ratings'
+COMMENTS_APP = 'discussions'
 
 # A sample logging configuration. The only tangible logging
 # performed by this configuration is to send an email to
diff --git a/sweettooth/urls.py b/sweettooth/urls.py
index 9825226..4be98f9 100644
--- a/sweettooth/urls.py
+++ b/sweettooth/urls.py
@@ -17,7 +17,7 @@ urlpatterns = patterns('',
     url(r'^errors/', include('errorreports.urls')),
 
     url(r'^admin/', include(admin.site.urls)),
-    url(r'^comments/', include('ratings.urls')),
+    url(r'^comments/', include('discussions.urls')),
     url(r'^comments/', include('django.contrib.comments.urls')),
 
 )



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