mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-09-13 13:13:01 +02:00
Add: storage info widget and storage api endpoint refactoring project structure add version app
This commit is contained in:
0
logs_collector/collector/utils/__init__.py
Normal file
0
logs_collector/collector/utils/__init__.py
Normal file
38
logs_collector/collector/utils/helpers.py
Normal file
38
logs_collector/collector/utils/helpers.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import shutil
|
||||
|
||||
|
||||
def logs_dir_path(instance, filename):
|
||||
"""
|
||||
file will be uploaded to
|
||||
MEDIA_ROOT/view/<filename>
|
||||
"""
|
||||
return f'{instance.ticket.number}/{filename}'
|
||||
|
||||
|
||||
def sizify(value: int) -> str:
|
||||
"""Simple kb/mb/gb size snippet for admin panel custom field:
|
||||
|
||||
Args:
|
||||
value (int): size of file from Filefield
|
||||
|
||||
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, 1)} {ext}'
|
||||
|
||||
|
||||
def get_mount_fs_info(path):
|
||||
mount_info = shutil.disk_usage(path)._asdict()
|
||||
mount_info['used_percent'] = round(
|
||||
mount_info['used'] / mount_info['total'] * 100
|
||||
)
|
||||
return {'storage': mount_info}
|
23
logs_collector/collector/utils/mixins.py
Normal file
23
logs_collector/collector/utils/mixins.py
Normal file
@@ -0,0 +1,23 @@
|
||||
class ExtraContextMixin:
|
||||
"""The class adds additional context
|
||||
to all child view classes that inherit from it.
|
||||
Overrides the get_context_data method for CBV
|
||||
"""
|
||||
|
||||
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 = {}
|
||||
try:
|
||||
context = super().get_context_data(**kwargs)
|
||||
except Exception:
|
||||
pass
|
||||
context['title'] = self.get_title()
|
||||
return context
|
Reference in New Issue
Block a user