Skip to content

Commit

Permalink
Merge pull request #238 from rkshaon/bs-150
Browse files Browse the repository at this point in the history
done: issue#150 - file length extended
  • Loading branch information
rkshaon authored Jan 22, 2025
2 parents e250e9d + ed93b7a commit e0d0f40
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
11 changes: 0 additions & 11 deletions backend/BookShelf/utilities/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,9 @@ class ReplaceExistingFileStorage(FileSystemStorage):
Custom file storage class that deletes the existing file
from the file system before saving a new one.
"""

# def get_available_name(self, name, max_length=None):
# # If the file already exists, delete it before saving the new one
# if self.exists(name):
# os.remove(self.path(name))

# return super().get_available_name(name, max_length=max_length)
def get_available_name(self, name, max_length=None):
# Get the full file path without extension
base_name, _ = os.path.splitext(self.path(name))

# Delete any existing file with the same base name,
# regardless of extension
# Matches all files with the same name but any extension
for file_path in glob.glob(f"{base_name}.*"):
try:
os.remove(file_path)
Expand Down
2 changes: 1 addition & 1 deletion backend/book_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def cover(self, obj):

def open_url(self, obj):
return format_html(
'<a href="{}" target="_blank">Open the Book</a>',
'<a href="{}" target="_blank">Click</a>',
f"{FRONTEND_BASE_URL}/book/{obj.book_code}"
)
open_url.short_description = 'Read'
Expand Down
20 changes: 20 additions & 0 deletions backend/book_api/migrations/0025_alter_book_cover_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.1 on 2025-01-22 19:18

import BookShelf.utilities.storage
import book_api.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('book_api', '0024_alter_book_book'),
]

operations = [
migrations.AlterField(
model_name='book',
name='cover_image',
field=models.ImageField(blank=True, max_length=255, null=True, storage=BookShelf.utilities.storage.ReplaceExistingFileStorage(), upload_to=book_api.models.cover_upload_path),
),
]
1 change: 1 addition & 0 deletions backend/book_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class Book(models.Model):
validators=[validate_book_file_type],
)
cover_image = models.ImageField(
max_length=255,
upload_to=cover_upload_path,
blank=True,
null=True,
Expand Down

0 comments on commit e0d0f40

Please sign in to comment.