# Path: minent/utils.py
# def htmlize(text):
#     """
#     This helper method renders Markdown then uses Bleach to sanitize it as
#     well as convert all links to actual links.
#     """
#     text = bleach.clean(text, strip=True)    # Clean the text by stripping bad HTML tags
#     text = markdown(text)                    # Convert the markdown to HTML
#     text = bleach.linkify(text)              # Add links from the text and add nofollow to existing links
# 
#     return text
# 
# Path: stream/signals.py
# def stream_handler(sender, **kwargs):
# 
# Path: users/models.py
# class Profile(models.Model):
# 
#     user         = models.OneToOneField(User, editable=False)
#     email_hash   = models.CharField(max_length=32, editable=False)
#     organization = models.CharField(max_length=255, **nullable)
#     location     = models.CharField(max_length=255, **nullable)
#     biography    = models.CharField(max_length=255, **nullable)
#     biography    = models.TextField(help_text="Edit in Markdown", **nullable)
#     biography_rendered = models.TextField(editable=False, **nullable)
#     twitter      = models.CharField(max_length=128, **nullable)
#     github       = models.CharField(max_length=128, **nullable)
# 
#     def get_gravatar_url(self, size=200, default="mm"):
#         """
#         Computes the gravatar url from an email address
#         """
#         params = urlencode({'d': default, 's': str(size)})
#         grvurl = "http://www.gravatar.com/avatar/%s?%s" % (self.email_hash,
#                                                            params)
#         return grvurl
# 
#     @property
#     def gravatar(self):
#         return self.get_gravatar_url()
# 
#     @property
#     def gravatar_icon(self):
#         return self.get_gravatar_url(size=24)
# 
#     @property
#     def gravatar_badge(self):
#         return self.get_gravatar_url(size=64)
# 
#     @property
#     def full_name(self):
#         return self.user.get_full_name()
# 
#     @property
#     def full_email(self):
#         email = "%s <%s>" % (self.full_name, self.user.email)
#         return email.strip()
# 
#     def get_api_detail_url(self):
#         """
#         Returns the API detail endpoint for the object
#         """
#         return reverse('api:user-detail', args=(self.pk,))
# 
#     def __str__(self):
#         return self.full_email


import hashlib
from minent.utils import htmlize
from stream.signals import stream
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save
from users.models import Profile
from django.contrib.auth.models import User
Signals management for the Users app
"""

##########################################################################
## Imports
##########################################################################




##########################################################################
## Signals
##########################################################################

@receiver(pre_save, sender=Profile)
def question_render_markdown(sender, instance, *args, **kwargs):
    if instance.biography:
        instance.biography_rendered = htmlize(instance.biography)


@receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
    """
    Creates a Profile object for the user if it doesn't exist, or updates
    it with new information from the User (e.g. the gravatar).
    """
    ## Compute the email hash
    digest = hashlib.md5(instance.email.lower().encode("utf-8")).hexdigest()

    if created:

# Path: minent/utils.py
# def htmlize(text):
#     """
#     This helper method renders Markdown then uses Bleach to sanitize it as
#     well as convert all links to actual links.
#     """
#     text = bleach.clean(text, strip=True)    # Clean the text by stripping bad HTML tags
#     text = markdown(text)                    # Convert the markdown to HTML
#     text = bleach.linkify(text)              # Add links from the text and add nofollow to existing links
# 
#     return text
# 
# Path: stream/signals.py
# def stream_handler(sender, **kwargs):
# 
# Path: users/models.py
# class Profile(models.Model):
# 
#     user         = models.OneToOneField(User, editable=False)
#     email_hash   = models.CharField(max_length=32, editable=False)
#     organization = models.CharField(max_length=255, **nullable)
#     location     = models.CharField(max_length=255, **nullable)
#     biography    = models.CharField(max_length=255, **nullable)
#     biography    = models.TextField(help_text="Edit in Markdown", **nullable)
#     biography_rendered = models.TextField(editable=False, **nullable)
#     twitter      = models.CharField(max_length=128, **nullable)
#     github       = models.CharField(max_length=128, **nullable)
# 
#     def get_gravatar_url(self, size=200, default="mm"):
#         """
#         Computes the gravatar url from an email address
#         """
#         params = urlencode({'d': default, 's': str(size)})
#         grvurl = "http://www.gravatar.com/avatar/%s?%s" % (self.email_hash,
#                                                            params)
#         return grvurl
# 
#     @property
#     def gravatar(self):
#         return self.get_gravatar_url()
# 
#     @property
#     def gravatar_icon(self):
#         return self.get_gravatar_url(size=24)
# 
#     @property
#     def gravatar_badge(self):
#         return self.get_gravatar_url(size=64)
# 
#     @property
#     def full_name(self):
#         return self.user.get_full_name()
# 
#     @property
#     def full_email(self):
#         email = "%s <%s>" % (self.full_name, self.user.email)
#         return email.strip()
# 
#     def get_api_detail_url(self):
#         """
#         Returns the API detail endpoint for the object
#         """
#         return reverse('api:user-detail', args=(self.pk,))
# 
#     def __str__(self):
#         return self.full_email


# Path: users/signals.py
import hashlib
from minent.utils import htmlize
from stream.signals import stream
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save
from users.models import Profile
from django.contrib.auth.models import User

Signals management for the Users app
"""

##########################################################################
## Imports
##########################################################################




##########################################################################
## Signals
##########################################################################

@receiver(pre_save, sender=Profile)
def question_render_markdown(sender, instance, *args, **kwargs):
    if instance.biography:
        instance.biography_rendered = htmlize(instance.biography)


@receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
    """
    Creates a Profile object for the user if it doesn't exist, or updates
    it with new information from the User (e.g. the gravatar).
    """
    ## Compute the email hash
    digest = hashlib.md5(instance.email.lower().encode("utf-8")).hexdigest()

    if created:

        Profile.objects.create(user=instance, email_hash=digest)