From a10f165a26d5b86ebedf81f3809dc801851e4a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 7 Dec 2023 08:58:00 +0100 Subject: [PATCH] collect hosted strings --- weblate_web/admin.py | 1 + ..._strings_report_hosted_strings_and_more.py | 27 +++++++++++++++++++ weblate_web/models.py | 21 +++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 weblate_web/migrations/0026_package_limit_hosted_strings_report_hosted_strings_and_more.py diff --git a/weblate_web/admin.py b/weblate_web/admin.py index c686650ac5..a924b9da21 100644 --- a/weblate_web/admin.py +++ b/weblate_web/admin.py @@ -66,6 +66,7 @@ class ServiceAdmin(admin.ModelAdmin): "languages_limit", "source_strings_limit", "hosted_words_limit", + "hosted_strings_limit", "status", "user_emails", "expires", diff --git a/weblate_web/migrations/0026_package_limit_hosted_strings_report_hosted_strings_and_more.py b/weblate_web/migrations/0026_package_limit_hosted_strings_report_hosted_strings_and_more.py new file mode 100644 index 0000000000..8149ac93f1 --- /dev/null +++ b/weblate_web/migrations/0026_package_limit_hosted_strings_report_hosted_strings_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.6 on 2023-12-07 07:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("weblate_web", "0025_alter_subscription_options"), + ] + + operations = [ + migrations.AddField( + model_name="package", + name="limit_hosted_strings", + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name="report", + name="hosted_strings", + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name="service", + name="limit_hosted_strings", + field=models.IntegerField(default=0), + ), + ] diff --git a/weblate_web/models.py b/weblate_web/models.py index 97540a283b..7c3e046744 100644 --- a/weblate_web/models.py +++ b/weblate_web/models.py @@ -451,6 +451,7 @@ class Package(models.Model): limit_languages = models.IntegerField(default=0) limit_source_strings = models.IntegerField(default=0) limit_hosted_words = models.IntegerField(default=0) + limit_hosted_strings = models.IntegerField(default=0) class Meta: verbose_name = "Service package" @@ -489,6 +490,7 @@ class Service(models.Model): limit_projects = models.IntegerField(default=0) limit_source_strings = models.IntegerField(default=0) limit_hosted_words = models.IntegerField(default=0) + limit_hosted_strings = models.IntegerField(default=0) created = models.DateTimeField(auto_now_add=True) note = models.TextField(blank=True) hosted_billing = models.IntegerField(default=0, db_index=True) @@ -578,6 +580,16 @@ def hosted_words_limit(self): hosted_words_limit.short_description = "Hosted words" + def hosted_strings_limit(self): + report = self.last_report + if report: + if self.limit_hosted_strings: + return f"{report.hosted_strings}/{self.limit_hosted_strings}" + return f"{report.hosted_strings}" + return "0" + + hosted_strings_limit.short_description = "Hosted strings" + @cached_property def user_emails(self): return ", ".join(self.users.values_list("email", flat=True)) @@ -720,10 +732,12 @@ def update_status(self): status != self.status or package_obj.limit_source_strings != self.limit_source_strings or package_obj.limit_hosted_words != self.limit_hosted_words + or package_obj.limit_hosted_strings != self.limit_hosted_strings ): self.status = status self.limit_source_strings = package_obj.limit_source_strings self.limit_hosted_words = package_obj.limit_hosted_words + self.limit_hosted_strings = package_obj.limit_hosted_strings self.limit_languages = package_obj.limit_languages self.limit_projects = package_obj.limit_projects self.save() @@ -741,12 +755,18 @@ def create_backup(self): def get_limits(self): return { "hosted_words": self.limit_hosted_words, + "hosted_strings": self.limit_hosted_strings, "source_strings": self.limit_source_strings, "projects": self.limit_projects, "languages": self.limit_languages, } def check_in_limits(self): + if ( + self.limit_hosted_strings + and self.last_report.hosted_strings > self.limit_hosted_strings + ): + return False if ( self.limit_hosted_words and self.last_report.hosted_words > self.limit_hosted_words @@ -880,6 +900,7 @@ class Report(models.Model): components = models.IntegerField(default=0) languages = models.IntegerField(default=0) source_strings = models.IntegerField(default=0) + hosted_strings = models.IntegerField(default=0) hosted_words = models.IntegerField(default=0) timestamp = models.DateTimeField(auto_now_add=True) discoverable = models.BooleanField(default=False)