Corrected ExtMethod keyword generation to eliminate unicode. Added capfirst use for...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 31 Mar 2011 21:45:00 +0000 (17:45 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 6 Apr 2011 20:58:11 +0000 (16:58 -0400)
contrib/gilbert/extdirect/core.py
contrib/gilbert/plugins/models.py
contrib/penfield/gilbert.py

index 42c24c0..f0a4e2a 100644 (file)
@@ -1,13 +1,13 @@
-import sys
-import datetime
+from django.db.models import Q
+from django.http import HttpResponse
+from django.utils import simplejson as json
+from django.utils.encoding import smart_str
+from django.views.debug import ExceptionReporter
 from inspect import isclass, ismethod, isfunction, getmembers, getargspec
 from traceback import format_tb
 from abc import ABCMeta, abstractproperty
 from collections import Callable, Sized, Mapping
-from django.utils import simplejson as json
-from django.views.debug import ExceptionReporter
-from django.http import HttpResponse
-from django.db.models import Q
+import sys, datetime
 
 
 # __all__ = ('ext_action', 'ext_method', 'is_ext_action', 'is_ext_method', 'ExtAction', 'ExtMethod')
@@ -225,7 +225,7 @@ class ExtMethod(Callable, Sized):
                
                keywords = {}
                if self.accepts_keywords:
-                       keywords = args.pop()
+                       keywords = dict([(smart_str(k, 'ascii'), v) for k,v in args.pop().items()])
                
                varargs = []
                if self.accepts_varargs:
index 0ba310e..ae97ee7 100644 (file)
@@ -5,6 +5,7 @@ from django.db.models import Q
 from django.db.models.fields.related import ManyToOneRel
 from django.db.models.fields.files import FieldFile, ImageFieldFile, FileField
 from django.forms.models import ModelForm, modelform_factory
+from django.template.defaultfilters import capfirst
 from django.utils import simplejson as json
 from django.utils.encoding import smart_unicode
 from .base import Plugin
@@ -126,7 +127,7 @@ class ModelAdmin(Plugin):
                                'editable': False,
                        }
                        header, attr = label_for_field(field_name, self.model, model_admin=self, return_attr=True)
-                       column['header'] = header
+                       column['header'] = capfirst(header)
                        if (field_name in self.sortable_fields) or (getattr(attr, 'admin_order_field', None) in self.sortable_fields):
                                column['sortable'] = True
                        if field_name in self.data_editable_columns:
@@ -170,17 +171,20 @@ class ModelAdmin(Plugin):
                        raise PermissionDenied
                return self.model._default_manager.all()
        
+       def queryset(self, request):
+               return self.model._default_manager.get_query_set()
+       
        @ext_method
        def filter(self, request, **kwargs):
                if not self.has_read_permission(request):
                        raise PermissionDenied
-               return self.model._default_manager.all().filter(**kwargs)
+               return self.queryset(request).filter(**kwargs)
        
        @ext_method
        def get(self, request, **kwargs):
                if not self.has_read_permission(request):
                        raise PermissionDenied
-               return self.model._default_manager.all().values().get(**kwargs)
+               return self.queryset(request).values().get(**kwargs)
        
        @property
        def form_class(self):
index fb284a5..cae1936 100644 (file)
@@ -1,9 +1,19 @@
 from .models import Blog, BlogEntry, BlogView, NewsletterArticle, NewsletterIssue, Newsletter, NewsletterView
 from philo.contrib.gilbert import site
+from philo.contrib.gilbert.plugins.models import ModelAdmin
 
 
-site.register_model(Blog, icon_name='blog')
-site.register_model(BlogEntry, search_fields=('title', 'content',), icon_name='document-snippet')
+class BlogAdmin(ModelAdmin):
+       search_fields = ('title',)
+
+
+class BlogEntryAdmin(ModelAdmin):
+       search_fields = ('title', 'content',)
+       data_columns = ('title', 'author', 'date',)
+
+
+site.register_model(Blog, BlogAdmin, icon_name='blog')
+site.register_model(BlogEntry, BlogEntryAdmin, icon_name='document-snippet')
 site.register_model(BlogView, icon_name='application-blog')
 site.register_model(NewsletterArticle, icon_name='document-snippet')
 site.register_model(NewsletterIssue, icon_name='newspaper')