diff options
author | luxagraf <sng@luxagraf.net> | 2014-11-10 20:44:49 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2014-11-10 20:44:49 -0500 |
commit | f650f1860eabfb7d114513dbd0980698ca2b7f84 (patch) | |
tree | a190e56d224baeeb3c8cc7adeb4233c47646c79f /app/blog/models.py | |
parent | d283e039666fa57ccf06c3d235162927db285fb8 (diff) |
reverted Pages to database
Diffstat (limited to 'app/blog/models.py')
-rw-r--r-- | app/blog/models.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/app/blog/models.py b/app/blog/models.py index 4ff1935..4ad6022 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -162,7 +162,6 @@ class HomepageCurrator(models.Model): template_name = models.CharField(max_length=200,help_text="full path") - class BlogSitemap(Sitemap): changefreq = "never" priority = 1.0 @@ -183,3 +182,38 @@ class LatestFull(Feed): def items(self): return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + +import os +import io +import urllib.request +import urllib.parse +import urllib.error +import shutil +from django_gravatar.helpers import get_gravatar_url, has_gravatar, get_gravatar_profile_url, calculate_gravatar_hash +from django.dispatch import receiver +from django_comments.signals import comment_was_posted +from django_comments import Comment + +@receiver(comment_was_posted, sender=Comment) +def cache_gravatar(sender, comment, **kwargs): + gravatar_exists = has_gravatar(comment.email) + grav_dir = settings.IMAGES_ROOT + '/gravcache/' + print(gravatar_exists) + if gravatar_exists: + url = get_gravatar_url(comment.email, size=60) + if not os.path.isdir(grav_dir): + os.makedirs(grav_dir) + local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) + urllib.request.urlretrieve(url, local_grav) + else: + dest = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) + src = settings.IMAGES_ROOT + '/gravcache/default.jpg' + try: + shutil.copy(src, dest) + # eg. src and dest are the same file + except shutil.Error as e: + print('Error: %s' % e) + # eg. source or destination doesn't exist + except IOError as e: + print('Error: %s' % e.strerror) |