1 from inspect import isclass, getargspec
4 def is_gilbert_method(function):
5 return getattr(function, 'gilbert_method', False)
8 def gilbert_method(function=None, name=None, argc=None, restricted=True):
10 setattr(function, 'gilbert_method', True)
11 setattr(function, 'name', name or function.__name__)
12 setattr(function, 'restricted', restricted)
15 args = getargspec(function)[0]
20 new_argc = new_argc - 1
22 if args[0] == 'request':
24 new_argc = new_argc - 1
25 setattr(function, 'argc', new_argc)
27 if function is not None:
28 return wrapper(function)
32 class GilbertPluginBase(type):
33 def __new__(cls, name, bases, attrs):
34 if 'methods' not in attrs:
36 for attr in attrs.values():
37 if is_gilbert_method(attr):
38 methods.append(attr.name)
39 attrs['methods'] = methods
40 return super(GilbertPluginBase, cls).__new__(cls, name, bases, attrs)
43 class GilbertPlugin(object):
44 __metaclass__ = GilbertPluginBase
46 def __init__(self, site):
49 def get_method(self, method_name):
50 method = getattr(self, method_name, None)
51 if not is_gilbert_method(method):
68 def fugue_icons(self):
72 class GilbertModelAdmin(GilbertPlugin):
73 def __init__(self, site, model):
75 self.name = model._meta.object_name
76 super(GilbertModelAdmin, self).__init__(site)
80 return list(self.model._default_manager.all().values())
83 def get(self, constraint):
84 return self.model._default_manager.all().values().get(**constraint)