Guest User

Untitled

a guest
Jan 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CatalogItem:
  2.     """
  3.    Decorator class, collect all catalog modules and his item classes in cls.REGISTRY
  4.    """
  5.  
  6.     REGISTRY = {}
  7.  
  8.     def __init__(self, name):
  9.         self.verbose_name = name
  10.  
  11.     def __call__(self, cls):
  12.         self.register(cls)
  13.         return cls
  14.  
  15.     def register(self, cls):
  16.         """
  17.        Register item modules and its item classes.
  18.        :param cls: Class object
  19.        :return:
  20.        """
  21.         module_name, module = self.register_module(cls)
  22.         self.__class__.REGISTRY[module_name] = self.register_item(module, cls)
  23.  
  24. @CatalogItem('Куплю квартиру')
  25. class FlatBuy(BaseAd):
  26.     building_type = BuildingTypeField(choices=BuildingTypeField.get_choices_for_model_field())
Add Comment
Please, Sign In to add comment