Staff members can inspect private pictures

This commit is contained in:
Alexandre Iooss 2022-01-30 12:29:27 +01:00
parent d7a39a0334
commit 696bc4d5c1
7 changed files with 49 additions and 53 deletions

View file

@ -52,13 +52,6 @@ else:
fn = unicodedata.normalize('NFKD', force_str(filename)).encode('ascii', 'ignore').decode('ascii')
return os.path.join('photos', fn)
# Support CACHEDIR.TAG spec for backups for ignoring cache dir.
# See http://www.brynosaurus.com/cachedir/spec.html
PHOTOLOGUE_CACHEDIRTAG = os.path.join("photos", "cache", "CACHEDIR.TAG")
if not default_storage.exists(PHOTOLOGUE_CACHEDIRTAG):
default_storage.save(PHOTOLOGUE_CACHEDIRTAG, ContentFile(
b"Signature: 8a477f597d28d172789f06886806bc55"))
# Exif Orientation values
# Value 0thRow 0thColumn
# 1 top left
@ -181,22 +174,13 @@ class Gallery(models.Model):
def get_absolute_url(self):
return reverse('photologue:pl-gallery', args=[self.slug])
def latest(self, limit=LATEST_LIMIT, public=True):
if not limit:
limit = self.photo_count()
if public:
return self.public()[:limit]
else:
return self.photos[:limit]
def sample(self, count=None, public=True):
def sample(self, public=True):
"""Return a sample of photos, ordered at random."""
if not count:
count = 1
count = 1
if count > self.photo_count():
count = self.photo_count()
if public:
photo_set = self.public()
photo_set = self.photos.filter(is_public=True)
else:
photo_set = self.photos
return random.sample(set(photo_set), count)
@ -204,16 +188,12 @@ class Gallery(models.Model):
def photo_count(self, public=True):
"""Return a count of all the photos in this gallery."""
if public:
return self.public().count()
return self.photos.filter(is_public=True).count()
else:
return self.photos.count()
photo_count.short_description = _('count')
def public(self):
"""Return a queryset of all the public photos in this gallery."""
return self.photos.filter(is_public=True)
class ImageModel(models.Model):
image = models.ImageField(_('image'),
@ -375,11 +355,6 @@ class ImageModel(models.Model):
return
# Save the original format
im_format = im.format
# Apply effect if found
if self.effect is not None:
im = self.effect.pre_process(im)
elif photosize.effect is not None:
im = photosize.effect.pre_process(im)
# Rotate if found & necessary
if 'Image Orientation' in self.exif() and \
self.exif().get('Image Orientation').values[0] in IMAGE_EXIF_ORIENTATION_MAP:
@ -388,11 +363,6 @@ class ImageModel(models.Model):
# Resize/crop image
if (im.size != photosize.size and photosize.size != (0, 0)) or recreate:
im = self.resize_image(im, photosize)
# Apply effect if found
if self.effect is not None:
im = self.effect.post_process(im)
elif photosize.effect is not None:
im = photosize.effect.post_process(im)
# Save file
im_filename = getattr(self, "get_%s_filename" % photosize.name)()
try:
@ -515,10 +485,10 @@ class Photo(ImageModel):
return self.title
def save(self, *args, **kwargs):
# If crop_from or effect property has been changed on existing image,
# If crop_from property has been changed on existing image,
# update kwargs to force image recreation in parent class
current = Photo.objects.get(pk=self.pk) if self.pk else None
if current and (current.crop_from != self.crop_from or current.effect != self.effect):
if current and (current.crop_from != self.crop_from):
kwargs.update(recreate=True)
if self.slug is None: