diff --git a/navbar/migrations/0004_elementdescription_link_override.py b/navbar/migrations/0004_elementdescription_link_override.py new file mode 100644 index 0000000..6ae193c --- /dev/null +++ b/navbar/migrations/0004_elementdescription_link_override.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-25 13:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('navbar', '0003_auto_20180204_2035'), + ] + + operations = [ + migrations.AddField( + model_name='elementdescription', + name='link_override', + field=models.CharField(blank=True, max_length=512), + ), + ] diff --git a/navbar/models.py b/navbar/models.py index 6f6f62e..d737e31 100644 --- a/navbar/models.py +++ b/navbar/models.py @@ -37,11 +37,21 @@ class Element(models.Model): ) def description(self): + lang = get_language() + if lang is None: + lang = settings.LANGUAGE_CODE return ElementDescription.objects.filter( element=self.id, - language=get_language() + language=lang ).first() + def localized_link(self): + link = self.link + desc = self.description() + if desc.link_override: + link = desc.link_override + return link + def __str__(self): desc = self.description() return desc.short_name if desc is not None else self.link @@ -53,6 +63,7 @@ class ElementDescription(models.Model): short_name = models.CharField(max_length=32) full_name = models.CharField(max_length=64, blank=True) description = models.CharField(max_length=512, blank=True) + link_override = models.CharField(max_length=512, blank=True) def is_separator(self): return False diff --git a/navbar/templates/navbar/navbar.html b/navbar/templates/navbar/navbar.html index c2f2cfa..256bfc4 100644 --- a/navbar/templates/navbar/navbar.html +++ b/navbar/templates/navbar/navbar.html @@ -8,9 +8,9 @@