Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix ZeroDivisionError in TaskModel admin #133

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ You must change your Django settings and replace the app name:

## History

* [dev](https://github.com/boxine/django-huey-monitor/compare/v0.8.0...main)
* [dev](https://github.com/boxine/django-huey-monitor/compare/v0.8.1...main)
* _tbc_
* [v0.8.1 - 20.11.2023](https://github.com/boxine/django-huey-monitor/compare/v0.8.0...v0.8.1)
* Bugfix `ZeroDivisionError` in admin
* [v0.8.0 - 20.11.2023](https://github.com/boxine/django-huey-monitor/compare/v0.7.1...v0.8.0)
* Make is possible to override `list_filter` of `SignalInfoModelAdmin` and `TaskModelAdmin` via settings
* Update local docker dev setup
Expand Down
2 changes: 1 addition & 1 deletion huey_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Django based tool for monitoring huey task queue: https://github.com/coleifer/huey
"""

__version__ = '0.8.0'
__version__ = '0.8.1'
__author__ = 'Jens Diemer <[email protected]>'
7 changes: 6 additions & 1 deletion huey_monitor/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ def format_sizeof(num, suffix='', divisor=1000):
return f'{num:3.1f}Y' + suffix


def percentage(num, total):
def percentage(num, total) -> str | None:
"""
>>> percentage(25, 100)
'25%'
>>> percentage(33.333, 100)
'33%'
>>> percentage(123, 0)
None
"""
if not total:
return None

frac = num / total
percentage = frac * 100
return f'{percentage:.0f}%'
Expand Down
2 changes: 1 addition & 1 deletion huey_monitor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def elapsed_sec(self):
return dt_diff.total_seconds()

def human_percentage(self):
if self.progress_count is not None and self.total is not None:
if self.progress_count is not None and self.total:
return percentage(num=self.progress_count, total=self.total)
human_percentage.short_description = _('percentage')

Expand Down
12 changes: 12 additions & 0 deletions huey_monitor_project/tests/test_huey_monitor_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.test import TestCase
from model_bakery import baker

from huey_monitor.models import TaskModel


class HueyMonitorModelsTestCase(TestCase):
def test_human_percentage(self):
instance = baker.make(TaskModel, progress_count=10, total=None)
self.assertIs(instance.human_percentage(), None)
instance.total = 100
self.assertEqual(instance.human_percentage(), '10%')
Loading