Exemple #1
0
 def assign_labels(cls, class_name, class_dict):
     # Assign labels for the class/extent.
     if '_label' not in class_dict and not hasattr(cls, '_label'):
         cls._label = label_from_name(class_name)
     if '_plural' not in class_dict and not hasattr(cls, '_plural'):
         cls._plural = plural_from_name(class_name)
     # Assign labels for query, transaction, and view methods.
     for key in class_dict:
         if key[:2] in ('q_', 't_', 'v_'):
             m_name = key
             func = getattr(cls, m_name)
             # Drop the prefix.
             method_name = m_name[2:]
             # Assign a label if none exists.
             new_label = None
             if getattr(func, '_label', None) is None:
                 # Make a label after dropping prefix.
                 new_label = label_from_name(method_name)
             if isextentmethod(func):
                 # Extentmethod.
                 if new_label is not None:
                     func._label = new_label
             else:
                 # Instancemethod.
                 if new_label is not None:
                     class_dict[m_name]._label = new_label
Exemple #2
0
 def __init__(self, name, instance, EntityClass):
     NamespaceExtension.__init__(self, name, instance)
     # Expose methods through this namespace.
     for name in dir(EntityClass):
         # Extender methods always have x_ prefix.
         if name.startswith('x_'):
             method = getattr(EntityClass, name)
             # Methods that apply to an extent are extentmethods.
             if isextentmethod(method):
                 # Drop the 'x_' prefix.
                 name = name[2:]
                 self._set(name, method)
Exemple #3
0
 def test_extentmethod_detection(self):
     assert isextentmethod(db.Hotel.x.return_extent_name)
     assert isextentmethod(db.schema.E["Hotel"].x_return_extent_name)
     assert isextentmethod(db.Hotel.x.return_class)
     assert isextentmethod(db.schema.E["Hotel"].x_return_class)
     hotel = db.execute(db.Hotel.t.create())
     assert not isextentmethod(hotel.x.return_oid)
     assert not isextentmethod(db.schema.E["Hotel"].x_return_oid)
Exemple #4
0
 def __init__(self, name, instance, EntityClass):
     NamespaceExtension.__init__(self, name, instance)
     self._E = EntityClass
     # Expose transaction methods through this namespace.
     for key in dir(EntityClass):
         # Transaction methods always have t_ prefix.
         if key.startswith('t_'):
             method = getattr(EntityClass, key)
             # Transaction methods that apply to an extent are
             # extentmethods of an Entity class.
             if isextentmethod(method):
                 # Drop the 't_' prefix.
                 name = key[2:]
                 self._set(name, method)
Exemple #5
0
 def test_extentmethod_decoration(self):
     assert isextentmethod(db.LoopSegment.t.create_loop)
     assert isextentmethod(db.Sprocket.t.create)