From 68361e252c5fae432e30bb88ce86b3d9ac073f28 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 10 Jul 2015 10:13:58 -0400 Subject: added more images to facebook OG tags --- app/blog/models.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app/blog') diff --git a/app/blog/models.py b/app/blog/models.py index 513ce05..fbbf1db 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -9,7 +9,7 @@ from django import forms import markdown 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) @@ -19,10 +19,17 @@ def get_tn_path(self, filename): return "images/post-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) -def image_url_replace(str): - str = str.replace('[[base_url]]', settings.IMAGES_URL) - return str +def image_url_replace(s): + s = s.replace('[[base_url]]', settings.IMAGES_URL) + return s +def extract_images(s): + soup = BeautifulSoup(s) + imgs = [] + for img in soup.find_all('img'): + print(img['src']) + imgs.append(img['src']) + return imgs class PostImage(models.Model): title = models.CharField(max_length=100) @@ -110,6 +117,9 @@ class Entry(models.Model): img = os.path.splitext(img)[0] return '/media/images/home-images/hero%s_sm.jpg' % (img) + def get_images(self): + return extract_images(self.body_html) + @property def state(self): return self.location.state -- cgit v1.2.3-70-g09d2