Django

Code

Ticket #8630 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

Improve the comments framework customizability

Reported by: thejaswi_puthraya Assigned to: carljm
Milestone: Component: django.contrib.comments
Version: SVN Keywords: comments, customization
Cc: dane.springmeyer@gmail.com, steingrd@ifi.uio.no, david, halfdan@halfdans.net Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Currently the comments framework allows to customize comments by requiring the three attributes get_model(), get_form() and get_form_target() in the custom comments app. But by hard-coding the get_model(), get_form() and get_form_target() in django.contrib.comments.__int__.py we are restricting the extensibility.

The patch attached allows easy customization. This is *NOT* a new feature, just hard-coded it by mistake while sending patches to Jacob.

Attachments

8630.diff (1.2 kB) - added by thejaswi_puthraya on 08/27/08 22:56:42.
git-patch against the latest trunk checkout
8630_r8782_alternative.diff (1.7 kB) - added by carljm on 08/31/08 21:02:27.
A patch to use get_comment_app in templatetags, so customization can work (but I actually think Thejaswi's patch is a better approach)
8630_r8782_svn.diff (1.2 kB) - added by carljm on 08/31/08 21:03:42.
Thejaswi's original patch, in svn diff style
8630_r8782_admin.diff (1.9 kB) - added by carljm on 09/01/08 00:08:56.
admin.py needs to not register the Comment model if it's been replaced with a custom model
__init__.py.patch (1.9 kB) - added by amir on 09/05/08 09:02:00.
Also removed the checks in get_comment_app() so it's possible to override only part of the functions and use the default for the rest.
8630_r9084.diff (12.2 kB) - added by carljm on 09/24/08 00:06:41.
consolidated patch
8630_r9084.2.diff (12.2 kB) - added by carljm on 09/24/08 00:07:04.
consolidated patch, with docs
8630_r9084_with_tests.diff (15.8 kB) - added by carljm on 09/24/08 01:23:04.
consolidated patch with docs and tests
8630_new.diff (17.3 kB) - added by thejaswi_puthraya on 01/18/09 10:26:21.
git-patch that has tests, docs and the patch. Slight change from Carljm's patch.
8630_r9776.diff (7.3 kB) - added by carljm on 01/19/09 12:16:45.
updated patch with minor typo fixes
8630_r9781.diff (17.2 kB) - added by carljm on 01/22/09 21:26:40.
this time with all the files included :-)

Change History

08/27/08 22:56:42 changed by thejaswi_puthraya

  • attachment 8630.diff added.

git-patch against the latest trunk checkout

(follow-up: ↓ 2 ) 08/27/08 23:06:31 changed by mtredinnick

  • needs_better_patch changed.
  • needs_docs changed.
  • needs_tests changed.
  • milestone deleted.

Yes, it is a feature. The comments work fine without this patch, so it's not a bug fix. It's adding new functionality.

(in reply to: ↑ 1 ) 08/27/08 23:31:05 changed by thejaswi_puthraya

Replying to mtredinnick:

Yes, it is a feature. The comments work fine without this patch, so it's not a bug fix. It's adding new functionality.

But we have no way to customize comments without the patch :(

08/28/08 10:51:04 changed by jacob

You're not understanding how those methods are intended to be called: an app that wants to provide custom comments provides its own app; you'd call, for example, get_comments_app().get_form() -- this would return COMMENTS_APP.get_form().

Either way, though, COMMENTS_APP is a hook designed for the future; the goal of comments in 1.0 is to *work*. Extensibility comes next.

08/31/08 17:04:56 changed by carljm

  • cc set to carl@dirtcircle.com.

In that case, the template tags in django.contrib.comments need fixing to use get_comments_app(). Currently the template tags are hardcoded to call comments.get_form() etc, which means there is no usable customization hook in contrib.comments.

08/31/08 21:02:27 changed by carljm

  • attachment 8630_r8782_alternative.diff added.

A patch to use get_comment_app in templatetags, so customization can work (but I actually think Thejaswi's patch is a better approach)

08/31/08 21:03:42 changed by carljm

  • attachment 8630_r8782_svn.diff added.

Thejaswi's original patch, in svn diff style

(follow-up: ↓ 6 ) 08/31/08 23:26:46 changed by thejaswi_puthraya

Carljm, I actually wanted to sneak this patch before 1.0 but Malcolm and Jacob have a valid point that comments currently work and the extensibility can be taken care of post-1.0. This patch might also require documenting the process of writing custom comments. So a patch just addresses the issue is not sufficient, docs are also vital.

Anyways, let this ticket rest till 1.0 is released :)

(in reply to: ↑ 5 ) 08/31/08 23:57:34 changed by carljm

Replying to thejaswi_puthraya:

Anyways, let this ticket rest till 1.0 is released :)

