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

Python article.Article类代码示例

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

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



在下文中一共展示了Article类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_lost_and_found

 def get_lost_and_found():
     if ns.lost_and_found:
         return ns.lost_and_found
     try:
         ns.lost_and_found = URLPath.objects.get(
             slug=settings.LOST_AND_FOUND_SLUG,
             parent=URLPath.root(),
             site=site)
     except URLPath.DoesNotExist:
         article = Article(group_read=True,
                           group_write=False,
                           other_read=False,
                           other_write=False)
         article.add_revision(
             ArticleRevision(
                 content=_(
                     'Articles who lost their parents\n'
                     '===============================\n\n'
                     'The children of this article have had their parents deleted. You should probably find a new home for them.'),
                 title=_("Lost and found")))
         ns.lost_and_found = URLPath.objects.create(
             slug=settings.LOST_AND_FOUND_SLUG,
             parent=URLPath.root(),
             site=site,
             article=article)
         article.add_object_relation(ns.lost_and_found)
     return ns.lost_and_found
开发者ID:Arken94,项目名称:django-wiki,代码行数:27,代码来源:urlpath.py


示例2: on_article_delete

def on_article_delete(instance, *args, **kwargs):
    # If an article is deleted, then throw out its URLPaths
    # But move all descendants to a lost-and-found node.
    site = Site.objects.get_current()

    # Get the Lost-and-found path or create a new one
    try:
        lost_and_found = URLPath.objects.get(slug=settings.LOST_AND_FOUND_SLUG, parent=URLPath.root(), site=site)
    except URLPath.DoesNotExist:
        article = Article(group_read=True, group_write=False, other_read=False, other_write=False)
        article.add_revision(
            ArticleRevision(
                content=_(
                    u"Articles who lost their parents\n"
                    "===============================\n\n"
                    "The children of this article have had their parents deleted. You should probably find a new home for them."
                ),
                title=_(u"Lost and found"),
            )
        )
        lost_and_found = URLPath.objects.create(
            slug=settings.LOST_AND_FOUND_SLUG, parent=URLPath.root(), site=site, article=article
        )
        article.add_object_relation(lost_and_found)

    for urlpath in URLPath.objects.filter(articles__article=instance, site=site):
        # Delete the children
        for child in urlpath.get_children():
            child.move_to(lost_and_found)
        # ...and finally delete the path itself
        # TODO: This should be unnecessary because of URLPath.article(...ondelete=models.CASCADE)
        urlpath.delete()
开发者ID:kamilgrymuza,项目名称:django-wiki,代码行数:32,代码来源:urlpath.py


示例3: dispatch

   def dispatch(self, request, workgroup_slug, *args, **kwargs):   
       self.workgroup = get_object_or_404(WorkGroup, slug=workgroup_slug)         
       article = Article.get_for_object(Article.get_for_object(self.workgroup)) 
       
       self.sidebar_plugins = plugin_registry.get_sidebar()
       self.sidebar = []
 
       return super(WikiEdit, self).dispatch(request, article, *args, **kwargs)
开发者ID:Gnuside,项目名称:imaginationforpeople,代码行数:8,代码来源:views.py


示例4: get_context_data

    def get_context_data(self, **kwargs):
        """
        Adds the member of the associated ML if there's one
        """
        context = super(GroupDetailView, self).get_context_data(**kwargs)
        
        workgroup = context['workgroup']

        # Look up mailing list members
        context.update(lookup_ml_membership(workgroup))

        # Wiki
        try:
            article = Article.get_for_object(workgroup)
        except ArticleForObject.DoesNotExist:
            article = Article.objects.create()
            article.add_object_relation(workgroup)
            revision = ArticleRevision(title=workgroup.name, content='')
            article.add_revision(revision)

        context['wiki_article'] = article
        
        context['group_projects'] = workgroup.projects.all()
            
        return context
开发者ID:Gnuside,项目名称:imaginationforpeople,代码行数:25,代码来源:views.py


示例5: create_urlpath

    def create_urlpath(
            cls,
            parent,
            slug,
            site=None,
            title="Root",
            article_kwargs={},
            request=None,
            article_w_permissions=None,
            **revision_kwargs):
        """
        Utility function:
        Creates a new urlpath with an article and a new revision for the
        article

        :returns: A new URLPath instance
        """
        if not site:
            site = Site.objects.get_current()
        article = Article(**article_kwargs)
        article.add_revision(ArticleRevision(title=title, **revision_kwargs),
                             save=True)
        article.save()
        newpath = cls.objects.create(
            site=site,
            parent=parent,
            slug=slug,
            article=article)
        article.add_object_relation(newpath)
        return newpath
开发者ID:Arken94,项目名称:django-wiki,代码行数:30,代码来源:urlpath.py


示例6: create_article

def create_article(bustopic,title="Root", article_kwargs={}, content="",user_message="",request=None):
    """Utility function:
    Create a new urlpath with an article and a new revision for the article"""
    article = Article(**article_kwargs)
    ar = ArticleRevision()

    ar.content = content 
    ar.user_message =  user_message 
    ar.deleted = False
    if request:
        ar.set_from_request(request)
    else:
        ar.ip_address = None
        ar.user = get_default_user()
    article.add_revision(ar, save=True)

    article.save()
    bustopic.article=article
    bustopic.save() 
    return ar
开发者ID:zouf,项目名称:as2,代码行数:20,代码来源:topic_operations.py


示例7: create_article

 def create_article(cls, parent, slug, site=None, title="Root", article_kwargs={}, **kwargs):
     """Utility function:
     Create a new urlpath with an article and a new revision for the article"""
     if not site:
         site = Site.objects.get_current()
     article = Article(**article_kwargs)
     article.add_revision(ArticleRevision(title=title, **kwargs), save=True)
     article.save()
     newpath = cls.objects.create(site=site, parent=parent, slug=slug, article=article)
     article.add_object_relation(newpath)
     return newpath
开发者ID:kamilgrymuza,项目名称:django-wiki,代码行数:11,代码来源:urlpath.py


示例8: create_root

 def create_root(cls, site=None, title="Root", **kwargs):
     if not site:
         site = Site.objects.get_current()
     root_nodes = cls.objects.root_nodes().filter(site=site)
     if not root_nodes:
         # (get_or_create does not work for MPTT models??)
         article = Article()
         article.add_revision(ArticleRevision(title=title, **kwargs), save=True)
         article.save()
         root = cls.objects.create(site=site, article=article)
         article.add_object_relation(root)
     else:
         root = root_nodes[0]
     return root
开发者ID:kamilgrymuza,项目名称:django-wiki,代码行数:14,代码来源:urlpath.py


示例9: create_root

 def create_root(cls, site=None, title="Root", request=None, **kwargs):
     if not site:
         site = Site.objects.get_current()
     root_nodes = cls.objects.root_nodes().filter(site=site)
     if not root_nodes:
         article = Article()
         revision = ArticleRevision(title=title, **kwargs)
         if request:
             revision.set_from_request(request)
         article.add_revision(revision, save=True)
         article.save()
         root = cls.objects.create(site=site, article=article)
         article.add_object_relation(root)
     else:
         root = root_nodes[0]
     return root
开发者ID:azaghal,项目名称:django-wiki,代码行数:16,代码来源:urlpath.py


示例10: full_dehydrate

 def full_dehydrate(self, bundle, for_list=False):
     bundle = ModelResource.full_dehydrate(self, bundle, for_list)
     if bundle.obj.picture:
         thumbnailer = get_thumbnailer(bundle.obj.picture)
         thumbnail_options = {'size': (ResizeThumbApi.width, ResizeThumbApi.height)}
         bundle.data["thumb"] = thumbnailer.get_thumbnail(thumbnail_options).url
     else:
         bundle.data["thumb"] = None
     if for_list is False:
         bundle.data["tags"] = [tag.name for tag in Tag.objects.get_for_object(bundle.obj)]
         if(bundle.obj.picture):
             thumbnail_options = {'size': (ResizeDisplay.width, ResizeDisplay.width)}
             bundle.data["image"] = thumbnailer.get_thumbnail(thumbnail_options).url
         else:
             bundle.data["image"] = None
         try:
             bundle.data["article"] = Article.get_for_object(bundle.obj).render()
         except ArticleForObject.DoesNotExist:
             bundle.data["article"] = None
     return bundle
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:imaginationforpeople,代码行数:20,代码来源:workgroup.py


