Slugify filenames & update notifications
This commit is contained in:
parent
b2ffd28e8e
commit
7860d69747
3 changed files with 40 additions and 8 deletions
18
gallery/migrations/0002_alter_photo_slug.py
Normal file
18
gallery/migrations/0002_alter_photo_slug.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.1.7 on 2025-04-23 12:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gallery', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='photo',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(verbose_name='Photo Slug'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -20,7 +20,7 @@ def get_upload_path(instance, filename):
|
||||||
|
|
||||||
class Photo(models.Model):
|
class Photo(models.Model):
|
||||||
album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name='photos', verbose_name="Album")
|
album = models.ForeignKey(Album, on_delete=models.CASCADE, related_name='photos', verbose_name="Album")
|
||||||
slug = models.CharField(max_length=50, verbose_name="Photo Slug")
|
slug = models.SlugField(max_length=50, verbose_name="Photo Slug")
|
||||||
photo = models.ImageField(upload_to=get_upload_path, height_field='height', width_field='width', verbose_name="Photo")
|
photo = models.ImageField(upload_to=get_upload_path, height_field='height', width_field='width', verbose_name="Photo")
|
||||||
|
|
||||||
photo_sm = ImageSpecField(source='photo', processors=[ResizeToFit(320, 320)], format='JPEG', options={'quality': 70})
|
photo_sm = ImageSpecField(source='photo', processors=[ResizeToFit(320, 320)], format='JPEG', options={'quality': 70})
|
||||||
|
@ -45,7 +45,8 @@ class Photo(models.Model):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
self.slug = os.path.basename(self.photo.name)
|
base, ext = os.path.splitext(os.path.basename(self.photo.name))
|
||||||
|
self.slug = slugify(base) + ext.lower()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def add_like(self):
|
def add_like(self):
|
||||||
|
|
|
@ -143,11 +143,24 @@
|
||||||
Promise.allSettled(uploadPromises).then(() => {
|
Promise.allSettled(uploadPromises).then(() => {
|
||||||
selectedFiles = newFiles;
|
selectedFiles = newFiles;
|
||||||
renderFileList();
|
renderFileList();
|
||||||
UIkit.notification({
|
const successCount = total - newFiles.length;
|
||||||
message: `Upload completed - ${total - newFiles.length} succeeded, ${newFiles.length} failed`,
|
const failCount = newFiles.length;
|
||||||
status: newFiles.length > 0 ? 'warning' : 'success',
|
|
||||||
pos: 'top-center'
|
if (successCount > 0) {
|
||||||
});
|
UIkit.notification({
|
||||||
|
message: `${successCount} file${successCount > 1 ? 's were' : ' was'} uploaded successfully.`,
|
||||||
|
status: 'success',
|
||||||
|
pos: 'top-center'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failCount > 0) {
|
||||||
|
UIkit.notification({
|
||||||
|
message: `${failCount} file${failCount > 1 ? 's failed' : ' failed'} to upload.`,
|
||||||
|
status: 'danger',
|
||||||
|
pos: 'top-center'
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue