Skip to content

Commit

Permalink
Add short_title for navigation to section and page (#346, #363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jun 20, 2024
1 parent 13e342b commit ff6e0a3
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rdmo/management/assets/js/components/edit/EditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const EditPage = ({ config, page, elements, elementActions }) => {
<Tab key={index} eventKey={index} title={lang}>
<Text config={config} element={page} field={`title_${lang_code }`}
onChange={updatePage} />
<Text config={config} element={page} field={`short_title_${lang_code }`}
onChange={updatePage} />
<Textarea config={config} element={page} field={`help_${lang_code }`}
rows={4} onChange={updatePage} />
<Text config={config} element={page} field={`verbose_name_${lang_code }`}
Expand Down
2 changes: 2 additions & 0 deletions rdmo/management/assets/js/components/edit/EditSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const EditSection = ({ config, section, elements, elementActions }) => {
<Tab key={index} eventKey={index} title={lang}>
<Text config={config} element={section} field={`title_${lang_code }`}
onChange={updateSection} />
<Text config={config} element={section} field={`short_title_${lang_code }`}
onChange={updateSection} />
</Tab>
))
}
Expand Down
4 changes: 2 additions & 2 deletions rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def compute_navigation(section, project, snapshot=None):
navigation_section = {
'id': catalog_section.id,
'uri': catalog_section.uri,
'title': catalog_section.title,
'title': catalog_section.short_title or catalog_section.title,
'first': catalog_section.elements[0].id if catalog_section.elements else None
}
if catalog_section.id == section.id:
Expand All @@ -71,7 +71,7 @@ def compute_navigation(section, project, snapshot=None):
navigation_section['pages'].append({
'id': page.id,
'uri': page.uri,
'title': page.title,
'title': page.short_title or page.title,
'show': show,
'count': count,
'total': total
Expand Down
38 changes: 38 additions & 0 deletions rdmo/questions/migrations/0094_section_short_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.8 on 2024-06-06 15:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0093_alter_help_text_and_set_default'),
]

operations = [
migrations.AddField(
model_name='section',
name='short_title_lang1',
field=models.CharField(blank=True, help_text='The short title for this section (in the primary language), used in the navigation.', max_length=32, verbose_name='Short title (primary)'),
),
migrations.AddField(
model_name='section',
name='short_title_lang2',
field=models.CharField(blank=True, help_text='The short title for this section (in the secondary language), used in the navigation.', max_length=32, verbose_name='Short title (secondary)'),
),
migrations.AddField(
model_name='section',
name='short_title_lang3',
field=models.CharField(blank=True, help_text='The short title for this section (in the tertiary language), used in the navigation.', max_length=32, verbose_name='Short title (tertiary)'),
),
migrations.AddField(
model_name='section',
name='short_title_lang4',
field=models.CharField(blank=True, help_text='The short title for this section (in the quaternary language), used in the navigation.', max_length=32, verbose_name='Short title (quaternary)'),
),
migrations.AddField(
model_name='section',
name='short_title_lang5',
field=models.CharField(blank=True, help_text='The short title for this section (in the quinary language), used in the navigation.', max_length=32, verbose_name='Short title (quinary)'),
),
]
38 changes: 38 additions & 0 deletions rdmo/questions/migrations/0095_page_short_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.8 on 2024-06-06 15:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0094_section_short_title'),
]