Sure - I'm not advocating for this to happen pre-1.0. Just needed to do custom comments for my own project now anyway, so thought I might as well update things here while I was at it. I'm happy to help work on docs when the time comes.

09/01/08 00:08:56 changed by carljm

  • attachment 8630_r8782_admin.diff added.

admin.py needs to not register the Comment model if it's been replaced with a custom model

09/05/08 08:49:59 changed by jezdez

  • cc changed from carl@dirtcircle.com to carl@dirtcircle.com, jezdez.

09/05/08 09:02:00 changed by amir

  • attachment __init__.py.patch added.

Also removed the checks in get_comment_app() so it's possible to override only part of the functions and use the default for the rest.

09/10/08 08:49:41 changed by carljm

I'm ready to write draft docs and put together the patch for this, whenever it gets blessed with Accepted (though there may be a design decision needed first?)

09/10/08 09:14:53 changed by jezdez

  • cc changed from carl@dirtcircle.com, jezdez to carl@dirtcircle.com.
  • needs_docs set to 1.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Accepted.

That's a valid issue and needs to be adressed.

09/10/08 20:36:02 changed by carljm

  • owner changed from nobody to carljm.

09/24/08 00:06:41 changed by carljm

  • attachment 8630_r9084.diff added.

consolidated patch

09/24/08 00:07:04 changed by carljm

  • attachment 8630_r9084.2.diff added.

consolidated patch, with docs

09/24/08 00:14:53 changed by carljm

Ok, this patch is ready for a looking-over by someone who knows what they're doing. This is my first time trying to actually write any Django docs, so feedback and suggestions are welcome.

A couple other notes on decisions I made in the patch:

- I took Thejaswi's approach of modifying contrib.comments' get_model() etc functions to be smart about delegating to a custom COMMENTS_APP. To me, this seems cleanest, as no other code (ie the templatetags) has to duplicate the get_comment_app() song and dance, it all happens in one place.

- I also incorporated amir's suggestion to make all the customization functions optional, so you can customize what you like and leave the rest.

- No tests yet. I'm not clear where to go with this, as contrib.comments has no tests at all currently. Should I be writing tests for the whole app as part of this ticket? (Seems like maybe that should be its own ticket). Should I just introduce some simple tests for the customizability, and leave everything else untested?

Thoughts and feedback welcome.

09/24/08 00:23:07 changed by carljm

Oops - of course the comments app has tests, they're just with the rest of the Django tests, not with the app. Off to add some tests for customization...

09/24/08 01:23:04 changed by carljm

  • attachment 8630_r9084_with_tests.diff added.

consolidated patch with docs and tests

11/03/08 19:06:36 changed by anonymous

  • cc changed from carl@dirtcircle.com to carl@dirtcircle.com, dane.springmeyer@gmail.com.

11/14/08 14:35:27 changed by carljm

#9562 was a duplicate.

11/25/08 05:43:46 changed by steingrd <steingrd@ifi.uio.no>

  • cc changed from carl@dirtcircle.com, dane.springmeyer@gmail.com to carl@dirtcircle.com, dane.springmeyer@gmail.com, steingrd@ifi.uio.no.

01/18/09 10:26:21 changed by thejaswi_puthraya

  • attachment 8630_new.diff added.

git-patch that has tests, docs and the patch. Slight change from Carljm's patch.

01/18/09 10:28:49 changed by thejaswi_puthraya

  • needs_docs deleted.
  • needs_tests deleted.

The latest patch is based on carljm's patch with a few changes. Docs are courtesy of carljm. Thanks carljm.

01/19/09 12:16:45 changed by carljm

  • attachment 8630_r9776.diff added.

updated patch with minor typo fixes

01/19/09 12:20:24 changed by carljm

Thanks Thejaswi. It'd be nice if you could summarize your changes to the patch to make it easier to look over.

I attached an updated version that fixes a typo your latest patch introduced in contrib/comments/init.py in get_delete_url(), and uses forward slashes instead of dot notation to refer to file locations in docs/ref/contrib/comments/custom.txt.

