Skip to content

Commit 221566f

Browse files
committed
Move fuzzy version-matching pattern to constants
1 parent b5cd04c commit 221566f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

kobo/apps/reports/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
DEFAULT_REPORTS_KEY = 'default'
1010

1111
FUZZY_VERSION_ID_KEY = '_version_'
12-
INFERRED_VERSION_ID_KEY = '__inferred_version__'
12+
FUZZY_VERSION_PATTERN = r'^__?version__?(\d{3})?$'
13+
INFERRED_VERSION_ID_KEY = '__inferred_version__'

kpi/serializers/v2/asset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rest_framework.reverse import reverse
1010
from rest_framework.utils.serializer_helpers import ReturnList
1111

12+
from kobo.apps.reports.constants import FUZZY_VERSION_PATTERN
1213
from kobo.apps.reports.report_data import build_formpack
1314
from kpi.constants import (
1415
ASSET_STATUS_DISCOVERABLE,
@@ -509,11 +510,10 @@ def validate_data_sharing(self, data_sharing: dict) -> dict:
509510
# We do not want to include the version field.
510511
# See `_infer_version_id()` in `kobo.apps.reports.report_data.build_formpack`
511512
# for field name alternatives.
512-
version_pattern = r'^__?version__?(\d{3})?$'
513513
valid_fields = [
514514
f.path for f in form_pack.get_fields_for_versions(
515515
form_pack.versions.keys()
516-
) if not re.match(version_pattern, f.path)
516+
) if not re.match(FUZZY_VERSION_PATTERN, f.path)
517517
]
518518
unknown_fields = set(fields) - set(valid_fields)
519519
if unknown_fields and valid_fields:

kpi/serializers/v2/paired_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rest_framework import serializers
77
from rest_framework.reverse import reverse
88

9+
from kobo.apps.reports.constants import FUZZY_VERSION_PATTERN
910
from kobo.apps.reports.report_data import build_formpack
1011
from kpi.constants import (
1112
ASSET_TYPE_SURVEY,
@@ -134,11 +135,10 @@ def _validate_fields(self, attrs: dict):
134135
# We do not want to include the version field.
135136
# See `_infer_version_id()` in `kobo.apps.reports.report_data.build_formpack`
136137
# for field name alternatives.
137-
version_pattern = r'^__?version__?(\d{3})?$'
138138
valid_fields = [
139139
f.path for f in form_pack.get_fields_for_versions(
140140
form_pack.versions.keys()
141-
) if not re.match(version_pattern, f.path)
141+
) if not re.match(FUZZY_VERSION_PATTERN, f.path)
142142
]
143143

144144
source_fields = source.data_sharing.get('fields') or valid_fields

0 commit comments

Comments
 (0)