operations = [
migrations.AddField(
model_name='page',
name='short_title_lang1',
field=models.CharField(blank=True, help_text='The short title for this page (in the primary language), used in the navigation.', max_length=32, verbose_name='Short title (primary)'),
),
migrations.AddField(
model_name='page',
name='short_title_lang2',
field=models.CharField(blank=True, help_text='The short title for this page (in the secondary language), used in the navigation.', max_length=32, verbose_name='Short title (secondary)'),
),
migrations.AddField(
model_name='page',
name='short_title_lang3',
field=models.CharField(blank=True, help_text='The short title for this page (in the tertiary language), used in the navigation.', max_length=32, verbose_name='Short title (tertiary)'),
),
migrations.AddField(
model_name='page',
name='short_title_lang4',
field=models.CharField(blank=True, help_text='The short title for this page (in the quaternary language), used in the navigation.', max_length=32, verbose_name='Short title (quaternary)'),
),
migrations.AddField(
model_name='page',
name='short_title_lang5',
field=models.CharField(blank=True, help_text='The short title for this page (in the quinary language), used in the navigation.', max_length=32, verbose_name='Short title (quinary)'),
),
]
30 changes: 30 additions & 0 deletions rdmo/questions/models/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ class Page(Model, TranslationMixin):
verbose_name=_('Title (quinary)'),
help_text=_('The title for this page (in the quinary language).')
)
short_title_lang1 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (primary)'),
help_text=_('The short title for this page (in the primary language), used in the navigation.')
)
short_title_lang2 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (secondary)'),
help_text=_('The short title for this page (in the secondary language), used in the navigation.')
)
short_title_lang3 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (tertiary)'),
help_text=_('The short title for this page (in the tertiary language), used in the navigation.')
)
short_title_lang4 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (quaternary)'),
help_text=_('The short title for this page (in the quaternary language), used in the navigation.')
)
short_title_lang5 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (quinary)'),
help_text=_('The short title for this page (in the quinary language), used in the navigation.')
)
help_lang1 = models.TextField(
blank=True,
verbose_name=_('Help (primary)'),
Expand Down Expand Up @@ -178,6 +203,10 @@ def save(self, *args, **kwargs):
def title(self):
return self.trans('title')

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

@property
def help(self):
return self.trans('help')
Expand Down Expand Up @@ -214,6 +243,7 @@ def to_dict(self):
'id': self.id,
'uri': self.uri,
'title': self.title,
'short_title': self.short_title,
'is_collection': self.is_collection,
'attribute': self.attribute.uri if self.attribute else None,
'conditions': [condition.uri for condition in self.conditions.all()],
Expand Down
30 changes: 30 additions & 0 deletions rdmo/questions/models/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ class Section(Model, TranslationMixin):
verbose_name=_('Title (quinary)'),
help_text=_('The title for this section (in the quinary language).')
)
short_title_lang1 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (primary)'),
help_text=_('The short title for this section (in the primary language), used in the navigation.')
)
short_title_lang2 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (secondary)'),
help_text=_('The short title for this section (in the secondary language), used in the navigation.')
)
short_title_lang3 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (tertiary)'),
help_text=_('The short title for this section (in the tertiary language), used in the navigation.')
)
short_title_lang4 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (quaternary)'),
help_text=_('The short title for this section (in the quaternary language), used in the navigation.')
)
short_title_lang5 = models.CharField(
max_length=32, blank=True,
verbose_name=_('Short title (quinary)'),
help_text=_('The short title for this section (in the quinary language), used in the navigation.')
)

class Meta:
ordering = ('uri', )
Expand All @@ -106,6 +131,10 @@ def save(self, *args, **kwargs):
def title(self):
return self.trans('title')

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

@cached_property
def is_locked(self):
return self.locked or any(catalog.is_locked for catalog in self.catalogs.all())
Expand All @@ -131,6 +160,7 @@ def to_dict(self):
'id': self.id,
'uri': self.uri,
'title': self.title,
'short_title': self.short_title,
'elements': elements,
'pages': elements
}
Expand Down
2 changes: 2 additions & 0 deletions rdmo/questions/serializers/v1/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Meta:
'attribute',
'is_collection',
'title',
'short_title',
'help',
'verbose_name',
'sections',
Expand All @@ -78,6 +79,7 @@ class Meta:
)
trans_fields = (
'title',
'short_title',
'help',
'verbose_name'
)
Expand Down
2 changes: 2 additions & 0 deletions rdmo/questions/serializers/v1/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Meta:
'comment',
'locked',
'title',
'short_title',
'catalogs',
'pages',
'editors',
Expand All @@ -55,6 +56,7 @@ class Meta:
)
trans_fields = (
'title',
'short_title'
)
parent_fields = (
('catalogs', 'catalog', 'section', 'catalog_sections'),
Expand Down

0 comments on commit ff6e0a3

Please sign in to comment.