Coverage for app/venv/lib/python3.14/site-packages/weblate/metrics/migrations/0002_new_public_projects_metric_data.py: 81%
14 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5# Generated by Django 5.0.6 on 2024-07-24 06:27
6from django.db import migrations
9def insert_public_project_data_in_latest_metric(apps, schema_editor) -> None:
10 access_public = 0
11 access_protected = 1
12 scope_global = 0
14 Metric = apps.get_model("metrics", "Metric")
15 Project = apps.get_model("trans", "Project")
16 public_projects_count = Project.objects.filter(
17 access_control__in={access_public, access_protected}
18 ).count()
20 # tests will not have Metric objects
21 if ( 21 ↛ 26line 21 didn't jump to line 26 because the condition on line 21 was never true
22 latest_global_metric := Metric.objects.filter(scope=scope_global)
23 .order_by("date")
24 .last()
25 ) and len(latest_global_metric.data) == 27:
26 latest_global_metric.data.append(public_projects_count)
27 latest_global_metric.save()
30class Migration(migrations.Migration):
31 dependencies = [
32 ("metrics", "0001_squashed_weblate_5"),
33 ]
35 operations = [
36 migrations.RunPython(
37 insert_public_project_data_in_latest_metric,
38 migrations.RunPython.noop,
39 elidable=True,
40 ),
41 ]