Komenda do poprawiania przyciskow.
authorŁukasz Rekucki <lrekucki@gmail.com>
Tue, 8 Sep 2009 16:24:03 +0000 (18:24 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Tue, 8 Sep 2009 16:24:03 +0000 (18:24 +0200)
apps/explorer/admin.py [deleted file]
apps/toolbar/admin.py
apps/toolbar/management/__init__.py [new file with mode: 0755]
apps/toolbar/management/commands/__init__.py [new file with mode: 0755]
apps/toolbar/management/commands/fixbuttons.py [new file with mode: 0755]
project/admin.py [new file with mode: 0644]

diff --git a/apps/explorer/admin.py b/apps/explorer/admin.py
deleted file mode 100644 (file)
index a03f393..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-from django.contrib import admin
-from django.utils.translation import ugettext_lazy as _
-
-from explorer import models
-
-admin.site.register(models.Book)
-admin.site.register(models.PullRequest)
-
index 052538e..58b5f74 100644 (file)
@@ -1,5 +1,7 @@
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
+from django import forms
+from django.utils import simplejson as json
 
 from toolbar import models
 
 
 from toolbar import models
 
@@ -8,7 +10,26 @@ from toolbar import models
 #    search_fields = ('name', 'slug',)
 #    prepopulated_fields = {'slug': ('name',)}
 #    list_editable = ('position',)
 #    search_fields = ('name', 'slug',)
 #    prepopulated_fields = {'slug': ('name',)}
 #    list_editable = ('position',)
+
+
+class ButtonAdminForm(forms.ModelForm):
+    model = models.Button
+
+    def clean_params(self):
+        value = self.cleaned_data['params']
+        try:
+            return json.dumps(json.loads(value))
+        except Exception, e:
+            raise forms.ValidationError(e)
+
+class ButtonAdmin(admin.ModelAdmin):
+    form = ButtonAdminForm
+    list_display = ('label', 'scriptlet', 'key', 'params')
+    prepopulated_fields = {'slug': ('label',)}
+
+admin.site.register(models.Button, ButtonAdmin)
 admin.site.register(models.ButtonGroup)
 admin.site.register(models.ButtonGroup)
+admin.site.register(models.Scriptlet)
 
 #class ButtonAdmin(admin.ModelAdmin):
 #    list_display = ('label', 'action', 'key', 'position',)
 
 #class ButtonAdmin(admin.ModelAdmin):
 #    list_display = ('label', 'action', 'key', 'position',)
@@ -17,6 +38,3 @@ admin.site.register(models.ButtonGroup)
 #    filter_horizontal = ('group',)
 #    list_editable = ('position',)
 
 #    filter_horizontal = ('group',)
 #    list_editable = ('position',)
 
-admin.site.register(models.Button)
-admin.site.register(models.Scriptlet)
-
diff --git a/apps/toolbar/management/__init__.py b/apps/toolbar/management/__init__.py
new file mode 100755 (executable)
index 0000000..5ff26b2
--- /dev/null
@@ -0,0 +1,4 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+
diff --git a/apps/toolbar/management/commands/__init__.py b/apps/toolbar/management/commands/__init__.py
new file mode 100755 (executable)
index 0000000..5ff26b2
--- /dev/null
@@ -0,0 +1,4 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+
diff --git a/apps/toolbar/management/commands/fixbuttons.py b/apps/toolbar/management/commands/fixbuttons.py
new file mode 100755 (executable)
index 0000000..9e72151
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- conding: utf-8
+__author__="lreqc"
+__date__ ="$2009-09-08 14:31:26$"
+from django.core.management.base import NoArgsCommand
+from toolbar.models import Button
+import json
+import re
+
+class Command(NoArgsCommand):
+    
+    def handle_noargs(self, **options):
+        buttons = Button.objects.all()
+        for b in buttons:
+            params = b.params;
+            try:
+                v = json.loads(b.params)
+               
+            except ValueError, e:
+                print 'On button %s: ' % b.label, b.params
+                print e
+                # try to fix the bad json
+                
+                # cut the parenthis
+                if params[0] == u'(':
+                    params = params[1:]
+                if params[-1] == u')':
+                    params = params[:-1]
+
+                v = json.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8'))
+            b.params = json.dumps(v)
+            b.save()
+
+
+
+    
\ No newline at end of file
diff --git a/project/admin.py b/project/admin.py
new file mode 100644 (file)
index 0000000..7bf8097
--- /dev/null
@@ -0,0 +1,4 @@
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+import toolbar.admin
\ No newline at end of file