Skip to content

Commit

Permalink
manage: Show support package limits
Browse files Browse the repository at this point in the history
Fixes #9055
  • Loading branch information
nijel committed May 17, 2023
1 parent 9696227 commit 18a9a70
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
4 changes: 4 additions & 0 deletions weblate/static/style-bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,10 @@ h5.list-group-item-heading {
font-weight: bolder;
}

.table-supportstatus .progress {
min-width: 100px;
}

@-webkit-keyframes flags-updated {
0% {
background-color: rgba(255, 165, 0, 255);
Expand Down
24 changes: 19 additions & 5 deletions weblate/templates/manage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ <h4 class="panel-title">
{% trans "Weblate support status" %}
</h4>
</div>
<table class="table table-condensed table-striped">
<table class="table table-striped table-supportstatus">
<tr>
<th>{% trans "Weblate version" %}</th>
<td>
<td colspan="3">
{% if git_revision %}
{{ version }} — <a href="{{ git_revision_link }}">{{ git_revision }}</a>
{% elif git_revision_link %}
Expand All @@ -38,7 +38,7 @@ <h4 class="panel-title">
</tr>
<tr>
<th>{% trans "Support status" %}</th>
<td>
<td colspan="3">
<a href="" class="pull-right flip btn btn-link link-post" data-href="{% url 'manage-activate' %}" data-params='{"refresh":1}'>{% trans "Refresh support status" %}</a>
{{ support.get_verbose }}
{% if not support.in_limits %}
Expand All @@ -49,15 +49,29 @@ <h4 class="panel-title">
</td>
</tr>
{% if support.expiry %}
{% with support.get_limits_details as limit_details %}
{% if limit_details %}
<tr>
<th rowspan="{{ limit_details|length }}">{% trans "Support package limits" %}</th>
{% for limit in limit_details %}
{% if not forloop.first %}
<tr>
{% endif %}
<td>{{ limit.name }}</td>
{% include "billing/used.html" with max=limit.limit total=limit.limit used=limit.current %}
</tr>
{% endfor %}
{% endif %}
{% endwith %}
<tr>
<th>{% trans "Support expiry" %}</th>
<td>{{ support.expiry|naturaltime }}</td>
<td colspan="3">{{ support.expiry|naturaltime }}</td>
</tr>
{% endif %}
{% if support.secret %}
<tr>
<th>{% trans "Discover Weblate" %}</th>
<td>
<td colspan="3">
<a href="https://weblate.org/discover/" class="btn btn-link pull-right flip">{% trans "Browse discovery" %}</a>
{% if support.discoverable %}
{% trans "Your Weblate is listed on weblate.org" %}
Expand Down
24 changes: 24 additions & 0 deletions weblate/wladmin/migrations/0007_supportstatus_limits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.1 on 2023-05-17 12:18

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"wladmin",
"0006_rename_configurationerror_ignored_timestamp_wladmin_con_ignored_fb498d_idx",
),
]

operations = [
migrations.AddField(
model_name="supportstatus",
name="limits",
field=models.JSONField(default=dict),
),
]
31 changes: 31 additions & 0 deletions weblate/wladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SupportStatus(models.Model):
expiry = models.DateTimeField(db_index=True, null=True)
in_limits = models.BooleanField(default=True)
discoverable = models.BooleanField(default=False)
limits = models.JSONField(default=dict)

objects = SupportStatusManager()

Expand Down Expand Up @@ -136,13 +137,43 @@ def refresh(self):
self.name = payload["name"]
self.expiry = dateutil.parser.parse(payload["expiry"])
self.in_limits = payload["in_limits"]
self.limits = payload["limits"]
if payload["backup_repository"]:
BackupService.objects.get_or_create(
repository=payload["backup_repository"], defaults={"enabled": False}
)
# Invalidate support status cache
cache.delete(SUPPORT_STATUS_CACHE_KEY)

def get_limits_details(self):
stats = GlobalStats()
current_values = {
"hosted_words": stats.all_words,
"source_strings": stats.source_strings,
"projects": Project.objects.count(),
"languages": stats.languages,
}
names = {
"hosted_words": gettext_lazy("Hosted words"),
"source_strings": gettext_lazy("Source strings"),
"projects": gettext_lazy("Projects"),
"languages": gettext_lazy("Languages"),
}
result = []
for limit, value in self.limits.items():
if not value or limit not in names:
continue
current = current_values[limit]
result.append(
{
"name": names[limit],
"limit": value,
"current": current,
"in_limit": current < value,
}
)
return result


class BackupService(models.Model):
repository = models.CharField(
Expand Down

0 comments on commit 18a9a70

Please sign in to comment.