summaryrefslogtreecommitdiff
path: root/app/photos
diff options
context:
space:
mode:
Diffstat (limited to 'app/photos')
-rw-r--r--app/photos/models.py17
-rw-r--r--app/photos/utils.py9
2 files changed, 16 insertions, 10 deletions
diff --git a/app/photos/models.py b/app/photos/models.py
index 5a7bff1..5a41182 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -15,7 +15,6 @@ from django.conf import settings
from django import forms
from taggit.managers import TaggableManager
-from locations.models import Location, Region
from resizeimage.imageexceptions import ImageSizeError
@@ -69,7 +68,7 @@ class LuxImage(models.Model):
height = models.CharField(max_length=6, blank=True, null=True)
width = models.CharField(max_length=6, blank=True, null=True)
point = models.PointField(null=True, blank=True)
- location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
+ location = models.ForeignKey("locations.Location", on_delete=models.CASCADE, null=True, blank=True)
is_public = models.BooleanField(default=True)
sizes = models.ManyToManyField(LuxImageSize, blank=True)
flickr_id = models.CharField(null=True, blank=True, max_length=80)
@@ -177,10 +176,10 @@ class LuxImage(models.Model):
if not self.point:
self.point = LuxImage.objects.latest().point
try:
- self.location = Location.objects.filter(
+ self.location = apps.get_model('locations', 'Location').objects.filter(
geometry__contains=self.point
).get()
- except Location.DoesNotExist:
+ except DoesNotExist:
raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
super(LuxImage, self).save()
@@ -239,7 +238,7 @@ class LuxGallery(models.Model):
images = models.ManyToManyField(LuxImage)
pub_date = models.DateTimeField(null=True)
point = models.PointField(null=True, blank=True)
- location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
+ location = models.ForeignKey("locations.Location", on_delete=models.CASCADE, null=True, blank=True)
is_public = models.BooleanField(default=True)
caption_style = models.CharField(blank=True, null=True, max_length=400)
@@ -318,8 +317,8 @@ class Photo(models.Model):
flickr_originalsecret = models.CharField(max_length=50)
lon = models.FloatField('Longitude', help_text="Longitude of centerpoint", null=True)
lat = models.FloatField('Latitude', help_text="Latitude of centerpoint", null=True)
- location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True)
- region = models.ForeignKey(Region, on_delete=models.CASCADE, null=True)
+ location = models.ForeignKey("locations.Location", on_delete=models.CASCADE, null=True)
+ region = models.ForeignKey("locations.Region", on_delete=models.CASCADE, null=True)
slideshowimage_width = models.CharField(max_length=4, blank=True, null=True)
slideshowimage_height = models.CharField(max_length=4, blank=True, null=True)
slideshowimage_margintop = models.CharField(max_length=4, blank=True, null=True)
@@ -462,8 +461,8 @@ class PhotoGallery(models.Model):
set_slug = models.CharField(blank=True, max_length=300)
primary = models.CharField(blank=True, max_length=300)
photos = models.ManyToManyField(Photo)
- location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True)
- region = models.ForeignKey(Region, on_delete=models.CASCADE, null=True)
+ location = models.ForeignKey("locations.Location", on_delete=models.CASCADE, null=True)
+ region = models.ForeignKey("locations.Region", on_delete=models.CASCADE, null=True)
pub_date = models.DateTimeField(null=True)
class Meta:
diff --git a/app/photos/utils.py b/app/photos/utils.py
index 28047d4..84e72f5 100644
--- a/app/photos/utils.py
+++ b/app/photos/utils.py
@@ -1,7 +1,12 @@
import os
+import re
import subprocess
-from PIL import ImageFile
+from django.apps import apps
+from django.conf import settings
+
+from PIL import ImageFile
+from bs4 import BeautifulSoup
# pip install python-resize-image
from resizeimage import resizeimage
@@ -19,3 +24,5 @@ def resize_image(img, width=None, height=None, quality=72, base_path="", filenam
ImageFile.MAXBLOCK = img.size[0] * img.size[1] * 4
newimg.save(path, newimg.format, quality=quality)
subprocess.call(["jpegoptim", "%s" % path])
+
+