1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.db import models
5 from django.utils.translation import ugettext_lazy as _
8 class ButtonGroup(models.Model):
9 name = models.CharField(max_length=32)
10 slug = models.SlugField()
11 position = models.IntegerField(default=0)
14 ordering = ('position', 'name',)
15 verbose_name, verbose_name_plural = _('button group'), _('button groups')
20 def to_dict(self, with_buttons=False):
21 d = {'name': self.name, 'position': self.position}
24 d['buttons'] = [b.to_dict() for b in self.button_set.all()]
29 class Button(models.Model):
30 label = models.CharField(max_length=32)
31 slug = models.SlugField(unique=True) # unused
34 params = models.TextField(default='[]') # TODO: should be a JSON field
35 scriptlet = models.ForeignKey('Scriptlet', models.SET_NULL, null=True, blank=True)
36 link = models.CharField(max_length=256, blank=True, default='')
39 accesskey = models.CharField(blank=True, max_length=1)
41 tooltip = models.CharField(blank=True, max_length=120)
43 # Why the button is restricted to have the same position in each group ?
44 # position = models.IntegerField(default=0)
45 group = models.ManyToManyField(ButtonGroup)
49 verbose_name, verbose_name_plural = _('button'), _('buttons')
52 def full_tooltip(self):
53 return u"%s %s" % (self.tooltip, "[Alt+%s]" % self.accesskey if self.accesskey else "")
58 'tooltip': self.tooltip,
59 'accesskey': self.accesskey,
60 'params': self.params,
61 'scriptlet_id': self.scriptlet_id,
68 class Scriptlet(models.Model):
69 name = models.CharField(max_length=64, primary_key=True)
70 code = models.TextField()
73 return _(u'javascript') + u':' + self.name