01/19/09 12:50:04 changed by carljm

  • cc changed from carl@dirtcircle.com, dane.springmeyer@gmail.com, steingrd@ifi.uio.no to dane.springmeyer@gmail.com, steingrd@ifi.uio.no.

01/19/09 21:32:13 changed by david

  • cc changed from dane.springmeyer@gmail.com, steingrd@ifi.uio.no to dane.springmeyer@gmail.com, steingrd@ifi.uio.no, david.

01/22/09 21:26:40 changed by carljm

  • attachment 8630_r9781.diff added.

this time with all the files included :-)

02/23/09 16:16:01 changed by jacob

(In [9889]) Refactored CommentForm?.get_comment_object into a handful of separete methods to make it easier for subclasses to provide custom models and data. Refs #8630.

02/23/09 16:16:28 changed by jacob

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

(In [9890]) Fixed #8630: finished the custom comment app API that was left out of 1.0. This means it's now possible to override any of the models, forms, or views used by the comment app; see the new custom comment app docs for details and an example. Thanks to Thejaswi Puthraya for the original patch, and to carljm for docs and tests.

02/28/09 18:51:10 changed by halfdan

  • cc changed from dane.springmeyer@gmail.com, steingrd@ifi.uio.no, david to dane.springmeyer@gmail.com, steingrd@ifi.uio.no, david, halfdan@halfdans.net.

(follow-up: ↓ 25 ) 03/19/09 09:45:51 changed by joshvanwyck

  • status changed from closed to reopened.
  • resolution deleted.

Greetings,

I'm trying to take advantage of the newest version of the django's customizable comments framework. I am following all the documentation when I try and implement a simple comment system that has an additional field. I tried initially with a BooleanField?, but have since resorted to trying to simply follow the example from the documentation provided.

When I run it, I get the following error message: Caught an exception while rendering: Cannot resolve keyword 'is_public' into field. Choices are: content_type, id, object_pk, site, title

I suspect that this is a bug or either mistaken documentation, as I'm assuming if I follow the example online character for character it should work.

A couple of things I've found by digging through the code. If we extend the BaseCommentAbstractModel?, how can we receive the Comment model's fields? Why does line 84 of templatetags/comments.py contain is_public = true. This field will only exist if we have extended the Comment model but this isn't an option as we are supposed to extend the BaseCommentAbstractModel?.

Also the unit testing doesn't seem to test the rendering which is where the problems seem to be occurring.

Maybe I'm completely off here, this is my first time posting any comments so if I have broken any posting rules please let me know.

Thanks for your work on this portion.

Josh

03/19/09 10:34:14 changed by carljm

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

This is valid, but should get its own ticket. Created #10548.

(in reply to: ↑ 23 ) 03/19/09 21:53:10 changed by thejaswi_puthraya

Hi Josh,

Thanks for your comments. They have been invaluable and they have helped us locate a bug elsewhere.

Replying to joshvanwyck:

Greetings, I'm trying to take advantage of the newest version of the django's customizable comments framework. I am following all the documentation when I try and implement a simple comment system that has an additional field. I tried initially with a BooleanField?, but have since resorted to trying to simply follow the example from the documentation provided. When I run it, I get the following error message: Caught an exception while rendering: Cannot resolve keyword 'is_public' into field. Choices are: content_type, id, object_pk, site, title I suspect that this is a bug or either mistaken documentation, as I'm assuming if I follow the example online character for character it should work.

Ideally you should be subclassing from the Comment Model. But if your requirements are different, then BaseCommentAbstractModel? should do. This problem was fixed in [9891] but there is a small typo in that.

Will reopen that ticket and get it fixed. Also I will open a ticket for patching the documentation that makes it very clear.

A couple of things I've found by digging through the code. If we extend the BaseCommentAbstractModel?, how can we receive the Comment model's fields? Why does line 84 of templatetags/comments.py contain is_public = true. This field will only exist if we have extended the Comment model but this isn't an option as we are supposed to extend the BaseCommentAbstractModel?. Also the unit testing doesn't seem to test the rendering which is where the problems seem to be occurring. Maybe I'm completely off here, this is my first time posting any comments so if I have broken any posting rules please let me know. Thanks for your work on this portion. Josh


Add/Change #8630 (Improve the comments framework customizability)




Change Properties
Action