2018-01-21 12:44:00 +00:00
|
|
|
from django.utils.translation import get_language
|
|
|
|
from django.conf import settings
|
|
|
|
from django.db import models
|
|
|
|
import os
|
|
|
|
|
2018-01-27 22:12:09 +00:00
|
|
|
|
2018-01-21 12:44:00 +00:00
|
|
|
class Element(models.Model):
|
2018-01-27 22:12:09 +00:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
'Element',
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
null=True,
|
|
|
|
blank=True
|
|
|
|
)
|
2018-01-21 12:44:00 +00:00
|
|
|
link = models.CharField(max_length=512, blank=True)
|
|
|
|
new_window = models.BooleanField(default=False)
|
2018-01-27 22:12:09 +00:00
|
|
|
icon = models.FilePathField(
|
|
|
|
path=os.path.join(settings.BASE_DIR, 'navbar/static/icons'),
|
|
|
|
match=".png",
|
|
|
|
null=True,
|
|
|
|
blank=True
|
|
|
|
)
|
2018-01-21 12:44:00 +00:00
|
|
|
weight = models.PositiveSmallIntegerField()
|
|
|
|
|
|
|
|
def icon_path(self):
|
|
|
|
return os.path.join('icons', os.path.basename(self.icon))
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
return Element.objects.filter(parent=self.id).order_by('weight')
|
|
|
|
|
|
|
|
def description(self):
|
2018-01-27 22:12:09 +00:00
|
|
|
return ElementDescription.objects.filter(
|
|
|
|
element=self.id,
|
|
|
|
language=get_language()
|
|
|
|
).first()
|
2018-01-21 12:44:00 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
desc = self.description()
|
|
|
|
return desc.short_name if desc is not None else self.link
|
|
|
|
|
2018-01-27 22:12:09 +00:00
|
|
|
|
2018-01-21 12:44:00 +00:00
|
|
|
class ElementDescription(models.Model):
|
|
|
|
element = models.ForeignKey(Element, on_delete=models.CASCADE)
|
|
|
|
language = models.CharField(max_length=10, choices=settings.LANGUAGES)
|
|
|
|
short_name = models.CharField(max_length=32)
|
|
|
|
full_name = models.CharField(max_length=64, blank=True)
|
|
|
|
description = models.CharField(max_length=512, blank=True)
|