On Oct 9, 2008, at 8:14 AM, fitzage wrote:
> > So far this is working great in terms of firing off the emails. How do > you go about creating the security hash? I'm a little lost when it > comes to that point. I'm on less solid ground here, unfortunately. Django's got a utility for this (django.utils.hashcompat.sha_constructor) – basically you feed sha_constructor strings and then call hexdigest() on it to get the security hash (http://docs.python.org/library/hashlib.html). But I'm not confident that I'm using it securely. I make a hash out of the commenter's email address and the pk of the blog entry in question. It works, but it might not be Best Practices. > This works, but it should be noted that it's an unfortunate > monkeypatch that is necessary because contrib.comments doesn't > properly support customization yet. Once ticket 8630 [1] is resolved, > the proper way to do this will be to create your own app with a > get_form() function in __init__.py, and then set COMMENTS_APP to point > to your app. Thanks for the head's up, Carl, I'll keep an eye on the ticket. E > > On Oct 7, 7:49 pm, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: >> On Oct 7, 2008, at 11:38 PM, fitzage wrote: >> >> >> >>> I want to add one additional piece of data to the comment form. >>> Basically a checkbox that says whether or not the commenter wants to >>> be notified of followup comments. >> >> I just did exactly this, and found that what works best is not just >> to >> add an input field to the form template, but to actually subclass the >> builtin CommentForm and add the field there. That way the field will >> be a part of the form no matter how and where you use it, and will >> remain in the 'cleaned data' dictionary when the form is validated. >> Subclass the builtin form, add the field, and then do: >> >> from django.contrib import comments >> >> def my_get_form(): >> return MyCommentForm >> >> comments.get_form = my_get_form >> >>> I know how to add the checkbox. I just created a comments/form.html >>> template and added the checkbox to it. I know that the data is >>> getting >>> passed correctly. >> >>> Now how do I grab that on the backend without having to modify the >>> comment app directly? There is probably a simple, django-standard >>> way >>> to do this, but I'm at a loss. I already have a function that emails >>> admin users when a comment is posted, but I'm not sure I >>> understand it >>> well enough to piggy-back off of that, and I'm not even sure that I >>> can. >> >> Signals are beautiful! I made Commenter (email field) and >> CommentNotification (commenter and entry foreign keys) models, and >> did >> this: >> >> def make_notification(sender, comment, request, **kwargs): >> notify = request.POST.get("notify", None) >> email = request.POST.get("email", None) >> if notify and email: >> commenter, created = Commenter.get_or_create(email=email) >> notification, created = >> CommentNotification.get_or_create(commenter=commenter, >> entry=comment.content_object) >> >> def notify_commenters(sender, comment, request, **kwargs): >> notifications = >> CommentNotification >> .objects.select_related().filter(entry=comment.content_object) >> if notifications: >> for n in notifications: >> msg = render_to_string('comments/email.txt', >> {'comment':comment,'notification':n}) >> send_mail("There's a new comment!",msg,"[EMAIL PROTECTED] >> ",recipient_list=[n.commenter.email],fail_silently=True) >> >> comment_was_posted.connect(make_notification) >> comment_was_posted.connect(notify_commenters) >> >> The email contains a link with a security hash which they can use to >> un-register themselves for that particular blog entry. >> >> I only just wrote all this and haven't tested it yet, but the basic >> principle ought to be sound... >> >> Hope that helps, >> Eric >> >> > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---