From: Ɓukasz Rekucki Date: Tue, 8 Sep 2009 16:24:03 +0000 (+0200) Subject: Komenda do poprawiania przyciskow. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/3a100c86bdaa0dbdd25796286ef3b6d4888911d8?ds=inline Komenda do poprawiania przyciskow. --- diff --git a/apps/explorer/admin.py b/apps/explorer/admin.py deleted file mode 100644 index a03f3936..00000000 --- a/apps/explorer/admin.py +++ /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) - diff --git a/apps/toolbar/admin.py b/apps/toolbar/admin.py index 052538ea..58b5f746 100644 --- a/apps/toolbar/admin.py +++ b/apps/toolbar/admin.py @@ -1,5 +1,7 @@ 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 @@ -8,7 +10,26 @@ from toolbar import models # 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.Scriptlet) #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',) -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 index 00000000..5ff26b2a --- /dev/null +++ b/apps/toolbar/management/__init__.py @@ -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 index 00000000..5ff26b2a --- /dev/null +++ b/apps/toolbar/management/commands/__init__.py @@ -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 index 00000000..9e721510 --- /dev/null +++ b/apps/toolbar/management/commands/fixbuttons.py @@ -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 index 00000000..7bf80973 --- /dev/null +++ b/project/admin.py @@ -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