From 8862f6777728b3c84362d9a1b4e23d41cf7d7c31 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 25 Feb 2018 16:15:29 +0100 Subject: [PATCH] Allow to override a navbar link for each language ref issue #1 --- .../0004_elementdescription_link_override.py | 18 ++++++++++++++++++ navbar/models.py | 13 ++++++++++++- navbar/templates/navbar/navbar.html | 6 +++--- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 navbar/migrations/0004_elementdescription_link_override.py 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 @@