summaryrefslogtreecommitdiff
path: root/app/sightings
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-07-09 20:14:24 -0400
committerluxagraf <sng@luxagraf.net>2018-07-09 20:14:24 -0400
commitcd2b724e01195ae097871607fe61db70e5e8d92b (patch)
treed832e41385a4e48ad78d9c3a91ea7b0ce30823ca /app/sightings
parent07df2304c8d2ac6fa0a0e56f48949471413e551b (diff)
changed sightings to use the image parsing from util
Diffstat (limited to 'app/sightings')
-rw-r--r--app/sightings/models.py21
1 files changed, 4 insertions, 17 deletions
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('<img(.*)/>', 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)