本文整理汇总了Python中ptah.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_container_delete
def test_container_delete(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container['content'] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
del container['content']
self.assertEqual(container.keys(), [])
self.assertEqual(container.values(), [])
transaction.commit()
self.assertTrue(ptah.resolve(content_uri) is None)
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), [])
self.assertRaises(KeyError, container.__delitem__, 'content')
self.assertRaises(KeyError, container.__delitem__, Content())
开发者ID:blaflamme,项目名称:ptah,代码行数:27,代码来源:test_container.py
示例2: generateThumbnail
def generateThumbnail(theme, width=210):
blob = ptah.resolve(theme.preview)
if not blob:
return
data = StringIO(blob.read())
image = PIL.Image.open(data)
if image.mode == '1':
image = image.convert('L')
elif image.mode == 'P':
image = image.convert('RGBA')
# get width, height
orig_size = image.size
scale = float(width)/orig_size[0]
height = int(round(orig_size[1] * scale))
#convert image
pilfilter = PIL.Image.NEAREST
pilfilter = PIL.Image.ANTIALIAS
image.thumbnail((width, height), pilfilter)
newfile = StringIO()
image.save(newfile, 'jpeg', quality=88)
blob = ptah.resolve(theme.thumbnail)
if blob is None:
blob = ptah.cms.blob_storage.create(theme)
theme.thumbnail = blob.__uri__
blob.write(newfile.getvalue())
blob.updateMetadata(mimetype = 'image/jpeg')
开发者ID:cleder,项目名称:ploud.themegallery,代码行数:35,代码来源:theme.py
示例3: test_container_getitem
def test_container_getitem(self):
container = Container(__name__="container", __path__="/container/")
content1 = Content(title="Content1")
content2 = Content(title="Content2")
container["content1"] = content1
container["content2"] = content2
self.assertEqual(container["content1"].__uri__, content1.__uri__)
self.assertEqual(container["content2"].__uri__, content2.__uri__)
self.assertEqual(container.get("content1").__uri__, content1.__uri__)
self.assertEqual(container.get("content2").__uri__, content2.__uri__)
ptah.cms.Session.add(container)
ptah.cms.Session.add(content1)
ptah.cms.Session.add(content2)
ptah.cms.Session.flush()
c_u = container.__uri__
c1_u = content1.__uri__
c2_u = content2.__uri__
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container["content1"].__uri__, c1_u)
self.assertEqual(container["content2"].__uri__, c2_u)
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container.get("content1").__uri__, c1_u)
self.assertEqual(container.get("content2").__uri__, c2_u)
开发者ID:mcdonc,项目名称:ptah,代码行数:31,代码来源:test_container.py
示例4: test_container_simple_move
def test_container_simple_move(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container['content'] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
container['moved'] = content
self.assertEqual(content.__name__, 'moved')
self.assertEqual(content.__path__, '/container/moved/')
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
transaction.commit()
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), ['moved'])
self.assertEqual(container['moved'].__uri__, content_uri)
开发者ID:blaflamme,项目名称:ptah,代码行数:28,代码来源:test_container.py
示例5: __call__
def __call__(self):
self.tinfo = ptah.resolve(self.params['turi'])
with ptah.sa_session() as sa:
self.session = sa
self.context = ptah.resolve(self.params['uri'])
return super(EditRecord, self).__call__()
开发者ID:ptahproject,项目名称:heroku-ptah,代码行数:7,代码来源:crud.py
示例6: test_container_simple_move
def test_container_simple_move(self):
container = Container(__name__="container", __path__="/container/")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container["content"] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
container["moved"] = content
self.assertEqual(content.__name__, "moved")
self.assertEqual(content.__path__, "/container/moved/")
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
transaction.commit()
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), ["moved"])
self.assertEqual(container["moved"].__uri__, content_uri)
开发者ID:mcdonc,项目名称:ptah,代码行数:28,代码来源:test_container.py
示例7: test_container_insert_subtree
def test_container_insert_subtree(self):
container = Container(__name__="container", __path__="/container/")
folder = Container(title="Folder")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(folder)
ptah.cms.Session.add(content)
folder["content"] = content
container["folder"] = folder
content_uri = content.__uri__
folder_uri = folder.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
folder = ptah.resolve(folder_uri)
self.assertEqual(container.keys(), ["folder"])
self.assertEqual(folder.keys(), ["content"])
self.assertEqual(folder.__path__, "/container/folder/")
self.assertEqual(content.__path__, "/container/folder/content/")
transaction.commit()
开发者ID:mcdonc,项目名称:ptah,代码行数:26,代码来源:test_container.py
示例8: test_container_insert_subtree
def test_container_insert_subtree(self):
container = Container(__name__ = 'container', __path__ = '/container/')
folder = Container(title='Folder')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(folder)
ptah.cms.Session.add(content)
folder['content'] = content
container['folder'] = folder
content_uri = content.__uri__
folder_uri = folder.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
folder = ptah.resolve(folder_uri)
self.assertEqual(container.keys(), ['folder'])
self.assertEqual(folder.keys(), ['content'])
self.assertEqual(folder.__path__, '/container/folder/')
self.assertEqual(content.__path__, '/container/folder/content/')
transaction.commit()
开发者ID:blaflamme,项目名称:ptah,代码行数:26,代码来源:test_container.py
示例9: test_container_getitem
def test_container_getitem(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content1 = Content(title='Content1')
content2 = Content(title='Content2')
container['content1'] = content1
container['content2'] = content2
self.assertEqual(container['content1'].__uri__, content1.__uri__)
self.assertEqual(container['content2'].__uri__, content2.__uri__)
self.assertEqual(container.get('content1').__uri__, content1.__uri__)
self.assertEqual(container.get('content2').__uri__, content2.__uri__)
ptah.cms.Session.add(container)
ptah.cms.Session.add(content1)
ptah.cms.Session.add(content2)
ptah.cms.Session.flush()
c_u = container.__uri__
c1_u = content1.__uri__
c2_u = content2.__uri__
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container['content1'].__uri__, c1_u)
self.assertEqual(container['content2'].__uri__, c2_u)
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container.get('content1').__uri__, c1_u)
self.assertEqual(container.get('content2').__uri__, c2_u)
开发者ID:blaflamme,项目名称:ptah,代码行数:31,代码来源:test_container.py
示例10: test_superuser_resolver
def test_superuser_resolver(self):
import ptah
from ptah.authentication import SUPERUSER
self._init_ptah()
user = ptah.resolve(ptah.SUPERUSER_URI)
self.assertIs(user, SUPERUSER)
self.assertIsNone(ptah.resolve("ptah+auth:unknown"))
开发者ID:mcdonc,项目名称:ptah,代码行数:9,代码来源:test_auth.py
示例11: test_superuser_resolver
def test_superuser_resolver(self):
import ptah
from ptah.authentication import SUPERUSER
self.init_ptah()
user = ptah.resolve(ptah.SUPERUSER_URI)
self.assertIs(user, SUPERUSER)
self.assertIsNone(ptah.resolve('ptah-auth:unknown'))
self.assertEqual(repr(user), '<ptah Superuser>')
开发者ID:runyaga,项目名称:ptah,代码行数:9,代码来源:test_auth.py
示例12: test_blob_write
def test_blob_write(self):
import ptah, ptah.cms
blob_uri = ptah.cms.blobStorage.add(StringIO("blob data")).__uri__
blob = ptah.resolve(blob_uri)
blob.write("new data")
transaction.commit()
blob = ptah.resolve(blob_uri)
self.assertEqual(blob.read(), "new data")
开发者ID:blaflamme,项目名称:ptah,代码行数:10,代码来源:test_blobstorage.py
示例13: test_blob_write
def test_blob_write(self):
import ptah
blob_uri = ptah.cms.blob_storage.add(
BytesIO(bytes_('blob data','utf-8'))).__uri__
blob = ptah.resolve(blob_uri)
blob.write(bytes_('new data','utf-8'))
transaction.commit()
blob = ptah.resolve(blob_uri)
self.assertEqual(blob.read(), bytes_('new data','utf-8'))
开发者ID:runyaga,项目名称:ptah,代码行数:11,代码来源:test_blobstorage.py
示例14: test_container_basics
def test_container_basics(self):
container = Container(__name__="container", __path__="/container/")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
self.assertEqual(content.__path__, "")
self.assertRaises(ValueError, container.__setitem__, "content", object())
self.assertRaises(ValueError, container.__setitem__, "content", container)
container["content"] = content
self.assertEqual(content.__name__, "content")
self.assertEqual(content.__path__, "/container/content/")
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
self.assertTrue("content" in container)
self.assertEqual(container.keys(), ["content"])
self.assertEqual(container["content"].__uri__, content_uri)
self.assertEqual(container.get("content").__uri__, content_uri)
self.assertEqual(container.get("unknown"), None)
self.assertRaises(KeyError, container.__getitem__, "unknown")
content = container["content"]
self.assertRaises(KeyError, container.__setitem__, "content", content)
开发者ID:mcdonc,项目名称:ptah,代码行数:34,代码来源:test_container.py
示例15: create
def create(self, tname, name=None, **params):
tinfo = ptah.resolve(tname)
if tinfo is None:
raise NotFound('Type information is not found')
tinfo.check_context(self)
item = tinfo.create()
if not name:
name = item.__uri__
if '/' in name:
raise Error("Names cannot contain '/'")
if name.startswith(' '):
raise Error("Names cannot starts with ' '")
if name in self:
raise Error("Name already in use.")
self[name] = item
item.update(**params)
return item
开发者ID:djedproject,项目名称:ptahcms,代码行数:26,代码来源:container.py
示例16: test_loadapi_load_with_parents
def test_loadapi_load_with_parents(self):
content = Content(title='Content')
container = Container(__name__='container', __path__='/container/')
c_uri = content.__uri__
co_uri = container.__uri__
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
transaction.commit()
container = ptah.resolve(co_uri)
container['content'] = ptah.resolve(c_uri)
transaction.commit()
content = ptah.cms.load(c_uri)
self.assertEqual(content.__parent__.__uri__, co_uri)
开发者ID:runyaga,项目名称:ptah,代码行数:16,代码来源:test_loadapi.py
示例17: test_container_keys_with_local
def test_container_keys_with_local(self):
container = Container(__name__="container", __path__="/container/")
content = Content(title="Content")
container["content"] = content
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
c2 = Content(title="Content2")
container["content2"] = c2
self.assertEqual(container.keys(), ["content", "content2"])
self.assertEqual([c.__uri__ for c in container.values()], [content_uri, c2.__uri__])
del container["content"]
self.assertEqual(container.keys(), ["content2"])
self.assertEqual([c.__uri__ for c in container.values()], [c2.__uri__])
开发者ID:mcdonc,项目名称:ptah,代码行数:25,代码来源:test_container.py
示例18: create
def create(self):
data, errors = self.extract()
if errors:
self.add_error_message(errors)
return
# create user
cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.request.registry)
tp = cfg['type']
if not tp.startswith('type:'):
tp = 'type:{0}'.format(tp)
tinfo = ptah.resolve(tp)
user = tinfo.create(
fullname=data['fullname'], username=data['username'], email=data['email'],
validated=data['validated'], suspended=data['suspended'])
user.password = ptah.pwd_tool.encode(data['password'])
tinfo.add(user)
# notify system
self.request.registry.notify(ptah.events.PrincipalAddedEvent(user))
self.request.add_message('User has been created.', 'success')
return HTTPFound(location='.')
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:27,代码来源:user.py
示例19: __init__
def __init__(self, context, request):
self.tinfo = context.__type__
self.roles = [r for r in ptah.get_roles().values() if not r.system]
self.local_roles = local_roles = context.__local_roles__
self.local_principals = [ptah.resolve(principalUri)
for principalUri in self.local_roles]
for p in list(ptah.search_principals('')):
p = ptah.resolve(p.__uri__)
if hasattr(p, 'properties'):
if p.properties.get('roles') and p not in self.local_principals:
self.local_principals.append(p)
self.principals = sorted(self.local_principals, key=lambda p: str(p))
super(ShareForm, self).__init__(context, request)
开发者ID:djedproject,项目名称:ptahcms,代码行数:16,代码来源:forms.py
示例20: create
def create(self):
data, errors = self.extract()
if errors:
self.message(errors, "form-error")
return
# create user
cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.request.registry)
tp = cfg["type"]
if not tp.startswith("type:"):
tp = "type:{0}".format(tp)
tinfo = ptah.resolve(tp)
user = tinfo.create(
name=data["name"],
login=data["login"],
email=data["login"],
validated=data["validated"],
suspended=data["suspended"],
)
user.password = ptah.pwd_tool.encode(data["password"])
tinfo.add(user)
# notify system
self.request.registry.notify(ptah.events.PrincipalAddedEvent(user))
self.message("User has been created.", "success")
return HTTPFound(location=".")
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:31,代码来源:user.py
注:本文中的ptah.resolve函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论