Features: 1) Add configurable options for BACKUP_DATABASE and BACKUP_MEDIA in system settings; 2) Enhance backup_task to handle selective backups and return status message;
Fixes: 1) Add exception handling for invalid image file dimensions in `validators.py`; Extra: 1) Update settings categories to include new system options; 2) Improve code clarity in `backup_task` and `validators.py`.
This commit is contained in:
parent
5db4c3be37
commit
9034551502
3 changed files with 21 additions and 6 deletions
|
|
@ -23,9 +23,15 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
@shared_task(queue="default")
|
||||
def backup_task():
|
||||
call_command("dbbackup", clean=True)
|
||||
call_command("mediabackup", clean=True)
|
||||
def backup_task() -> tuple[bool, str]:
|
||||
backups: list[str] = []
|
||||
if config.BACKUP_DATABASE:
|
||||
call_command("dbbackup", clean=True)
|
||||
backups.append("database")
|
||||
if config.BACKUP_MEDIA:
|
||||
call_command("mediabackup", clean=True)
|
||||
backups.append("media")
|
||||
return True, f"Successfully backed up {', '.join(backups)}"
|
||||
|
||||
|
||||
@shared_task(queue="stock_updater")
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ def validate_category_image_dimensions(
|
|||
max_height = max_height or 4320
|
||||
|
||||
if image:
|
||||
width, height = get_image_dimensions(image.file) # type: ignore [arg-type]
|
||||
try:
|
||||
width, height = get_image_dimensions(image.file) # type: ignore [arg-type]
|
||||
except (FileNotFoundError, OSError, ValueError):
|
||||
return
|
||||
|
||||
if int(width) > max_width or int(height) > max_height: # type: ignore [arg-type]
|
||||
raise ValidationError(_(f"image dimensions should not exceed w{max_width} x h{max_height} pixels"))
|
||||
|
|
|
|||
|
|
@ -47,8 +47,10 @@ CONSTANCE_CONFIG = OrderedDict(
|
|||
### SEO Options ###
|
||||
("ADVERTSIMENT", (getenv("EVIBES_ADVERTISIMENT", ""), _("An entity for storing advertisiment data"), "json")),
|
||||
("ANALYTICS", (getenv("EVIBES_ANALYTICS", ""), _("An entity for storing analytics data"), "json")),
|
||||
### Debugging Options ###
|
||||
### System Options ###
|
||||
("SAVE_VENDORS_RESPONSES", (False, _("Save responses from vendors' APIs"))),
|
||||
("BACKUP_DATABASE", (True, _("Backup database"))),
|
||||
("BACKUP_MEDIA", (False, _("Backup media"))),
|
||||
]
|
||||
)
|
||||
|
||||
|
|
@ -85,7 +87,11 @@ CONSTANCE_CONFIG_FIELDSETS = OrderedDict(
|
|||
"ADVERTSIMENT",
|
||||
"ANALYTICS",
|
||||
),
|
||||
_("Debugging Options"): ("SAVE_VENDORS_RESPONSES",),
|
||||
_("System Options"): (
|
||||
"SAVE_VENDORS_RESPONSES",
|
||||
"BACKUP_DATABASE",
|
||||
"BACKUP_MEDIA",
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue