from disqus.wxr_feed import ContribCommentsWxrFeed

class ShirtCommentsWxrFeed(ContribCommentsWxrFeed):
  def get_object(self, request): #Fetch the current site
    from django.contrib.sites.models import Site
    self.site = Site.objects.get_current()
    return self.site

  def items(self, obj):
    # Fetch all shirts which have valid comments
    return Shirt.objects.valid().filter(pk__in = Shirt.objects.filter(comments__site = obj))

  def item_title(self, item):
    print "*** title", item.title
    return item.title

  def item_link(self, item):
    site = self.site

    url = Url(item.get_absolute_url())
    url.domain = self.site.domain
    return url.url

  def item_comment_status(self, item):
    return "open"

  def item_pubdate(self, item):
    return item.created

  def item_guid(self, item):
    """
    The path to the comments thread.
    """
    return "/shirt/{0}".format(item.pk) # aka item.disqus_identifier

  def item_comments(self, item):
    # Select the valid comments for this shirt
    from django.contrib.comments.models import Comment
    return Comment.objects.for_model(item).filter(is_public = True, is_removed = False)

  # Comment information
  def comment_id(self, comment):
    print "comment", comment.pk
    return comment.pk
  
  def comment_user_id(self, comment):
    return comment.user.pk if comment.user else 0

  def comment_user_name(self, comment):
    return comment.user_name

  def comment_user_email(self, comment):
    if comment.user:
      return comment.user.email.lower()
    else:
      return comment.user_email.lower()

  def comment_user_url(self, comment):
    # Comment author's homepage URL
    return comment.user_url

  def comment_ip_address(self, comment):
    return comment.ip_address

  def comment_submit_date(self, comment):
    return comment.submit_date

  def comment_comment(self, comment):
    return comment.comment

  def comment_is_approved(self, comment):
    return '1' # '0' for False
  
  def comment_parent(self, comment):
    # Should match comment_id() if you support it
    return 0