def render(self, context):
        try:
            comment_user = self.user.resolve(context)
        except template.VariableDoesNotExist:
            return ""

        comment_user_pk = comment_user.pk
        user = User.objects.get(pk=comment_user_pk)

        try:
            profile = UserProfile.objects.get(user=user)
        except:
            profile = UserProfile()
            profile.user = User
        try:
            if self.mode == "full":
                avatar = profile.image
            else:
                avatar = profile.thumbnail
        except KeyError:
            avatar = None

        if not avatar or avatar._name is u"":
            if self.mode == "full":
                avatar = settings.DEFAULT_PROFILE_IMAGE
            else:
                avatar = settings.DEFAULT_PROFILE_THUMBNAIL
            return avatar

        return settings.MEDIA_URL + avatar._name
Beispiel #2
0
def createUserProfile(sender, **kwargs):
    """Creates a UserProfile associated with the instance provided from User.save().
    Will only work if the User has been created with an email address. 
    """
    created = kwargs.pop("created", False)
    instance = kwargs.pop("instance", False)    
    
    if created and instance:
        up = UserProfile()
        up.user = instance
        up.save(commit=True)