Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion app/eventyay/control/forms/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@
class EventWizardFoundationForm(forms.Form):
locales = forms.MultipleChoiceField(
choices=settings.LANGUAGES,
label=_('Use languages'),
label=_('Active languages'),
widget=MultipleLanguagesWidget,
help_text=_('Choose all languages that your event should be available in.'),
)
content_locales = forms.MultipleChoiceField(
choices=settings.LANGUAGES,
label=_('Content languages'),
widget=MultipleLanguagesWidget,
required=False,
help_text=_('Users will be able to submit proposals in these languages.'),
)
has_subevents = forms.BooleanField(
label=_('This is an event series'),
required=False,
Expand Down Expand Up @@ -99,6 +106,25 @@ def __init__(self, *args, **kwargs):
self.fields['organizer'].initial = qs.first()
self.fields['organizer'].required = False

def clean(self):
cleaned_data = super().clean()
locales = cleaned_data.get('locales', [])
content_locales = cleaned_data.get('content_locales')

assert isinstance(locales, list)

if content_locales is None or not content_locales:
return cleaned_data

assert isinstance(content_locales, list)
Comment on lines +114 to +119
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

Using assertions for runtime validation is inappropriate. Assertions can be disabled with Python's -O flag and are meant for debugging, not user input validation. Replace with proper error handling that raises a ValidationError with a clear message if the type check fails.

Suggested change
assert isinstance(locales, list)
if content_locales is None or not content_locales:
return cleaned_data
assert isinstance(content_locales, list)
if not isinstance(locales, list):
raise ValidationError({'locales': _('Active languages data is invalid.')})
if content_locales is None or not content_locales:
return cleaned_data
if not isinstance(content_locales, list):
raise ValidationError({'content_locales': _('Content languages data is invalid.')})

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

@hongquan shall I revert it back then

Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

Using assertions for runtime validation is inappropriate. Assertions can be disabled with Python's -O flag and are meant for debugging, not user input validation. Replace with proper error handling that raises a ValidationError with a clear message if the type check fails.

Suggested change
assert isinstance(content_locales, list)
if not isinstance(content_locales, list):
raise ValidationError({
'content_locales': _('Content languages must be provided as a list.')
})

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

here too


if invalid_content_locales := set(content_locales) - set(locales):
raise ValidationError({
'content_locales': _('Content languages must be a subset of the active languages.')
})

return cleaned_data


class EventWizardBasicsForm(I18nModelForm):
error_messages = {
Expand Down Expand Up @@ -169,6 +195,7 @@ def __init__(self, *args, **kwargs):
self.is_video_creation = kwargs.pop('is_video_creation')
self.user = kwargs.pop('user')
kwargs.pop('session')
kwargs.pop('content_locales', None)
super().__init__(*args, **kwargs)
if 'timezone' not in self.initial:
self.initial['timezone'] = get_current_timezone_name()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@
</div>
</div>
</div>
{% bootstrap_field form.locales layout="horizontal" %}
<fieldset>
<legend>{% trans "Localization" %}</legend>
{% bootstrap_field form.locales layout="horizontal" %}
{% bootstrap_field form.content_locales layout="horizontal" %}
</fieldset>
{% endblock %}
6 changes: 4 additions & 2 deletions app/eventyay/eventyay_common/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def get_form_initial(self, step):
if step == 'foundation':
initial_form['is_video_creation'] = True
initial_form['locales'] = ['en']
initial_form['content_locales'] = ['en']
initial_form['create_for'] = EventCreatedFor.BOTH
if 'organizer' in request_get:
try:
Expand Down Expand Up @@ -265,7 +266,8 @@ def done(self, form_list, form_dict, **kwargs):
event.settings.set('timezone', basics_data['timezone'])
event.settings.set('locale', basics_data['locale'])
event.settings.set('locales', foundation_data['locales'])
event.settings.set('content_locales', foundation_data['locales'])
content_locales = foundation_data.get('content_locales') or foundation_data['locales']
event.settings.set('content_locales', content_locales)

# Use the selected create_for option, but ensure smart defaults work for all
create_for = self.storage.extra_data.get('create_for', EventCreatedFor.BOTH)
Expand All @@ -283,7 +285,7 @@ def done(self, form_list, form_dict, **kwargs):
'timezone': str(basics_data.get('timezone')),
'locale': event.settings.locale,
'locales': event.settings.locales,
'content_locales': event.settings.get('content_locales', as_type=list),
'content_locales': content_locales,
'is_video_creation': final_is_video_creation,
}

Expand Down