def test_rest_cms_create(self): from ptahcms import rest self.init_ptah() all_types = ptah.get_types() all_types[Content.__type__.__uri__] = Content.__type__ container = Container() request = DummyRequest(params={ 'tinfo': Content.__type__.__uri__, 'name': 'content' }, post={'title': ''}) info = rest.createContentAction(container, request) self.assertEqual(info['errors']['title'], 'Required') request = DummyRequest(params={ 'tinfo': Content.__type__.__uri__, 'name': 'content' }, post={'title': 'New title'}) rest.createContentAction(container, request) self.assertEqual(container.keys(), ['content']) self.assertEqual(container['content'].title, 'New title')
def cmsTypes(request, *args): types = [] for name, tinfo in ptah.get_types().items(): types.append((tinfo.title, name, typeInfo(tinfo, request))) return [info for _t, name, info in sorted(types)]
def list_models(self): cfg = ptah.get_settings(ptah.CFG_ID_PTAH) disabled = cfg['disable_models'] types = [] for ti in ptah.get_types().values(): types.append( {'name': ti.__uri__, 'title': ti.title, 'description': ti.description, 'disabled': ti.__uri__ in disabled, 'cls': ti.cls}) for ti in sorted(types, key=lambda item:item['name']): print (grpTitleWrap.fill( '{name}: {title} (disabled: {disabled})'.format(**ti))) if ti['description']: print (grpDescriptionWrap.fill(ti['description'])) print('') cls = ti['cls'] print(grpDescriptionWrap.fill('class: {0}'.format(cls.__name__))) print(grpDescriptionWrap.fill('module: {0}'.format(cls.__module__))) print(' file: ', sys.modules[cls.__module__].__file__) print('\n')
def update(self): cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.request.registry) types = [] for ti in ptah.get_types().values(): if ti.__class__ is not TypeInformation: continue if ti.__uri__ in cfg['disable_models']: continue types.append((ti.title, ti)) self.types = [f for _t, f in sorted(types, key=lambda f: f[0])]
def msg_list_models(self, data): cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry) types = [] for ti in ptah.get_types().values(): if ti.__uri__ in cfg['disable_models']: continue types.append((ti.title, ti)) types = [{'uri': f.__uri__, 'name': f.name, 'description': f.description} for _t, f in sorted(types)] self.send('list_models', {'models': types})
def test_tinfo_create(self): import ptah @ptah.tinfo("mycontent", "MyContent") class MyContent(object): def __init__(self, title=""): self.title = title self.init_ptah() all_types = ptah.get_types() content = all_types["type:mycontent"].create(title="Test content") self.assertTrue(isinstance(content, MyContent)) self.assertEqual(content.title, "Test content")
def test_tinfo_create(self): import ptah @ptah.tinfo('mycontent', 'MyContent') class MyContent(object): def __init__(self, title=''): self.title = title self.init_ptah() all_types = ptah.get_types() content = all_types['type:mycontent'].create(title='Test content') self.assertTrue(isinstance(content, MyContent)) self.assertEqual(content.title, 'Test content')
def test_tinfo_create(self): import ptahcms global MyContent class MyContent(ptahcms.Content): __type__ = ptahcms.Type("mycontent", "MyContent") self.init_ptah() all_types = ptah.get_types() content = all_types["type:mycontent"].create(title="Test content") self.assertTrue(isinstance(content, MyContent)) self.assertEqual(content.title, "Test content") self.assertTrue(content not in ptah.get_session())
def test_tinfo(self): import ptah @ptah.tinfo("mycontent", "MyContent") class Mycontent(object): pass self.init_ptah() all_types = ptah.get_types() self.assertTrue("type:mycontent" in all_types) tinfo = ptah.get_type("type:mycontent") self.assertEqual(tinfo.__uri__, "type:mycontent") self.assertEqual(tinfo.name, "mycontent") self.assertEqual(tinfo.title, "MyContent") self.assertIs(tinfo.cls, Mycontent) self.assertIs(Mycontent.__type__, tinfo)
def test_tinfo(self): import ptah @ptah.tinfo('mycontent', 'MyContent') class Mycontent(object): pass self.init_ptah() all_types = ptah.get_types() self.assertTrue('type:mycontent' in all_types) tinfo = ptah.get_type('type:mycontent') self.assertEqual(tinfo.__uri__, 'type:mycontent') self.assertEqual(tinfo.name, 'mycontent') self.assertEqual(tinfo.title, 'MyContent') self.assertIs(tinfo.cls, Mycontent) self.assertIs(Mycontent.__type__, tinfo)
def test_tinfo(self): import ptahcms global MyContent class MyContent(ptahcms.Content): __type__ = ptahcms.Type("mycontent", "MyContent") self.init_ptah() all_types = ptah.get_types() self.assertTrue("type:mycontent" in all_types) tinfo = ptah.get_type("type:mycontent") self.assertEqual(tinfo.__uri__, "type:mycontent") self.assertEqual(tinfo.name, "mycontent") self.assertEqual(tinfo.title, "MyContent") self.assertEqual(tinfo.cls, MyContent)
def test_rest_cms_create(self): from ptahcms import rest self.init_ptah() all_types = ptah.get_types() all_types[Content.__type__.__uri__] = Content.__type__ container = Container() request = DummyRequest( params = {'tinfo': Content.__type__.__uri__, 'name': 'content'}, post = {'title':''}) info = rest.createContentAction(container, request) self.assertEqual(info['errors']['title'], 'Required') request = DummyRequest( params = {'tinfo': Content.__type__.__uri__, 'name': 'content'}, post = {'title':'New title'}) rest.createContentAction(container, request) self.assertEqual(container.keys(), ['content']) self.assertEqual(container['content'].title, 'New title')
def msg_load_page(self, data): uri = data['uri'] ti = ptah.get_types()[uri] with ptah.sa_session() as sa: self.send('page', {'page': self.page(sa, ti, 0, 5)})
def available(self): return bool(ptah.get_types())