Commit 38930702 authored by Malcolm Tredinnick's avatar Malcolm Tredinnick
Browse files

[1.0.x] Fixed #8803 -- Allow authenticated users without first_name/last_name...

[1.0.x] Fixed #8803 -- Allow authenticated users without first_name/last_name values set to post comments.

Backport of r9118 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9125 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 4393fea6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ def post_comment(request, next=None):
    data = request.POST.copy()
    if request.user.is_authenticated():
        if not data.get('name', ''):
            data["name"] = request.user.get_full_name()
            data["name"] = request.user.get_full_name() or request.user.username
        if not data.get('email', ''):
            data["email"] = request.user.email

+19 −2
Original line number Diff line number Diff line
@@ -101,6 +101,23 @@ class CommentViewTests(CommentTestCase):
        self.assertEqual(c.user_name, u.get_full_name())
        self.assertEqual(c.user_email, u.email)

    def testPostAsAuthenticatedUserWithoutFullname(self):
        """
        Check that the user's name in the comment is populated for
        authenticated users without first_name and last_name.
        """
        user = User.objects.create_user(username='jane_other',
                email='jane@example.com', password='jane_other')
        a = Article.objects.get(pk=1)
        data = self.getValidData(a)
        data['name'] = data['email'] = ''
        self.client.login(username="jane_other", password="jane_other")
        self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
        c = Comment.objects.get(user=user)
        self.assertEqual(c.ip_address, "1.2.3.4")
        self.assertEqual(c.user_name, 'jane_other')
        user.delete()

    def testPreventDuplicateComments(self):
        """Prevent posting the exact same comment twice"""
        a = Article.objects.get(pk=1)