示例11: import_page

    def import_page(self, api, site, page, current_site, url_root, user_matching, replace_existing):

        import pypandoc

        # Filter titles, to avoid stranges charaters.
        title = only_printable(page.title)
        urltitle = slugify(only_printable(urllib.unquote(page.urltitle))[:50])

        added = 1

        while urltitle in self.articles_worked_on:
            title = only_printable(page.title) + " " + str(added)
            urltitle = only_printable(slugify((urllib.unquote(page.urltitle))[:47] + " " + str(added)))
            added += 1

        self.articles_worked_on.append(urltitle)

        print "Working on %s (%s)" % (title, urltitle)

        # Check if the URL path already exists
        try:
            urlp = URLPath.objects.get(slug=urltitle)

            self.matching_old_link_new_link[page.title] = urlp.article.get_absolute_url()

            if not replace_existing:
                print "\tAlready existing, skipping..."
                return

            print "\tDestorying old version of the article"
            urlp.article.delete()

        except URLPath.DoesNotExist:
            pass

        # Create article
        article = Article()

        for history_page in page.getHistory()[-2:][::-1]:

            try:
                if history_page['user'] in user_matching:
                    user = get_user_model().objects.get(pk=user_matching[history_page['user']])
                else:
                    user = get_user_model().objects.get(username=history_page['user'])
            except get_user_model().DoesNotExist:
                print "\tCannot found user with username=%s. Use --user-matching \"%s:<user_pk>\" to manualy set it" % (history_page['user'], history_page['user'], )
                user = None

            article_revision = ArticleRevision()
            article_revision.content = pypandoc.convert(history_page['*'], 'md', 'mediawiki')
            article_revision.title = title
            article_revision.user = user
            article_revision.owner = user

            article.add_revision(article_revision, save=True)

            article_revision.created = history_page['timestamp']
            article_revision.save()

        # Updated lastest content WITH expended templates
        # TODO ? Do that for history as well ?
        article_revision.content = pypandoc.convert(striptags(page.getWikiText(True, True).decode('utf-8')).replace('__NOEDITSECTION__', '').replace('__NOTOC__', ''), 'md', 'mediawiki')
        article_revision.save()

        article.save()

        upath = URLPath.objects.create(site=current_site, parent=url_root, slug=urltitle, article=article)
        article.add_object_relation(upath)

        self.matching_old_link_new_link[page.title] = upath.article.get_absolute_url()

        self.articles_imported.append((article, article_revision))
开发者ID:CBitLabs,项目名称:django-wiki,代码行数:73,代码来源:mediawiki_import.py


示例12: import_page

    def import_page(
            self,
            api,
            site,
            page,
            current_site,
            url_root,
            user_matching,
            replace_existing,
            ):

        from wikitools.pagelist import listFromQuery



        # Filter titles, to avoid stranges charaters.
        title = page.title
        urltitle = title
        urltitle = urltitle.replace("ø", "o") 
        urltitle = urltitle.replace("æ", "ae") 
        urltitle = urltitle.replace("å", "a") 
        urltitle = urltitle.replace("Ø", "O") 
        urltitle = urltitle.replace("Æ", "AE") 
        urltitle = urltitle.replace("Å", "A") 
        urltitle = only_printable(urltitle)
        urltitle = slugify(only_printable(urllib.parse.unquote(urltitle))[:50])


        added = 1

        while urltitle in self.articles_worked_on:
            title = only_printable("{} {}".format(page.title, added))
            urltitle = slugify(
                "{} {}".format(only_printable(urllib.parse.unquote(page.urltitle))[:47], added)
            )

            added += 1

        self.articles_worked_on.append(urltitle)

        print("Working on {} ({})".format(title, urltitle))
        print(url_root)
        print(urltitle)
        print()
        # Check if the URL path already exists
        try:
            urlp = URLPath.objects.get(slug=urltitle)

            self.matching_old_link_new_link[
                page.title] = urlp.article.get_absolute_url()

            if not replace_existing:
                print("\tAlready existing, skipping...")
                return

            print("\tDestorying old version of the article")
            urlp.article.delete()

        except URLPath.DoesNotExist:
            pass

        # Create article
        article = Article()

        history_page = page.getHistory()[0]

        try:
            if history_page['user'] in user_matching:
                user = get_user_model().objects.get(
                    pk=user_matching[
                        history_page['user']])
            else:
                user = get_user_model().objects.get(
                    username=history_page['user'])
        except get_user_model().DoesNotExist:
            user = None
        except Exception:
            print("Couldn't find user. Something is weird.")

        article_revision = ArticleRevision()
        article_revision.content = refactor(page.getWikiText())
        article_revision.title = title
        article_revision.user = user
        article_revision.owner = user
        article_revision.content = re.sub("\[\[.*(Category|Kategori).*\]\]\n", "", article_revision.content)

        article.add_revision(article_revision, save=True)

        article_revision.created = history_page['timestamp']
        article_revision.save()

        # Updated lastest content WITH expended templates
        # TODO ? Do that for history as well ?
        
        article_revision.save()

        article.save()

        upath = URLPath.objects.create(
            site=current_site,
#.........这里部分代码省略.........
开发者ID:NablaWebkom,项目名称:django-wiki,代码行数:101,代码来源:mediawiki_import.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python parser.wiki_to_html函数代码示例发布时间:2022-05-26
下一篇:
Python models.URLPath类代码示例发布时间: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