- tag, created = Tag.objects.get_or_create(
- slug=slughifi(theme_name),
- category='theme')
- if created:
- tag.name = theme_name
- tag.sort_key = sortify(theme_name.lower())
- tag.save()
- themes.append(tag)
+ if lang == settings.LANGUAGE_CODE:
+ # Allow creating themes if book in default language.
+ tag, created = Tag.objects.get_or_create(
+ slug=slughifi(theme_name),
+ category='theme')
+ if created:
+ tag.name = theme_name
+ setattr(tag, "name_%s" % lang, theme_name)
+ tag.sort_key = sortify(theme_name.lower())
+ tag.save()
+ themes.append(tag)
+ elif lang is not None:
+ # Don't create unknown themes in non-default languages.
+ try:
+ tag = Tag.objects.get(category='theme',
+ **{"name_%s" % lang: theme_name})
+ except Tag.DoesNotExist:
+ pass
+ else:
+ themes.append(tag)