2023-07-29 12:56:42 +08:00
|
|
|
def logs_dir_path(instance, filename):
|
2023-08-11 21:12:51 +08:00
|
|
|
"""
|
|
|
|
file will be uploaded to
|
|
|
|
MEDIA_ROOT_FOR_SENSITIVE_FILES/<ticket-token>/<filename>
|
|
|
|
"""
|
2023-08-11 09:38:47 +08:00
|
|
|
return f'{instance.ticket.number}/{filename}'
|
2023-07-29 12:56:42 +08:00
|
|
|
|
|
|
|
|
2023-09-02 16:54:53 +08:00
|
|
|
def sizify(value: int) -> str:
|
|
|
|
"""Simple kb/mb/gb size snippet for admin panel custom field:
|
2023-08-01 19:13:04 +08:00
|
|
|
|
2023-09-02 16:54:53 +08:00
|
|
|
Args:
|
|
|
|
value (int): size of file from Filefield
|
2023-08-01 19:13:04 +08:00
|
|
|
|
2023-09-02 16:54:53 +08:00
|
|
|
Returns:
|
|
|
|
str: format human readable size like 4.2 Gb
|
|
|
|
"""
|
|
|
|
if value < 512000:
|
|
|
|
value = value / 1024.0
|
|
|
|
ext = 'Kb'
|
|
|
|
elif value < 4194304000:
|
|
|
|
value = value / 1048576.0
|
|
|
|
ext = 'Mb'
|
|
|
|
else:
|
|
|
|
value = value / 1073741824.0
|
|
|
|
ext = 'Gb'
|
|
|
|
return f'{round(value, 2)} {ext}'
|
2023-08-06 10:53:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PageTitleViewMixin:
|
|
|
|
title = 'Collector'
|
|
|
|
|
|
|
|
def get_title(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Return the class title attr by default,
|
|
|
|
but you can override this method to further customize
|
|
|
|
"""
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['title'] = self.get_title()
|
|
|
|
return context
|