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")
|
@shared_task(queue="default")
|
||||||
def backup_task():
|
def backup_task() -> tuple[bool, str]:
|
||||||
call_command("dbbackup", clean=True)
|
backups: list[str] = []
|
||||||
call_command("mediabackup", clean=True)
|
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")
|
@shared_task(queue="stock_updater")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ def validate_category_image_dimensions(
|
||||||
max_height = max_height or 4320
|
max_height = max_height or 4320
|
||||||
|
|
||||||
if image:
|
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]
|
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"))
|
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 ###
|
### SEO Options ###
|
||||||
("ADVERTSIMENT", (getenv("EVIBES_ADVERTISIMENT", ""), _("An entity for storing advertisiment data"), "json")),
|
("ADVERTSIMENT", (getenv("EVIBES_ADVERTISIMENT", ""), _("An entity for storing advertisiment data"), "json")),
|
||||||
("ANALYTICS", (getenv("EVIBES_ANALYTICS", ""), _("An entity for storing analytics 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"))),
|
("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",
|
"ADVERTSIMENT",
|
||||||
"ANALYTICS",
|
"ANALYTICS",
|
||||||
),
|
),
|
||||||
_("Debugging Options"): ("SAVE_VENDORS_RESPONSES",),
|
_("System Options"): (
|
||||||
|
"SAVE_VENDORS_RESPONSES",
|
||||||
|
"BACKUP_DATABASE",
|
||||||
|
"BACKUP_MEDIA",
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue