コード例 #1
0
class testViewFactory:
    def setup(self):
        provider = IProvider()
        self.viewFactory = ViewFactory()
        self.viewConfig = DummyViewConfig(provider, 'test_table')
        
    def testCreateObj(self):
        pass
    
    def testCreate(self):
        view  = self.viewFactory.create(self.viewConfig)
コード例 #2
0
ファイル: sprockets.py プロジェクト: arianepaola/tg2jython
class Views(dict):
    def __init__(self, provider, controller):
        if not isinstance(provider, IProvider):
            raise TypeError('provider is not of type IProvider')
        if not isinstance(controller, types.StringTypes):
            raise TypeError('controller is not of type String')
        self.viewFactory = ViewFactory()
        self.provider = provider
        self.controller = controller
        
    defaultViewConfigs = {'databaseView': DatabaseViewConfig,
                          'editRecord'  : EditRecordViewConfig,
                          'addRecord'   : AddRecordViewConfig,
                          #'viewRecord'  : ViewConfig,
                          'tableView'   : TableViewConfig,
                          'tableDef'    : TableDefViewConfig,
                          }

    def _getView(self, key):
        if '__' not in key:
            identifier = ''
            viewType = key
        else:
            viewType, identifier = key.split('__')
        if viewType not in self.defaultViewConfigs:
            raise ViewConfigError('viewType:%s now found in default Views'%viewType)
        viewConfig = self.defaultViewConfigs[viewType](self.provider, identifier, self.controller)
        self[key] = self.viewFactory.create(viewConfig, id=key)
        return self[key]
    
    def __getitem__(self, key):
        if dict.__contains__(self, key):
            return dict.__getitem__(self, key)
        view = self._getView(key)
        self[key] = view
        return view

    def __setitem__(self, key, item):
        if not isinstance(item, View):
            raise TypeError('item must be of type View')
        return dict.__setitem__(self, key, item)