Django

Code

Ticket #5909 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

__repr__ methods still present in contrib.comments.models, need to be replaced by __unicode__ methods

Reported by: prairiedogg Assigned to: nobody
Milestone: Component: django.contrib.comments
Version: SVN Keywords: comments, unicode
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

django trunk rev: 6658

in: django.contrib.comments.models

repr method appears five times in the comments models.py file, this causes a Unicode error when users enter names or comments with non-ascii characters. Discovered on a production site when user entered their Chinese name up the creation of a new FreeComment.

I asked on the irc #django room if this sounded like a bug. It was flagged as a bug because apparently all of the repr and str methods were supposed to be replaced with unicode methods.

Assuming that this is the case I've submitted a patch of a simple find of django.contrib.comments.models which is no more than a simple search for repr, replacing all instances with unicode.

This is my first ticket, I would like to produce a unit test for this change, but am having a little trouble. If there is someone from the community who wouldn't mind giving me a little bit of help with this, I'd really enjoy submitting more complete tickets in the future and hopefully becoming an active tester for Django.

Attachments

comments_model.diff (1.5 kB) - added by prairiedogg on 11/08/07 22:36:18.
diff file for my patch
comments_model_tests.diff (0.6 kB) - added by scompt on 11/24/07 05:01:54.
Tests for the comments_model patch

Change History

11/08/07 22:36:18 changed by prairiedogg

  • attachment comments_model.diff added.

diff file for my patch

11/24/07 05:01:54 changed by scompt

  • attachment comments_model_tests.diff added.

Tests for the comments_model patch

11/24/07 05:07:19 changed by scompt

  • needs_better_patch changed.
  • stage changed from Unreviewed to Ready for checkin.
  • needs_tests changed.
  • needs_docs changed.

The above patch adds two tests which demonstrate the new behavior with prairiedogg's patch. According to http://www.djangoproject.com/documentation/model-api/#unicode, __unicode__ seems to be the way to do things.

11/29/07 11:46:05 changed by mtredinnick

Replacing {{repr}} with {{unicode}} is often not a particularly good solution, since the former is output for developers and the latter is targeted at a different audience. In this case, it's not a bad solution, though.

11/29/07 12:15:31 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [6742]) Fixed #5909 -- Made the various django.contrib.comment models more robust in the face of non-ASCII characters by giving them a unicode method and letting the default repr use that. Patches from prairiedogg and scompt.


Add/Change #5909 (__repr__ methods still present in contrib.comments.models, need to be replaced by __unicode__ methods)




Change Properties
Action