Skip to content

Commit

Permalink
#1047 add default values for additional input for options
Browse files Browse the repository at this point in the history
* prepare option model to contain default_text
* add default_text to imports, mixins, option and export serializer
* add migrations
* add translations
* insert Tabs structure for display default text values in EditOption component
  • Loading branch information
CalamityC committed Jul 11, 2024
1 parent b5a46ba commit 4ef627e
Show file tree
Hide file tree
Showing 16 changed files with 2,958 additions and 1,738 deletions.
Binary file modified rdmo/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
543 changes: 334 additions & 209 deletions rdmo/locale/de/LC_MESSAGES/django.po

Large diffs are not rendered by default.

Binary file modified rdmo/locale/es/LC_MESSAGES/django.mo
Binary file not shown.
541 changes: 336 additions & 205 deletions rdmo/locale/es/LC_MESSAGES/django.po

Large diffs are not rendered by default.

Binary file modified rdmo/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
2,948 changes: 1,828 additions & 1,120 deletions rdmo/locale/fr/LC_MESSAGES/django.po

Large diffs are not rendered by default.

Binary file modified rdmo/locale/it/LC_MESSAGES/django.mo
Binary file not shown.
540 changes: 336 additions & 204 deletions rdmo/locale/it/LC_MESSAGES/django.po

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions rdmo/management/assets/js/components/edit/EditOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ const EditOption = ({ config, option, elements, elementActions }) => {

<Radio config={config} element={option} field="additional_input"
options={additionalInputs} onChange={updateOption} />
{
(option.additional_input === 'text' || option.additional_input === 'textarea') &&
config.settings &&
<Tabs id="#option-tabs2" defaultActiveKey={0} animation={false}>
{config.settings.languages.map(([lang_code, lang], index) => (
<Tab key={index} eventKey={index} title={lang}>
<Textarea key={index} config={config} element={option} field={`default_text_${lang_code}`}
rows={1} onChange={updateOption} />
</Tab>

))}
</Tabs>
}

{get(config, 'settings.multisite') && <Select config={config} element={option} field="editors"
options={sites} onChange={updateOption} isMulti />}
Expand Down
1 change: 1 addition & 0 deletions rdmo/options/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def import_option(element, save=False, user=None):

set_lang_field(option, 'text', element)
set_lang_field(option, 'help', element)
set_lang_field(option, 'default_text', element)
set_lang_field(option, 'view_text', element)

validate_instance(option, element, OptionLockedValidator, OptionUniqueURIValidator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.13 on 2024-07-11 11:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('options', '0035_alter_help_text_and_set_default'),
]

operations = [
migrations.AddField(
model_name='option',
name='default_text_lang1',
field=models.TextField(blank=True, default='', help_text='The default text value for this option (in the primary language).', verbose_name='Default text value (primary)'),
),
migrations.AddField(
model_name='option',
name='default_text_lang2',
field=models.TextField(blank=True, default='', help_text='The default text value for this option (in the secondary language).', verbose_name='Default text value (secondary)'),
),
migrations.AddField(
model_name='option',
name='default_text_lang3',
field=models.TextField(blank=True, default='', help_text='The default text value for this option (in the tertiary language).', verbose_name='Default text value (tertiary)'),
),
migrations.AddField(
model_name='option',
name='default_text_lang4',
field=models.TextField(blank=True, default='', help_text='The default text value for this option (in the quaternary language).', verbose_name='Default text value (quaternary)'),
),
migrations.AddField(
model_name='option',
name='default_text_lang5',
field=models.TextField(blank=True, default='', help_text='The default text value for this option (in the quinary language).', verbose_name='Default text value (quinary)'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.13 on 2024-07-11 12:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('options', '0036_option_default_text_lang1_option_default_text_lang2_and_more'),
]

operations = [
migrations.AlterField(
model_name='option',
name='default_text_lang1',
field=models.TextField(blank=True, default='', help_text='The default text value for the additional input of this option (in the primary language).', verbose_name='Default text value (primary)'),
),
migrations.AlterField(
model_name='option',
name='default_text_lang2',
field=models.TextField(blank=True, default='', help_text='The default text value for the additional input of this option (in the secondary language).', verbose_name='Default text value (secondary)'),
),
migrations.AlterField(
model_name='option',
name='default_text_lang3',
field=models.TextField(blank=True, default='', help_text='The default text value for the additional input of this option (in the tertiary language).', verbose_name='Default text value (tertiary)'),
),
migrations.AlterField(
model_name='option',
name='default_text_lang4',
field=models.TextField(blank=True, default='', help_text='The default text value for the additional input of this option (in the quaternary language).', verbose_name='Default text value (quaternary)'),
),
migrations.AlterField(
model_name='option',
name='default_text_lang5',
field=models.TextField(blank=True, default='', help_text='The default text value for the additional input of this option (in the quinary language).', verbose_name='Default text value (quinary)'),
),
]
29 changes: 29 additions & 0 deletions rdmo/options/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ class Option(models.Model, TranslationMixin):
verbose_name=_('Help (quinary)'),
help_text=_('The help text for this option (in the quinary language).')
)
default_text_lang1 = models.TextField(
blank=True, default="",
verbose_name=_('Default text value (primary)'),
help_text=_('The default text value for the additional input of this option (in the primary language).')
)
default_text_lang2 = models.TextField(
blank=True, default="",
verbose_name=_('Default text value (secondary)'),
help_text=_('The default text value for the additional input of this option (in the secondary language).')
)
default_text_lang3 = models.TextField(
blank=True, default="",
verbose_name=_('Default text value (tertiary)'),
help_text=_('The default text value for the additional input of this option (in the tertiary language).')
)
default_text_lang4 = models.TextField(
blank=True, default="",
verbose_name=_('Default text value (quaternary)'),
help_text=_('The default text value for the additional input of this option (in the quaternary language).')
)
default_text_lang5 = models.TextField(
blank=True, default="",
verbose_name=_('Default text value (quinary)'),
help_text=_('The default text value for the additional input of this option (in the quinary language).')
)
view_text_lang1 = models.TextField(
blank=True, default="",
verbose_name=_('View text (primary)'),
Expand Down Expand Up @@ -287,6 +312,10 @@ def text(self):
def help(self):
return self.trans('help')

@property
def default_text(self):
return self.trans('default_text')

@property
def view_text(self):
return self.trans('view_text')
Expand Down
2 changes: 2 additions & 0 deletions rdmo/options/renderers/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def render_option(self, xml, option):
for lang_code, lang_string, lang_field in get_languages():
self.render_text_element(xml, 'text', {'lang': lang_code}, option['text_%s' % lang_code])
self.render_text_element(xml, 'help', {'lang': lang_code}, option['help_%s' % lang_code])
self.render_text_element(xml, 'default_text', {'lang': lang_code},
option['default_text_%s' % lang_code])
self.render_text_element(xml, 'view_text', {'lang': lang_code}, option['view_text_%s' % lang_code])

self.render_text_element(xml, 'additional_input', {}, option['additional_input'])
Expand Down
1 change: 1 addition & 0 deletions rdmo/options/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Meta:
trans_fields = (
'text',
'help',
'default_text',
'view_text'
)

Expand Down
2 changes: 2 additions & 0 deletions rdmo/options/serializers/v1/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Meta:
'locked',
'text',
'help',
'default_text',
'view_text',
'label',
'additional_input',
Expand All @@ -54,6 +55,7 @@ class Meta:
trans_fields = (
'text',
'help',
'default_text',
'view_text'
)
parent_fields = (
Expand Down

0 comments on commit 4ef627e

Please sign in to comment.