diff options
Diffstat (limited to 'app/blog/models.py')
-rw-r--r-- | app/blog/models.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/app/blog/models.py b/app/blog/models.py index ed0bb40..17f9f49 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -1,15 +1,20 @@ import datetime +import os + from django.contrib.gis.db import models from django.utils.html import format_html from django.conf import settings from django.contrib.syndication.views import Feed from django.contrib.sitemaps import Sitemap from django import forms + # http://freewisdom.org/projects/python-markdown/ import markdown +from bs4 import BeautifulSoup + from photos.models import PhotoGallery from locations.models import Location -from bs4 import BeautifulSoup + def get_upload_path(self, filename): return "images/post-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) @@ -23,6 +28,7 @@ def image_url_replace(s): s = s.replace('[[base_url]]', settings.IMAGES_URL) return s + def extract_images(s): soup = BeautifulSoup(s) imgs = [] @@ -30,6 +36,7 @@ def extract_images(s): imgs.append(img['src']) return imgs + class PostImage(models.Model): title = models.CharField(max_length=100) image = models.ImageField(upload_to="%s/%s" % (settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y"))) @@ -103,16 +110,15 @@ class Entry(models.Model): def get_image_wide_url(self): img = self.image.url.split('post-images/')[1].split('/')[1] - #return '%shome-images/%s' % (settings.IMAGES_URL, img) + # return '%shome-images/%s' % (settings.IMAGES_URL, img) return '/media/images/home-images/%s' % (img) def get_image_hero_url(self): img = self.image.url.split('post-images/')[1].split('/')[1] return '/media/images/home-images/hero%s' % (img) - + def get_image_hero_url_sm(self): img = self.image.url.split('post-images/')[1].split('/')[1] - import os img = os.path.splitext(img)[0] return '/media/images/home-images/hero%s_sm.jpg' % (img) @@ -165,13 +171,14 @@ class EntryAside(models.Model): body = models.TextField(null=True, blank=True) entry = models.ForeignKey(Entry) + class HomepageCurrator(models.Model): alt_text = models.CharField(max_length=200) image_base_url = models.CharField(max_length=200) tag_line = models.CharField(max_length=200) banner = models.ForeignKey(Entry, related_name="banner") entry_list = models.ManyToManyField(Entry) - template_name = models.CharField(max_length=200,help_text="full path") + template_name = models.CharField(max_length=200, help_text="full path") class BlogSitemap(Sitemap): @@ -196,18 +203,16 @@ class LatestFull(Feed): 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_gravatar.helpers import get_gravatar_url, has_gravatar, calculate_gravatar_hash from django.dispatch import receiver from django_comments.signals import comment_was_posted from django_comments.models import Comment from django_comments.moderation import CommentModerator, moderator + class EntryModerator(CommentModerator): ''' Moderate everything except people with multiple approvals @@ -218,11 +223,12 @@ class EntryModerator(CommentModerator): previous_approvals = Comment.objects.filter(user_email=comment.email, is_public=True).count() if previous_approvals > 2: return False - #do entry build right here so it goes to live site + # do entry build right here so it goes to live site return True moderator.register(Entry, EntryModerator) + @receiver(comment_was_posted, sender=Comment) def cache_gravatar(sender, comment, **kwargs): gravatar_exists = has_gravatar(comment.email) |