1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django.db import models
7 from django.utils.translation import ugettext_lazy as _
10 class ButtonGroup(models.Model):
11 name = models.CharField(max_length=32)
12 slug = models.SlugField()
13 position = models.IntegerField(default=0)
16 ordering = ('position', 'name',)
17 verbose_name, verbose_name_plural = _('button group'), _('button groups')
19 def __unicode__(self):
22 def to_dict(self, with_buttons=False):
23 d = {'name': self.name, 'position': self.position}
26 d['buttons'] = [b.to_dict() for b in self.button_set.all()]
31 class Button(models.Model):
32 label = models.CharField(max_length=32)
33 slug = models.SlugField(unique=True) # unused
36 params = models.TextField(default='[]') # TODO: should be a JSON field
37 scriptlet = models.ForeignKey('Scriptlet', null=True, blank=True)
38 link = models.CharField(max_length=256, blank=True, default='')
41 accesskey = models.CharField(null=True, max_length=1)
43 tooltip = models.CharField(blank=True, max_length=120)
45 # Why the button is restricted to have the same position in each group ?
46 # position = models.IntegerField(default=0)
47 group = models.ManyToManyField(ButtonGroup)
51 verbose_name, verbose_name_plural = _('button'), _('buttons')
54 def full_tooltip(self):
55 return u"%s %s" % (self.tooltip, "[Alt+%s]" % self.accesskey if self.accesskey else "")
60 'tooltip': self.tooltip,
61 'accesskey': self.accesskey,
62 'params': self.params,
63 'scriptlet_id': self.scriptlet_id,
66 def __unicode__(self):
70 class Scriptlet(models.Model):
71 name = models.CharField(max_length=64, primary_key=True)
72 code = models.TextField()
74 def __unicode__(self):
75 return _(u'javascript') + u':' + self.name