Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8803 -- Allow authenticated users without first_name/last_name…

… values set to post comments.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 227a93b64f582d62087ecbb19d281b9c6e5a2dcf 1 parent 16d0a61
Malcolm Tredinnick authored October 05, 2008
2  django/contrib/comments/views/comments.py
@@ -37,7 +37,7 @@ def post_comment(request, next=None):
37 37
     data = request.POST.copy()
38 38
     if request.user.is_authenticated():
39 39
         if not data.get('name', ''):
40  
-            data["name"] = request.user.get_full_name()
  40
+            data["name"] = request.user.get_full_name() or request.user.username
41 41
         if not data.get('email', ''):
42 42
             data["email"] = request.user.email
43 43
 
21  tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -85,7 +85,7 @@ def testCreateValidComment(self):
85 85
         c = Comment.objects.all()[0]
86 86
         self.assertEqual(c.ip_address, "1.2.3.4")
87 87
         self.assertEqual(c.comment, "This is my comment")
88  
-        
  88
+
89 89
     def testPostAsAuthenticatedUser(self):
90 90
         a = Article.objects.get(pk=1)
91 91
         data = self.getValidData(a)
@@ -101,6 +101,23 @@ def testPostAsAuthenticatedUser(self):
101 101
         self.assertEqual(c.user_name, u.get_full_name())
102 102
         self.assertEqual(c.user_email, u.email)
103 103
 
  104
+    def testPostAsAuthenticatedUserWithoutFullname(self):
  105
+        """
  106
+        Check that the user's name in the comment is populated for
  107
+        authenticated users without first_name and last_name.
  108
+        """
  109
+        user = User.objects.create_user(username='jane_other',
  110
+                email='jane@example.com', password='jane_other')
  111
+        a = Article.objects.get(pk=1)
  112
+        data = self.getValidData(a)
  113
+        data['name'] = data['email'] = ''
  114
+        self.client.login(username="jane_other", password="jane_other")
  115
+        self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
  116
+        c = Comment.objects.get(user=user)
  117
+        self.assertEqual(c.ip_address, "1.2.3.4")
  118
+        self.assertEqual(c.user_name, 'jane_other')
  119
+        user.delete()
  120
+
104 121
     def testPreventDuplicateComments(self):
105 122
         """Prevent posting the exact same comment twice"""
106 123
         a = Article.objects.get(pk=1)
@@ -131,7 +148,7 @@ def receive(sender, **kwargs):
131 148
         # Post a comment and check the signals
132 149
         self.testCreateValidComment()
133 150
         self.assertEqual(received_signals, excepted_signals)
134  
-        
  151
+
135 152
     def testWillBePostedSignal(self):
136 153
         """
137 154
         Test that the comment_will_be_posted signal can prevent the comment from

0 notes on commit 227a93b

Please sign in to comment.
Something went wrong with that request. Please try again.