summaryrefslogtreecommitdiff
path: root/app/blog
diff options
context:
space:
mode:
Diffstat (limited to 'app/blog')
-rw-r--r--app/blog/admin.py1
-rw-r--r--app/blog/models.py36
2 files changed, 36 insertions, 1 deletions
diff --git a/app/blog/admin.py b/app/blog/admin.py
index 3038a4f..c30244e 100644
--- a/app/blog/admin.py
+++ b/app/blog/admin.py
@@ -17,6 +17,7 @@ class EntryAsideAdmin(admin.ModelAdmin):
class BlogEntryForm(forms.ModelForm):
class Meta:
model = Entry
+ fields = '__all__'
widgets = {
'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}),
}
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)