本文整理汇总了Python中wiki.models.URLPath类的典型用法代码示例。如果您正苦于以下问题:Python URLPath类的具体用法?Python URLPath怎么用?Python URLPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URLPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_or_create_root
def get_or_create_root():
"""
Returns the root article, or creates it if it doesn't exist.
"""
try:
root = URLPath.root()
if not root.article:
root.delete()
raise NoRootURL
return root
except NoRootURL:
pass
starting_content = "\n".join((
_("Welcome to the {platform_name} Wiki").format(platform_name=get_themed_value('PLATFORM_NAME',
settings.PLATFORM_NAME)),
"===",
_("Visit a course wiki to add an article."),
))
root = URLPath.create_root(title=_("Wiki"), content=starting_content)
article = root.article
article.group = None
article.group_read = True
article.group_write = False
article.other_read = True
article.other_write = False
article.save()
return root
示例2: test_manager
def test_manager(self):
root = URLPath.create_root()
child = URLPath.create_article(root, "child")
self.assertEqual(root.parent, None)
self.assertEqual(list(root.children.all().active()), [child])
示例3: get_or_create_root
def get_or_create_root():
"""
Returns the root article, or creates it if it doesn't exist.
"""
try:
root = URLPath.root()
if not root.article:
root.delete()
raise NoRootURL
return root
except NoRootURL:
pass
starting_content = "\n".join((
"Welcome to the edX Wiki",
"===",
"Visit a course wiki to add an article."))
root = URLPath.create_root(title="Wiki",
content=starting_content)
article = root.article
article.group = None
article.group_read = True
article.group_write = False
article.other_read = True
article.other_write = False
article.save()
return root
示例4: get_class
def get_class(self, el):
href = el.get("href")
if not href:
return
# The autolinker turns email links into links with many HTML entities.
# These entities are further escaped using markdown-specific codes.
# First unescape the markdown-specific, then use html.unescape.
href = AndSubstitutePostprocessor().run(href)
href = html.unescape(href)
try:
url = urlparse(href)
except ValueError:
return
if url.scheme == "mailto":
return
if url.scheme or url.netloc or url.path.startswith("/"):
# Contains a hostname or is an absolute link => external
return self.external_class
# Ensure that path ends with a slash
relpath = url.path.rstrip("/") + "/"
target = urljoin_internal(self.my_urlpath.path, relpath)
if target is None:
# Relative path goes outside wiki URL space => external
return self.external_class
try:
URLPath.get_by_path(target)
except URLPath.DoesNotExist:
return self.broken_class
return self.internal_class
示例5: setUp
def setUp(self):
super(RequireRootArticleMixin, self).setUp()
self.root = URLPath.create_root()
self.root_article = URLPath.root().article
rev = self.root_article.current_revision
rev.title = "Root Article"
rev.content = "root article content"
rev.save()
示例6: get_article
def get_article(self, cont):
urlpath = URLPath.create_urlpath(
URLPath.root(),
"html_attach",
title="TestAttach",
content=cont
)
self._create_test_attachment(urlpath.path)
return urlpath.article.render()
示例7: get_article
def get_article(self, cont, image):
urlpath = URLPath.create_urlpath(
URLPath.root(),
"html_image",
title="TestImage",
content=cont
)
if image:
self._create_test_image(urlpath.path)
return urlpath.article.render()
示例8: test_works_with_lazy_functions
def test_works_with_lazy_functions(self):
URLPath.create_root()
config = (
('base_url', reverse_lazy('wiki:get', kwargs={'path': ''})),
)
md = markdown.Markdown(
extensions=['extra', WikiPathExtension(config)]
)
text = '[Français](wiki:/fr)'
self.assertEqual(
md.convert(text),
'<p><a class="wikipath linknotfound" href="/fr">Français</a></p>',
)
示例9: test_edit_save
def test_edit_save(self):
old_revision = URLPath.root().article.current_revision
self.get_url('wiki:edit', path='')
self.fill({
'#id_content': 'Something 2',
'#id_summary': 'why edited',
'#id_title': 'wiki test'
})
self.submit('#id_save')
self.assertTextPresent('Something 2')
self.assertTextPresent('successfully added')
new_revision = URLPath.root().article.current_revision
self.assertIn('Something 2', new_revision.content)
self.assertEqual(new_revision.revision_number, old_revision.revision_number + 1)
示例10: test_revision_conflict
def test_revision_conflict(self):
"""
Test the warning if the same article is being edited concurrently.
"""
example_data = {
'content': 'More modifications',
'current_revision': str(URLPath.root().article.current_revision.id),
'preview': '0',
'save': '1',
'summary': 'why edited',
'title': 'wiki test'
}
response = self.client.post(
resolve_url('wiki:edit', path=''),
example_data
)
self.assertRedirects(response, resolve_url('wiki:root'))
response = self.client.post(
resolve_url('wiki:edit', path=''),
example_data
)
self.assertContains(
response,
'While you were editing, someone else changed the revision.'
)
示例11: test_html_removal
def test_html_removal(self):
urlpath = URLPath.create_article(
self.root,
'html_removal',
title="Test 1",
content="</html>only_this"
)
self.assertEqual(urlpath.article.render(), "<p></html>only_this</p>")
示例12: setUp
def setUp(self):
"""Test setup."""
self.wiki = get_or_create_root()
self.course_math101 = CourseFactory.create(org='edx', number='math101', display_name='2014', metadata={'use_unique_wiki_id': 'false'})
self.course_math101_instructor = InstructorFactory(course_key=self.course_math101.id, username='instructor', password='secret')
self.wiki_math101 = URLPath.create_article(self.wiki, 'math101', title='math101')
self.client = Client()
self.client.login(username='instructor', password='secret')
示例13: create
def create(cls, user, regional_level, title, question, topics, organisation=None):
try:
root_path = URLPath.objects.get(parent_id=None)
except Exception:
pass
else:
# Construct arguments
user_regional_levels = {
'1': user.personalid.municipality,
'2': user.personalid.province,
'3': user.personalid.country
}
regional_name = user_regional_levels[regional_level]
slug = str(regional_level) + '_' + regional_name + '_' + slugify(title)
content = '# Context\r\n# Consequences\r\n'
user_message = 'Initiated \'{}\''.format(title)
article_kwargs = {
'owner': user,
'group': None,
'group_read': True,
'group_write': False,
'other_read': False,
'other_write': False
}
# Make new wiki URLPath
new_url_path = URLPath.create_article(root_path,
slug,
title=title,
article_kwargs=article_kwargs,
content=content,
user_message=user_message,
user=user)
new_url_path.save()
try:
# Make new ConstructionProposal
construction_proposal = cls(regional_level=regional_level,
regional_name=regional_name,
title=title,
slug=slug,
question=question,
creator=user,
organisation=organisation,
wiki=new_url_path)
construction_proposal.save()
except Exception:
pass
else:
# Add topics
construction_proposal.topics.add(*topics)
# Return partially saved instance
return construction_proposal
return None
示例14: get_urlpath
def get_urlpath(course_id):
"""Returns url path of root wiki page for course."""
# Offical edX way to replace slashes by dots: course_key.replace('/', '.')
course_key = CourseKey.from_string(course_id)
course = get_course_by_id(course_key)
course_slug = course_wiki_slug(course)
try:
urlpath = URLPath.get_by_path(course_slug)
except URLPath.DoesNotExist:
urlpath = None
return urlpath
示例15: test_preview_and_save
def test_preview_and_save(self):
self.get_url('wiki:edit', path='')
self.fill({
'#id_content': 'Some changed stuff',
'#id_summary': 'why edited',
'#id_title': 'wiki test'
})
self.click('#id_preview')
self.submit('#id_preview_save_changes')
new_revision = URLPath.root().article.current_revision
self.assertIn("Some changed stuff", new_revision.content)