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):
|
||||
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_sm = ImageSpecField(source='photo', processors=[ResizeToFit(320, 320)], format='JPEG', options={'quality': 70})
|
||||
|
@ -42,10 +42,11 @@ class Photo(models.Model):
|
|||
@property
|
||||
def aspect_ratio(self):
|
||||
return self.width / self.height
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
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)
|
||||
|
||||
def add_like(self):
|
||||
|
|
|
@ -143,11 +143,24 @@
|
|||
Promise.allSettled(uploadPromises).then(() => {
|
||||
selectedFiles = newFiles;
|
||||
renderFileList();
|
||||
UIkit.notification({
|
||||
message: `Upload completed - ${total - newFiles.length} succeeded, ${newFiles.length} failed`,
|
||||
status: newFiles.length > 0 ? 'warning' : 'success',
|
||||
pos: 'top-center'
|
||||
});
|
||||
const successCount = total - newFiles.length;
|
||||
const failCount = newFiles.length;
|
||||
|
||||
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