diff --git a/apis_ontology/models.py b/apis_ontology/models.py index f3e01d4..5bf9d1a 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -7,6 +7,7 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from multiselectfield import MultiSelectField +import re @reversion.register @@ -143,6 +144,19 @@ class TitlesMixin(models.Model): class Meta: abstract = True + def full_title(self): + full_title = self.title + subtitle = self.subtitle + letter_or_digit = re.compile(r"[\W\d]", re.U) + + if subtitle: + if letter_or_digit.match(subtitle[0]): + full_title += f" {subtitle}" + else: + full_title += f". {subtitle}" + + return full_title + @reversion.register class DataSource(models.Model): diff --git a/apis_ontology/tables.py b/apis_ontology/tables.py index c7507e1..54b63b4 100644 --- a/apis_ontology/tables.py +++ b/apis_ontology/tables.py @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs): class FullTitleMixin(tables.Table): full_title = GenericEditLinkColumn( - accessor="title", + accessor="full_title", verbose_name=_("Titel (gesamt)"), order_by=("title", "subtitle"), ) @@ -46,15 +46,6 @@ class Meta: sequence = ("full_title", "title", "subtitle") exclude = ["title", "subtitle"] - def render_full_title(self, record): - full_title = record.title - subtitle = record.subtitle - - if subtitle: - full_title += f". {subtitle}" - - return full_title - class FullNameMixin(tables.Table): full_name = GenericEditLinkColumn(