diff --git a/temba/api/v2/views.py b/temba/api/v2/views.py index 6f83ac54b5..c494e46d9a 100644 --- a/temba/api/v2/views.py +++ b/temba/api/v2/views.py @@ -325,12 +325,12 @@ class ArchivesEndpoint(ListAPIMixin, BaseEndpoint): A `GET` returns the archives for your organization with the following fields. - * **archive_type** - the type of the archive, one of `message`or `run` (filterable as `archive_type`). + * **archive_type** - the type of the archive, one of `message` or `run` (filterable as `archive_type`). * **start_date** - the UTC date of the archive (string) (filterable as `before` and `after`). * **period** - `daily` for daily archives, `monthly` for monthly archives (filterable as `period`). * **record_count** - number of records in the archive (int). - * **size** - size of the gziped archive content (int). - * **hash** - MD5 hash of the gziped archive (string). + * **size** - size of the gzipped archive content (int). + * **hash** - MD5 hash of the gzipped archive (string). * **download_url** - temporary download URL of the archive (string). Example: @@ -345,13 +345,13 @@ class ArchivesEndpoint(ListAPIMixin, BaseEndpoint): "count": 248, "results": [ { - "archive_type":"message", - "start_date":"2017-02-20", - "period":"daily", - "record_count":1432, - "size":2304, - "hash":"feca9988b7772c003204a28bd741d0d0", - "download_url":"" + "archive_type": "message", + "start_date": "2017-02-20", + "period": "daily", + "record_count": 1432, + "size": 2304, + "hash": "feca9988b7772c003204a28bd741d0d0", + "download_url": "https://..." }, ... } diff --git a/temba/archives/models.py b/temba/archives/models.py index 4c0f21711a..71972bc14c 100644 --- a/temba/archives/models.py +++ b/temba/archives/models.py @@ -14,7 +14,7 @@ from django.db.models import Q from django.utils import timezone -from temba.utils import json, s3, sizeof_fmt +from temba.utils import json, s3 from temba.utils.s3 import EventStreamReader KEY_PATTERN = re.compile(r"^(?P\d+)/(?Prun|message)_(?P(D|M)\d+)_(?P[0-9a-f]{32})\.jsonl\.gz$") @@ -35,33 +35,20 @@ class Archive(models.Model): archive_type = models.CharField(choices=TYPE_CHOICES, max_length=16) created_on = models.DateTimeField(default=timezone.now) - # the length of time this archive covers period = models.CharField(max_length=1, choices=PERIOD_CHOICES, default=PERIOD_DAILY) + start_date = models.DateField() # the earliest modified_on date for records (inclusive) + record_count = models.IntegerField(default=0) # number of records in this archive + size = models.BigIntegerField(default=0) # size in bytes of the archive contents (after compression) + hash = models.TextField() # MD5 hash of the archive contents (after compression) + url = models.URLField() # full URL of this archive + build_time = models.IntegerField() # time in ms it took to build and upload this archive - # the earliest modified_on date for records in this archive (inclusive) - start_date = models.DateField() - - # number of records in this archive - record_count = models.IntegerField(default=0) - - # size in bytes of the archive contents (after compression) - size = models.BigIntegerField(default=0) - - # MD5 hash of the archive contents (after compression) - hash = models.TextField() - - # full URL of this archive - url = models.URLField() + # archive we were rolled up into, if any + rollup = models.ForeignKey("archives.Archive", on_delete=models.PROTECT, null=True) # whether the records in this archive need to be deleted needs_deletion = models.BooleanField(default=False) - # number of milliseconds it took to build and upload this archive - build_time = models.IntegerField() - - # archive we were rolled up into, if any - rollup = models.ForeignKey("archives.Archive", on_delete=models.PROTECT, null=True) - # when this archive's records where deleted (if any) deleted_on = models.DateTimeField(null=True) @@ -69,9 +56,6 @@ class Archive(models.Model): def storage(cls): return storages["archives"] - def size_display(self): - return sizeof_fmt(self.size) - def get_storage_location(self) -> tuple: """ Returns a tuple of the storage bucket and key diff --git a/temba/utils/__init__.py b/temba/utils/__init__.py index 18e5317162..8038410398 100644 --- a/temba/utils/__init__.py +++ b/temba/utils/__init__.py @@ -44,14 +44,6 @@ def format_number(val): return val -def sizeof_fmt(num, suffix="b"): - for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: - if abs(num) < 1024.0: - return "%3.1f %s%s" % (num, unit, suffix) - num /= 1024.0 - return "%.1f %s%s" % (num, "Y", suffix) - - def chunk_list(iterable, size): """ Splits a very large list into evenly sized chunks. diff --git a/temba/utils/tests.py b/temba/utils/tests.py index 6edad3e95e..567b4089fc 100644 --- a/temba/utils/tests.py +++ b/temba/utils/tests.py @@ -28,7 +28,6 @@ percentage, redact, set_nested_key, - sizeof_fmt, str_to_bool, ) from .checks import storage @@ -40,18 +39,6 @@ class InitTest(TembaTest): - def test_sizeof_fmt(self): - self.assertEqual("512.0 b", sizeof_fmt(512)) - self.assertEqual("1.0 Kb", sizeof_fmt(1024)) - self.assertEqual("1.0 Mb", sizeof_fmt(1024**2)) - self.assertEqual("1.0 Gb", sizeof_fmt(1024**3)) - self.assertEqual("1.0 Tb", sizeof_fmt(1024**4)) - self.assertEqual("1.0 Pb", sizeof_fmt(1024**5)) - self.assertEqual("1.0 Eb", sizeof_fmt(1024**6)) - self.assertEqual("1.0 Zb", sizeof_fmt(1024**7)) - self.assertEqual("1.0 Yb", sizeof_fmt(1024**8)) - self.assertEqual("1024.0 Yb", sizeof_fmt(1024**9)) - def test_str_to_bool(self): self.assertFalse(str_to_bool(None)) self.assertFalse(str_to_bool("")) diff --git a/templates/archives/archive_list.html b/templates/archives/archive_list.html index cf0a1d4b96..f702acf824 100644 --- a/templates/archives/archive_list.html +++ b/templates/archives/archive_list.html @@ -1,6 +1,13 @@ {% extends "orgs/base/list.html" %} {% load i18n humanize temba %} +{% block pre-table %} +
+ {% blocktrans trimmed %} + Archives are created after 90 days of inactivity for messages and flow runs. + {% endblocktrans %} +
+{% endblock pre-table %} {% block table %} @@ -19,7 +26,7 @@ {% endif %} - + - + {% endfor %}
{{ archive.record_count|intcomma }}{{ archive.size_display }}{{ archive.size|filesizeformat }} {% empty %}
- {% blocktrans trimmed %} - No archives found. Archives are created after 90 days of inactivity for messages and flow runs. Check back later to - see a list of all archives. - {% endblocktrans %} - {% trans "No archives" %}