From cd2b724e01195ae097871607fe61db70e5e8d92b Mon Sep 17 00:00:00 2001 From: luxagraf Date: Mon, 9 Jul 2018 20:14:24 -0400 Subject: changed sightings to use the image parsing from util --- app/sightings/models.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'app/sightings') diff --git a/app/sightings/models.py b/app/sightings/models.py index fd5cba6..fe09f39 100644 --- a/app/sightings/models.py +++ b/app/sightings/models.py @@ -14,20 +14,8 @@ from bs4 import BeautifulSoup from locations.models import Location from photos.models import LuxImage -from utils.util import parse_image, markdown_to_html from utils.next_prev import next_in_order, prev_in_order - - -def render_images(s): - s = re.sub('', parse_image, s) - return s - - -def extract_main_image(s): - soup = BeautifulSoup(s, 'html.parser') - image = soup.find_all('img')[0]['id'] - return image.split('image-')[1] - +from utils.util import render_images, extract_main_image, markdown_to_html def get_upload_path(self, filename): return "images/sightings-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) @@ -130,10 +118,9 @@ class AP(models.Model): if self.pk: md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) - try: - self.image = LuxImage.objects.get(pk=extract_main_image(self.body_markdown)) - except TypeError: - pass + main_image = extract_main_image(self.body_markdown) + if main_image: + self.image = main_image self.slug = slugify(self.common_name[:50]) super(AP, self).save(*args, **kwargs) -- cgit v1.2.3-70-g09d2