1 from django.contrib import admin
2 from django.utils.translation import ugettext_lazy as _
3 from django import forms
4 from django.utils import simplejson as json
6 from toolbar import models
8 #class ButtonGroupAdmin(admin.ModelAdmin):
9 # list_display = ('name', 'slug', 'position',)
10 # search_fields = ('name', 'slug',)
11 # prepopulated_fields = {'slug': ('name',)}
12 # list_editable = ('position',)
14 class KeyModSelector(forms.MultiWidget):
16 super(KeyModSelector, self).__init__(
17 [forms.CheckboxInput() for x in xrange(0, 3)])
19 def decompress(self, v):
21 r = [(v & 0x01) != 0, (v & 0x02) != 0, (v & 0x04) != 0]
22 print "DECOMPRESS: " , v, repr(r)
25 def format_output(self, widgets):
27 out += u'<p>' + widgets[0] + u' Alt </p>'
28 out += u'<p>' + widgets[1] + u' Ctrl </p>'
29 out += u'<p>' + widgets[2] + u' Shift </p>'
32 class KeyModField(forms.MultiValueField):
35 super(KeyModField, self).__init__(\
36 fields = tuple(forms.BooleanField() for x in xrange(0, 3)), \
37 widget = KeyModSelector())
39 def compress(self, dl):
40 v = int(dl[0]) | (int(dl[1]) << 1) | (int(dl[2]) << 2)
45 class ButtonAdminForm(forms.ModelForm):
46 key_mod = KeyModField()
51 def clean_params(self):
52 value = self.cleaned_data['params']
54 return json.dumps(json.loads(value))
56 raise forms.ValidationError(e)
58 class ButtonAdmin(admin.ModelAdmin):
59 form = ButtonAdminForm
60 list_display = ('slug', 'label', 'tooltip', 'hotkey_name')
61 list_display_links = ('slug',)
62 list_editable = ('label', 'tooltip',)
63 prepopulated_fields = {'slug': ('label',)}
65 admin.site.register(models.Button, ButtonAdmin)
66 admin.site.register(models.ButtonGroup)
67 admin.site.register(models.Scriptlet)
69 #class ButtonAdmin(admin.ModelAdmin):
70 # list_display = ('label', 'action', 'key', 'position',)
71 # list_filter = ('group',)
72 # search_fields = ('label', 'action', 'key',)
73 # filter_horizontal = ('group',)
74 # list_editable = ('position',)