• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.URLPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wiki.models.URLPath的典型用法代码示例。如果您正苦于以下问题:Python URLPath类的具体用法?Python URLPath怎么用?Python URLPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了URLPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:AndreySonetico,项目名称:edx-platform,代码行数:30,代码来源:views.py


示例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])
开发者ID:Kochijadictionary,项目名称:django-wiki,代码行数:7,代码来源:test_basic.py


示例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
开发者ID:pelikanchik,项目名称:edx-platform,代码行数:29,代码来源:views.py


示例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
开发者ID:django-wiki,项目名称:django-wiki,代码行数:29,代码来源:redlinks.py


示例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()
开发者ID:Arken94,项目名称:django-wiki,代码行数:8,代码来源:base.py


示例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()
开发者ID:azaghal,项目名称:django-wiki,代码行数:9,代码来源:test_views.py


示例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()
开发者ID:Arken94,项目名称:django-wiki,代码行数:10,代码来源:test_views.py


示例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>',
     )
开发者ID:Arken94,项目名称:django-wiki,代码行数:13,代码来源:test_links.py


示例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)
开发者ID:django-wiki,项目名称:django-wiki,代码行数:14,代码来源:test_views.py


示例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.'
        )
开发者ID:django-wiki,项目名称:django-wiki,代码行数:30,代码来源:test_views.py


示例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>&lt;/html&gt;only_this</p>")
开发者ID:NablaWebkom,项目名称:django-wiki,代码行数:10,代码来源:test_markdown.py


示例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')
开发者ID:AdityaKashyap,项目名称:edx-platform,代码行数:10,代码来源:test_middleware.py


示例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
开发者ID:bert3141592,项目名称:god,代码行数:54,代码来源:models.py


示例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
开发者ID:openfun,项目名称:fun-apps,代码行数:11,代码来源:views.py


示例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)
开发者ID:django-wiki,项目名称:django-wiki,代码行数:11,代码来源:test_views.py


示例16: setUp

    def setUp(self):

        super(ArticleWebTestBase, self).setUp()

        response = self.c.post(
            reverse('wiki:root_create'),
            {'content': 'root article content', 'title': 'Root Article'},
            follow=True
        )

        self.assertEqual(response.status_code, 200)  # sanity check
        self.root_article = URLPath.root().article
开发者ID:Omosofe,项目名称:django-wiki,代码行数:12,代码来源:base.py


示例17: 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=self.course_math101.location, 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")
开发者ID:ufcvirtual,项目名称:edx-platform,代码行数:14,代码来源:test_middleware.py


示例18: setUp

 def setUp(self):
     super(ArticleTestBase, self).setUp()
     response = self.c.post(
         reverse('wiki:root_create'),
         {'content': 'root article content', 'title': 'Root Article'},
         follow=True)
     self.assertEqual(response.status_code, 200)  # sanity check
     self.root_article = URLPath.root().article
     self.example_data = {
         'content': 'The modified text',
         'current_revision': '1',
         'preview': '1',
         # 'save': '1',  # probably not too important
         'summary': 'why edited',
         'title': 'wiki test'}
开发者ID:DavideyLee,项目名称:django-wiki,代码行数:15,代码来源:base.py


示例19: test_article_list_update

    def test_article_list_update(self):
        """
        Test automatic adding and removing the new article to/from article_list.
        """

        root_data = {
            'content': '[article_list depth:2]',
            'current_revision': str(URLPath.root().article.current_revision.id),
            'preview': '1',
            'title': 'Root Article'
        }

        response = self.client.post(resolve_url('wiki:edit', path=''), root_data)
        self.assertRedirects(response, resolve_url('wiki:root'))

        # verify the new article is added to article_list
        response = self.client.post(
            resolve_url('wiki:create', path=''),
            {'title': 'Sub Article 1', 'slug': 'SubArticle1'}
        )

        self.assertRedirects(
            response,
            resolve_url('wiki:get', path='subarticle1/')
        )
        self.assertContains(self.get_by_path(''), 'Sub Article 1')
        self.assertContains(self.get_by_path(''), 'subarticle1/')

        # verify the deleted article is removed from article_list
        response = self.client.post(
            resolve_url('wiki:delete', path='SubArticle1/'),
            {'confirm': 'on',
             'purge': 'on',
             'revision': str(URLPath.objects.get(slug='subarticle1').article.current_revision.id),
             }
        )

        message = getattr(self.client.cookies['messages'], 'value')

        self.assertRedirects(
            response,
            resolve_url('wiki:get', path='')
        )
        self.assertIn(
            'This article together with all '
            'its contents are now completely gone',
            message)
        self.assertNotContains(self.get_by_path(''), 'Sub Article 1')
开发者ID:django-wiki,项目名称:django-wiki,代码行数:48,代码来源:test_views.py


示例20: setUp

    def setUp(self):
        super(TestAttachmentManagementCommands, self).setUp()

        self.test_file = tempfile.NamedTemporaryFile('w', delete=False, suffix=".txt")
        self.test_file.write("test")

        self.child1 = URLPath.create_urlpath(self.root, 'test-slug', title="Test 1")

        self.attachment1 = models.Attachment.objects.create(
            article=self.child1.article
        )

        self.attachment1_revision1 = models.AttachmentRevision.objects.create(
            attachment=self.attachment1,
            file=self.test_file.name,
        )
开发者ID:Arken94,项目名称:django-wiki,代码行数:16,代码来源:test_commands.py



注:本文中的wiki.models.URLPath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python article.Article类代码示例发布时间:2022-05-26
下一篇:
Python models.Document类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap