1 from django.db import models
2 from django.utils.translation import ugettext_lazy as _
5 class ButtonGroup(models.Model):
6 name = models.CharField(max_length=32)
7 slug = models.SlugField()
8 position = models.IntegerField(default=0)
11 ordering = ('position', 'name',)
12 verbose_name, verbose_name_plural = _('button group'), _('button groups')
14 def __unicode__(self):
17 class Button(models.Model):
18 label = models.CharField(max_length=32)
19 slug = models.SlugField(unique=True) #unused
22 params = models.TextField(default='[]') # TODO: should be a JSON field
23 scriptlet = models.ForeignKey('Scriptlet', null=True, blank=True)
24 link = models.CharField(max_length=256, blank=True, default='')
27 key = models.CharField(blank=True, max_length=1)
28 key_mod = models.PositiveIntegerField(blank=True, default=1)
29 tooltip = models.CharField(blank=True, max_length=120)
31 # Why the button is restricted to have the same position in each group ?
32 # position = models.IntegerField(default=0)
33 group = models.ManyToManyField(ButtonGroup)
37 verbose_name, verbose_name_plural = _('button'), _('buttons')
39 def hotkey_code(self):
40 return ord(self.key.upper()) | (self.key_mod << 8)
42 def hotkey_name(self):
47 if self.key_mod & 0x01: mods.append('Alt')
48 if self.key_mod & 0x02: mods.append('Ctrl')
49 if self.key_mod & 0x04: mods.append('Shift')
50 mods.append('"'+self.key+'"')
53 def __unicode__(self):
56 class Scriptlet(models.Model):
57 name = models.CharField(max_length=64, primary_key=True)
58 code = models.TextField()
60 # TODO: add this later and remap code property to this
61 # code_min = models.TextField()
63 def __unicode__(self):
64 return _(u'javascript')+u':'+self.name