Skip to content

Commit

Permalink
collect hosted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Dec 7, 2023
1 parent 3685300 commit a10f165
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions weblate_web/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ServiceAdmin(admin.ModelAdmin):
"languages_limit",
"source_strings_limit",
"hosted_words_limit",
"hosted_strings_limit",
"status",
"user_emails",
"expires",
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
21 changes: 21 additions & 0 deletions weblate_web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a10f165

Please sign in to comment.