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):
18 #class ButtonGroupManager(models.Manager):
20 # def with_buttons(self):
21 # from django.db import connection
22 # cursor = connection.cursor()
24 # SELECT g.name, g.slug, CONCAT(b.slug),
25 # FROM toolbar_buttongroup as g LEFT JOIN toolbar_button as b
27 # WHERE p.id = r.poll_id
31 # for row in cursor.fetchall():
32 # p = self.model(id=row[0], question=row[1], poll_date=row[2])
33 # p.num_responses = row[3]
34 # result_list.append(p)
37 class Button(models.Model):
38 label = models.CharField(max_length=32)
39 slug = models.SlugField(unique=True) #unused
42 params = models.TextField(default='[]') # TODO: should be a JSON field
43 scriptlet = models.ForeignKey('Scriptlet', null=True, blank=True)
44 link = models.CharField(max_length=256, blank=True, default='')
47 key = models.CharField(blank=True, max_length=1)
48 key_mod = models.PositiveIntegerField(blank=True, default=1)
49 tooltip = models.CharField(blank=True, max_length=120)
51 # Why the button is restricted to have the same position in each group ?
52 # position = models.IntegerField(default=0)
53 group = models.ManyToManyField(ButtonGroup)
57 verbose_name, verbose_name_plural = _('button'), _('buttons')
59 def hotkey_code(self):
60 return ord(self.key.upper()) | (self.key_mod << 8)
62 def hotkey_name(self):
67 if self.key_mod & 0x01: mods.append('Alt')
68 if self.key_mod & 0x02: mods.append('Ctrl')
69 if self.key_mod & 0x04: mods.append('Shift')
70 mods.append('"'+self.key+'"')
73 def __unicode__(self):
76 class Scriptlet(models.Model):
77 name = models.CharField(max_length=64, primary_key=True)
78 code = models.TextField()
80 # TODO: add this later and remap code property to this
81 # code_min = models.TextField()
83 def __unicode__(self):
84 return _(u'javascript')+u':'+self.name