From f650f1860eabfb7d114513dbd0980698ca2b7f84 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Mon, 10 Nov 2014 20:44:49 -0500 Subject: reverted Pages to database --- app/blog/models.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'app/blog/models.py') 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) -- cgit v1.2.3-70-g09d2