Skip to content

Conversation

@ifoughal
Copy link

Fixes: #20731

During bulk import of config templates, it is not possible to set a data-source with data-file for the config-templates to be imported.

The change adds 3 additional fields to template_code as optional fields:

  • data_source
  • data_file
  • auto_sync_enabled

@jeremystretch jeremystretch requested review from a team and jeremystretch and removed request for a team November 10, 2025 14:37
@jeremystretch
Copy link
Member

@ifoughal could you address the linter errors please?

@ifoughal
Copy link
Author

@jeremystretch I have fixed the linter issues.

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality is there, but please avoid making changes that deviate from the established style or that modify components out of scope for the PR.

from django.contrib.postgres.forms import SimpleArrayField
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import gettext_lazy as _

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

from utilities.forms import CSVModelForm
from utilities.forms.fields import (
CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, CSVModelMultipleChoiceField, CSVMultipleChoiceField,
CSVMultipleContentTypeField, SlugField,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

CSVMultipleContentTypeField, SlugField,
CSVMultipleContentTypeField, SlugField
)
from core.models import DataSource, DataFile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine with line 9 above

model = ExportTemplate
fields = (
'name', 'object_types', 'description', 'environment_params', 'mime_type', 'file_name', 'file_extension',
'name', 'object_types', 'description', 'environment_params',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert (this class isn't even in scope for the FR)

CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, CSVModelMultipleChoiceField, CSVMultipleChoiceField,
CSVMultipleContentTypeField, SlugField,
CSVMultipleContentTypeField, SlugField
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

queryset=DataFile.objects.all(),
required=False,
to_field_name='path',
help_text=_('DataFile containing the template code')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help_text should be human-friendly

Suggested change
help_text=_('DataFile containing the template code')
help_text=_('Data file containing the template code')

auto_sync_enabled = forms.BooleanField(
required=False,
label=_('auto sync enabled'),
help_text=_("Enable automatic synchronization of data when the data file is updated")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help_text=_("Enable automatic synchronization of data when the data file is updated")
help_text=_("Enable automatic synchronization of template content when the data file is updated")

queryset=DataSource.objects.all(),
required=False,
to_field_name='name',
help_text=_('data_source of the config template')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help_text=_('data_source of the config template')
help_text=_('Data source which provides the data file')

Comment on lines +200 to +205
def clean_template_code(self):
# Make sure template_code is None when it's not included in the uploaded data
if not self.data.get('template_code') and not self.data.get('data_file'):
raise forms.ValidationError(_("Must specify either local content or a data file"))

return self.cleaned_data['template_code']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should be run under the form's clean() method as it involves more than one field.

Comment on lines +207 to +211
def clean_auto_sync_enabled(self):
# Make sure is_primary is None when it's not included in the uploaded data
if not self.data.get('auto_sync_enabled'):
self.cleaned_data['auto_sync_enabled'] = False
return self.cleaned_data['auto_sync_enabled']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not appear to be needed, as auto_sync_enabled is a boolean field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bulk import of config template missing data_source & data_file fields

2 participants