1 from philo.contrib.gilbert.utils import gilbert_method, is_gilbert_method, is_gilbert_class
4 class GilbertClassBase(type):
5 def __new__(cls, name, bases, attrs):
6 if 'gilbert_class' not in attrs:
7 attrs['gilbert_class'] = True
8 if 'gilbert_class_name' not in attrs:
9 attrs['gilbert_class_name'] = name
10 if 'gilbert_class_methods' not in attrs:
11 gilbert_class_methods = {}
12 for attr in attrs.values():
13 if is_gilbert_method(attr):
14 gilbert_class_methods[attr.gilbert_method_name] = attr
15 attrs['gilbert_class_methods'] = gilbert_class_methods
16 return super(GilbertClassBase, cls).__new__(cls, name, bases, attrs)
19 class GilbertClass(object):
20 __metaclass__ = GilbertClassBase
23 class GilbertPluginBase(type):
24 def __new__(cls, name, bases, attrs):
25 if 'gilbert_plugin' not in attrs:
26 attrs['gilbert_plugin'] = True
27 if 'gilbert_plugin_name' not in attrs:
28 attrs['gilbert_plugin_name'] = name
29 if 'gilbert_plugin_classes' not in attrs:
30 gilbert_plugin_classes = {}
31 for attr_name, attr in attrs.items():
32 if is_gilbert_class(attr):
33 gilbert_plugin_classes[attr_name] = attr
34 attrs['gilbert_plugin_classes'] = gilbert_plugin_classes
35 return super(GilbertPluginBase, cls).__new__(cls, name, bases, attrs)
38 class GilbertPlugin(object):
39 __metaclass__ = GilbertPluginBase
41 def __init__(self, site):
45 class GilbertModelAdmin(GilbertClass):
46 def __init__(self, site, model):
49 self.gilbert_class_name = model._meta.object_name
53 return list(self.model._default_manager.all().values())
56 def get(self, constraint):
57 return self.model._default_manager.all().values().get(**constraint)