from django.contrib.comments.models import Comment
from django.db import models

class OslComment(Comment):
    parent_comment = models.ForeignKey(Comment, blank=True, null=True, related_name='parent_comment')
    inline_to_object = models.BooleanField()
    edit_timestamp = models.DateTimeField(auto_now=True)


from django.contrib.comments.models import Comment
from django.contrib.comments.signals import comment_was_posted
from django.db import models

class OslComment(Comment):
    parent_comment = models.ForeignKey(Comment, blank=True, null=True, related_name='parent_comment')
    inline_to_object = models.BooleanField()
    edit_timestamp = models.DateTimeField(auto_now=True)

def comment_user_url_injection_handler(sender, **kwargs):
    if 'request' in kwargs and kwargs['request'].user.is_authenticated() and \
        'comment' in kwargs:
        
        comment = kwargs['comment']
        comment.url = comment.user.get_profile().url
        comment.save()
comment_was_posted.connect(comment_user_url_injection_handler)


Use signals to add authenticated user URL to comment when posted
Use signals to add authenticated user URL to comment when posted

  from django.contrib.comments.models import Comment
+ from django.contrib.comments.signals import comment_was_posted
  from django.db import models
  
  class OslComment(Comment):
      parent_comment = models.ForeignKey(Comment, blank=True, null=True, related_name='parent_comment')
      inline_to_object = models.BooleanField()
      edit_timestamp = models.DateTimeField(auto_now=True)
  
+ def comment_user_url_injection_handler(sender, **kwargs):
+     if 'request' in kwargs and kwargs['request'].user.is_authenticated() and \
+         'comment' in kwargs:
+         
+         comment = kwargs['comment']
+         comment.url = comment.user.get_profile().url
+         comment.save()
+ comment_was_posted.connect(comment_user_url_injection_handler)
  
+ 
Use signals to add authenticated user URL to comment when posted
## Code Before:
from django.contrib.comments.models import Comment
from django.db import models

class OslComment(Comment):
    parent_comment = models.ForeignKey(Comment, blank=True, null=True, related_name='parent_comment')
    inline_to_object = models.BooleanField()
    edit_timestamp = models.DateTimeField(auto_now=True)


## Instruction:
Use signals to add authenticated user URL to comment when posted
## Code After:
from django.contrib.comments.models import Comment
from django.contrib.comments.signals import comment_was_posted
from django.db import models

class OslComment(Comment):
    parent_comment = models.ForeignKey(Comment, blank=True, null=True, related_name='parent_comment')
    inline_to_object = models.BooleanField()
    edit_timestamp = models.DateTimeField(auto_now=True)

def comment_user_url_injection_handler(sender, **kwargs):
    if 'request' in kwargs and kwargs['request'].user.is_authenticated() and \
        'comment' in kwargs:
        
        comment = kwargs['comment']
        comment.url = comment.user.get_profile().url
        comment.save()
comment_was_posted.connect(comment_user_url_injection_handler)

