本文整理汇总了Python中models.PageOperationMixin类的典型用法代码示例。如果您正苦于以下问题:Python PageOperationMixin类的具体用法?Python PageOperationMixin怎么用?Python PageOperationMixin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageOperationMixin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: validate_new_content
def validate_new_content(self, base_revision, new_body, user):
# check metadata
new_md = PageOperationMixin.parse_metadata(new_body)
## prevent self-revoke
acl_r = new_md.get('read', '')
acl_r = acl_r.split(',') if acl_r else []
acl_w = new_md.get('write', '')
acl_w = acl_w.split(',') if acl_w else []
if not self.can_read(user, acl_r=acl_r, acl_w=acl_w):
raise ValueError('Cannot restrict your permission')
if not self.can_write(user, acl_r=acl_r, acl_w=acl_w):
raise ValueError('Cannot restrict your permission')
## prevent circular-redirection
try:
WikiPage._follow_redirect(self, new_md.get(u'redirect'))
except ValueError as e:
raise e
# check data
new_data = PageOperationMixin.parse_data(self.title, new_body, new_md['schema'])
if any(type(value) == schema.InvalidProperty for value in new_data.values()):
raise ValueError('Invalid schema data')
# check revision
if self.revision < base_revision:
raise ValueError('Invalid revision number: %d' % base_revision)
# check headings
if not TocGenerator(md.convert(new_body)).validate():
raise ValueError("Duplicate paths not allowed")
return new_data, new_md
开发者ID:jangxyz,项目名称:ecogwiki,代码行数:35,代码来源:wiki_page.py
示例2: get_preview_instance
def get_preview_instance(self, preview_body):
page = PageOperationMixin()
page.body = preview_body
page.title = self.title
page.revision = self.revision
page.inlinks = self.inlinks
page.outlinks = self.outlinks
page.related_links = self.related_links
page.older_title = self.older_title
page.newer_title = self.newer_title
page.updated_at = self.updated_at
return page
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:14,代码来源:wiki_page.py
示例3: test_normal
def test_normal(self):
expected = {
u'hello': u'a b c',
u'x': None,
u'z': u'what?',
}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'.hello a b c\n.x\n.z what?\nblahblah')
self.assertEqual(expected, actual)
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:9,代码来源:test_models.py
示例4: _update_content_all
def _update_content_all(self, body, base_revision, comment, user, force_update, dont_create_rev, dont_defer):
# do not update if the body is not changed
if not force_update and self.body == body:
return False
# validate and prepare new contents
new_data, new_md = self.validate_new_content(base_revision, body, user)
new_body = self._merge_if_needed(base_revision, body)
# get old data and metadata
old_md = self.metadata.copy()
old_data = self.data.copy()
# delete caches
caching.del_rendered_body(self.title)
caching.del_hashbangs(self.title)
caching.del_metadata(self.title)
caching.del_data(self.title)
# update model and save
self.body = new_body
self.modifier = user
self.description = PageOperationMixin.make_description(new_body)
self.acl_read = new_md.get('read', '')
self.acl_write = new_md.get('write', '')
self.comment = comment
self.itemtype_path = schema.get_itemtype_path(new_md['schema'])
self._update_pub_state(new_md, old_md)
if not dont_create_rev:
self.revision += 1
if not force_update:
self.updated_at = datetime.now()
self.put()
# create revision
if not dont_create_rev:
rev_key = self._rev_key()
rev = WikiPageRevision(parent=rev_key, title=self.title, body=self.body,
created_at=self.updated_at, revision=self.revision,
comment=self.comment, modifier=self.modifier,
acl_read=self.acl_read, acl_write=self.acl_write)
rev.put()
# update inlinks, outlinks and schema data index
self.update_links_and_data(old_md.get('redirect'), new_md.get('redirect'), old_data, new_data, dont_defer)
# delete config cache
if self.title == '.config':
caching.del_config()
# delete title cache if it's a new page
if self.revision == 1:
caching.del_titles()
return True
开发者ID:Salada,项目名称:ecogwiki,代码行数:55,代码来源:wiki_page.py
示例5: get_config
def get_config(cls):
result = caching.get_config()
if result is None:
result = main.DEFAULT_CONFIG
try:
config_page = cls.get_by_title('.config')
user_config = yaml.load(PageOperationMixin.remove_metadata(config_page.body))
except:
user_config = None
user_config = user_config or {}
def merge_dict(target_dict, source_dict):
for (key, value) in source_dict.iteritems():
if type(value) != dict:
target_dict[key] = value
else:
merge_dict(target_dict.setdefault(key, {}), value)
merge_dict(result, user_config)
caching.set_config(result)
return result
开发者ID:Salada,项目名称:ecogwiki,代码行数:23,代码来源:wiki_page.py
示例6: test_default_section
def test_default_section(self):
data = PageOperationMixin.parse_sections(u'Hello')
self.assertEqual({'articleBody'}, set(data.keys()))
self.assertEqual(u'Hello', data['articleBody'])
开发者ID:Sunsoo,项目名称:incodom,代码行数:4,代码来源:test_schema.py
示例7: test_should_ignore_yaml_schema_block
def test_should_ignore_yaml_schema_block(self):
self.assertEqual(u'Hello',
PageOperationMixin.make_description(u'.schema Book\n #!yaml/schema\n author: A\n\nHello', 20))
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:3,代码来源:test_models.py
示例8: test_should_ignore_metadata
def test_should_ignore_metadata(self):
self.assertEqual(u'Hello',
PageOperationMixin.make_description(u'.pub\n\nHello', 20))
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:3,代码来源:test_models.py
示例9: test_tab_and_space_mixed
def test_tab_and_space_mixed(self):
body = u'\t#!yaml/schema\n alternateName: hi\n\turl: http://x.com\n name: "Hello"\n'
data = PageOperationMixin.parse_schema_yaml(body)
self.assertEqual(data['name'], u'Hello')
self.assertEqual(data['alternateName'], u'hi')
self.assertEqual(data['url'], u'http://x.com')
开发者ID:Sunsoo,项目名称:incodom,代码行数:6,代码来源:test_schema.py
示例10: test_multiple_authors
def test_multiple_authors(self):
data = PageOperationMixin.parse_data(u'Hello', u'[[author::AK]] and [[author::TK]]', u'Book')
self.assertEqual([u'AK', u'TK'], [v.pvalue for v in data['author']])
开发者ID:Sunsoo,项目名称:incodom,代码行数:3,代码来源:test_schema.py
示例11: test_no_data
def test_no_data(self):
data = PageOperationMixin.parse_data(u'Hello', u'Hello')
self.assertEqual(['articleBody', 'name', 'schema'], data.keys())
self.assertEqual(u'Hello', data['name'].pvalue)
self.assertEqual(u'Thing/CreativeWork/Article/', data['schema'].pvalue)
self.assertEqual(u'Hello', data['articleBody'].pvalue)
开发者ID:Sunsoo,项目名称:incodom,代码行数:6,代码来源:test_schema.py
示例12: test_empty_string
def test_empty_string(self):
expected = {}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'')
self.assertEqual(expected, actual)
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:5,代码来源:test_models.py
示例13: test_no_schema
def test_no_schema(self):
self.assertEqual({}, PageOperationMixin.parse_schema_yaml(u'Hello'))
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:2,代码来源:test_models.py
示例14: absolute_url
def absolute_url(self):
return u'/%s?rev=%d' % (PageOperationMixin.title_to_path(self.title), int(self.revision))
开发者ID:0hoo,项目名称:ecogwiki,代码行数:2,代码来源:wiki_page_revision.py
示例15: test_specifying_default_section
def test_specifying_default_section(self):
data = PageOperationMixin.parse_sections(u'Hello', u'longText')
self.assertEqual({'longText'}, set(data.keys()))
self.assertEqual(u'Hello', data['longText'])
开发者ID:Sunsoo,项目名称:incodom,代码行数:4,代码来源:test_schema.py
示例16: test_additional_sections
def test_additional_sections(self):
data = PageOperationMixin.parse_sections(u'Hello\n\nsection1::---\n\nHello\n\nthere\n\nsection2::---\n\nGood\n\nbye\n')
self.assertEqual({'articleBody', 'section1', 'section2'}, set(data.keys()))
self.assertEqual(u'Hello', data['articleBody'])
self.assertEqual(u'Hello\n\nthere', data['section1'])
self.assertEqual(u'Good\n\nbye', data['section2'])
开发者ID:Sunsoo,项目名称:incodom,代码行数:6,代码来源:test_schema.py
示例17: test_no_metadata
def test_no_metadata(self):
expected = {}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'Hello\nThere')
self.assertEqual(expected, actual)
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:5,代码来源:test_models.py
示例18: test_author_and_isbn
def test_author_and_isbn(self):
data = PageOperationMixin.parse_data(u'Hello', u'[[author::AK]]\n{{isbn::1234567890}}', u'Book')
self.assertEqual(u'AK', data['author'].pvalue)
self.assertEqual(u'1234567890', data['isbn'].pvalue)
开发者ID:Sunsoo,项目名称:incodom,代码行数:4,代码来源:test_schema.py
示例19: test_try_newline
def test_try_newline(self):
self.assertEqual(u'Hello', PageOperationMixin.make_description(u'Hello\nWorld', 20))
开发者ID:Sunsoo,项目名称:ecogwiki,代码行数:2,代码来源:test_models.py
示例20: test_re_match
def test_re_match(self):
body = u'''\t#!yaml/schema\n url: "http://anotherfam.kr/"\n\n\n[[\uc81c\uc791\ub450\ub808]]\ub97c ...\n'''
data = PageOperationMixin.parse_schema_yaml(body)
self.assertEqual(data['url'], 'http://anotherfam.kr/')
开发者ID:Sunsoo,项目名称:incodom,代码行数:4,代码来源:test_schema.py
注:本文中的models.PageOperationMixin类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论