-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 [#1451] -- Add management command to check for template tag usage
- Loading branch information
1 parent
62121f7
commit ffbbe30
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/openforms/utils/management/commands/detect_deprecated_tags_usage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Tuple | ||
|
||
from django.apps import apps | ||
from django.core.management import BaseCommand | ||
|
||
DEPRECATED_TAGS = ("{% display_value",) | ||
|
||
|
||
MODELS_AND_FIELDS = ( | ||
( | ||
"config.GlobalConfiguration", | ||
( | ||
"submission_confirmation_template", | ||
"confirmation_email_subject", | ||
"confirmation_email_content", | ||
), | ||
), | ||
( | ||
"forms.Form", | ||
( | ||
"submission_confirmation_template", | ||
"explanation_template", | ||
), | ||
), | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Detect deprecated template tag usage in user-templates" | ||
|
||
def handle(self, **options): | ||
for model, fields in MODELS_AND_FIELDS: | ||
self.check_model(model, fields) | ||
|
||
self.stdout.write("Done checking.") | ||
|
||
def check_model(self, model: str, fields: Tuple[str]): | ||
model_cls = apps.get_model(model) | ||
|
||
for tag in DEPRECATED_TAGS: | ||
filters = {f"{field}__contains": tag for field in fields} | ||
queryset = model_cls.objects.filter(**filters).values_list("id", flat=True) | ||
if not queryset: | ||
continue | ||
self.stdout.write( | ||
f"Model {model} instances containing deprecated tag '{tag}': {', '.join(queryset)}" | ||
) |