def create_alphabetic_urls(url_slug='ru'):
    '''
    generate alphabetic table of content for selected language
    :param url_slug:
    :return:
    '''
    urlpath = URLPath.objects.get(slug=url_slug)
    user = User.objects.get(username='******')
    article = Article.objects.get(urlpath=urlpath)
    for char in ALPHABET:
        try:
            URLPath.objects.get(slug=char)
        except ObjectDoesNotExist:
            URLPath.create_article(urlpath,
                                   char,
                                   title=char.upper(),
                                   content='[article_list depth:2]',
                                   user_message='',
                                   user=user,
                                   ip_address=None,
                                   article_kwargs={
                                       'owner': user,
                                       'group': article.group,
                                       'group_read': article.group_read,
                                       'group_write': article.group_write,
                                       'other_read': article.other_read,
                                       'other_write': article.other_write,
                                   })
Example #2
0
def refresh_automated_report(slug, pk=None):
    Investigation = apps.get_model('db.Investigation')
    Sample = apps.get_model('db.Sample')
    BiologicalReplicate = apps.get_model('db.BiologicalReplicate')
    BiologicalReplicateProtocol = apps.get_model(
        'db.BiologicalReplicateProtocol')
    ComputationalPipeline = apps.get_model('db.ComputationalPipeline')

    slug_to_model = {'investigation': Investigation, 'sample': Sample}

    if pk is None:
        article = URLPath.get_by_path(slug).article
    else:
        try:
            article = URLPath.get_by_path("%s/%d" % (slug, pk)).article
        except URLPath.DoesNotExist:
            try:
                obj = slug_to_model[slug].objects.get(pk=pk)
            except slug_to_model[slug].DoesNotExist:
                raise ValueError("No such pk found, no wiki entry to update")
            try:
                root = URLPath.get_by_path(slug)
            except URLPath.DoesNotExist:
                raise ValueError(
                    "No such slug found, is your wiki initialized?")
            print("Creating new article")
            try:
                slug_to_model[slug]._meta.get_field("name")
                title = obj.name
            except:
                title = "%s %d" % (slug, pk)
            article = URLPath.create_urlpath(root,
                                   slug="%d" % (pk,),
                                   title=title,
                                   content="This page has been automatically" \
                                           "generated. You may edit at will").article
    current_content = article.current_revision.content
    md = markdown.Markdown()
    inv_html = md.convert(current_content)
    new_content = ""
    skip_until_h1 = False
    added = False
    for line in md.lines:
        if skip_until_h1 & (not line.startswith("# ")):
            continue
        elif skip_until_h1 & line.startswith("# "):
            skip_until_h1 = False
        if line == '# Automated Report':
            new_content += get_wiki_report(slug, pk=pk)
            skip_until_h1 = True
            added = True
        else:
            new_content += line + "\r\n"
    if not added:
        new_content += get_wiki_report(slug, pk=pk)
    article_revision = ArticleRevision(title=article.current_revision.title,
                                       content=new_content)
    article.add_revision(article_revision)
Example #3
0
 def _refresh_root(self):
     if "/" not in self.slug:
         try:
             self.root = URLPath.get_by_path("/")
         except:
             if self.slug == "root":
                 self.root = self._create_root()
             else:
                 raise ValueError("No root created. Make sure root.md is processed first")
     else:
         try:
             root_name = "/".join(self.slug.split("/")[:-1])
             self.root = URLPath.get_by_path(root_name)
         except:
             self.root = None
    def handle(self, *args, **options):

        try:
            import wikitools
        except ImportError:
            raise CommandError(
                'You need to install wikitools to use this command !')

        user_matching = {}

        for um in options['user_matching']:
            mu = um[::-1]
            kp, emanresu = mu.split(':', 1)

            pk = kp[::-1]
            username = emanresu[::-1]

            user_matching[username] = pk

        api_url, api_username, api_password = self.get_params(args)

        site = wikitools.wiki.Wiki(api_url)
        site.login(api_username, "dummy")

        pages = self.get_all_pages(wikitools.api, site)

        current_site = Site.objects.get_current()
        url_root = URLPath.root()
        print(url_root)

        oldpaths= [article.urlpath_set.all()[0] for article in Article.objects.all() if article.urlpath_set.all()[0].path.count("/") < 3]

        images = wikitools.api.APIRequest(
            site, {
                'action': 'query', 'list': 'allimages',
                'aiprop': 'url'}
            ).query()

        for image in images['query']['allimages']:
            print(image['url'])

        for page in pages:
            #root = self.get_page_parent(page, ["boker", "diverse", "f*g/alle_fag", "folk", "foreninger_og_organisasjoner", "studieprogrammer", "utveksling_info", "utveksling_info/universiteter", "studieteknisk"], "diverse")
            root = self.get_page_parent(page, ["f*g", "boker"], "diverse")

            if root != "ignore":

                for path in oldpaths:
                    if path.path == root + "/":
                        url_root = path
                        break

                self.import_page(
                    wikitools.api,
                    site,
                    page,
                    current_site,
                    url_root,
                    user_matching,
                    options['replace_existing'])
Example #5
0
 def update_wiki(self):
     if (self.slug == "root"):
         return  #Already made in get_root() if not made
     try:
         wiki_page = URLPath.get_by_path(self.prefix + "/" + self.slug)
         #Create a new revision and update with the template content
         article = wiki_page.article
         article_revision = ArticleRevision(
             title=article.current_revision.title, content=self.content)
         article.add_revision(article_revision)
     except URLPath.DoesNotExist:
         print("Creating wiki page for slug %s prefix %s" %
               (self.slug, self.prefix))
         wiki_page = URLPath.create_urlpath(self.root,
                                            slug=self.slug,
                                            title=self.title,
                                            content=self.content)
    def handle(self, *args, **options):

        try:
            import wikitools
        except ImportError:
            raise CommandError(
                'You need to install wikitools to use this command !')

        user_matching = {}

        for um in options['user_matching']:
            mu = um[::-1]
            kp, emanresu = mu.split(':', 1)

            pk = kp[::-1]
            username = emanresu[::-1]

            user_matching[username] = pk

        api_url, api_username, api_password = self.get_params(args)

        site = wikitools.wiki.Wiki(api_url)
        site.login(api_username, "dummy")

        pages = self.get_all_pages(wikitools.api, site)

        current_site = Site.objects.get_current()
        url_root = URLPath.root()
        print(url_root)

        oldpaths = [
            article.urlpath_set.all()[0] for article in Article.objects.all()
            if article.urlpath_set.all()[0].path.count("/") < 3
        ]

        images = wikitools.api.APIRequest(site, {
            'action': 'query',
            'list': 'allimages',
            'aiprop': 'url'
        }).query()

        for image in images['query']['allimages']:
            print(image['url'])

        for page in pages:
            #root = self.get_page_parent(page, ["boker", "diverse", "f*g/alle_fag", "folk", "foreninger_og_organisasjoner", "studieprogrammer", "utveksling_info", "utveksling_info/universiteter", "studieteknisk"], "diverse")
            root = self.get_page_parent(page, ["f*g", "boker"], "diverse")

            if root != "ignore":

                for path in oldpaths:
                    if path.path == root + "/":
                        url_root = path
                        break

                self.import_page(wikitools.api, site, page, current_site,
                                 url_root, user_matching,
                                 options['replace_existing'])
 def create_article(self, parent, slug, title):
     from wiki.models.urlpath import URLPath
     return URLPath.create_article(parent,
                                   slug,
                                   title=title,
                                   article_kwargs={
                                       'group_write': True,
                                       'other_write': True,
                                   })
Example #8
0
 def update_wiki(self):
     try:
         print("Retrieving slug %s" % (self.slug,))
         wiki_page = URLPath.get_by_path(self.slug)
         #Create a new revision and update with the template content
         article = wiki_page.article
         article_revision = ArticleRevision(title=article.current_revision.title,
                                            content=self.content)
         article.add_revision(article_revision)
     except URLPath.DoesNotExist:
         print("Creating a new article")
         if self.root is None:
             self._refresh_root()
         print("Using root %s" % (self.root,))
         print("Pushing to slug %s"% (self.slug,))
         base_slug = self.slug.split("/")[-1]
         wiki_page = URLPath.create_urlpath(self.root, slug=base_slug,
                                      title=self.title,
                                      content=self.content)
Example #9
0
 def get_root(self):
     try:
         base_root = URLPath.get_by_path(path="")
     except NoRootURL:
         if (self.slug == "root") and (self.prefix == "/"):
             root = URLPath.create_root(title="QUOREM Wiki",
                                        content=self.content)
             return root
         else:
             raise ValueError(
                 "No root created for prefix '%s'. Make sure root.md is processed first"
                 % (self.prefix, ))
     try:
         root = URLPath.get_by_path(self.prefix)
     except URLPath.DoesNotExist:
         if (self.slug == "root") and (self.prefix != "/"):
             root = URLPath.create_urlpath(base_root,
                                           slug=self.prefix,
                                           title=self.title,
                                           content=self.content)
         else:
             raise ValueError("No root created for prefix '%s'." %
                              (self.prefix, ))
     return root
Example #10
0
 def setUp(self):
     super(TestWikiUtils, self).setUp()
     from course_wiki.views import get_or_create_root
     from wiki.models.urlpath import URLPath
     self.wiki_root = get_or_create_root()
     self.course = CourseFactory.create(org='ORG', display_name='COURSE', number='RUN')
     self.wiki_course_root = URLPath.create_article(self.wiki_root, 'RUN', title=u"Page 0")
     self.page1 = URLPath.create_article(self.wiki_course_root, 'page1', title=u"Page 1")
     self.page2 = URLPath.create_article(self.wiki_course_root, 'page2', title=u"page 2")
     self.page11 = URLPath.create_article(self.page1, 'page11', title=u"page 1.1")
     self.page111 = URLPath.create_article(self.page11, 'page111', title=u"page 1.1.1")
     self.page112 = URLPath.create_article(self.page11, 'page112', title=u"page 1.1.2")
Example #11
0
    def handle(self, *args, **options):

        try:
            import wikitools
        except ImportError:
            raise CommandError(
                'You need to install wikitools to use this command !')

        try:
            import pypandoc  # noqa @UnusedImport
        except ImportError:
            raise CommandError('You need to install pypandoc')

        user_matching = {}

        for um in options['user_matching']:
            mu = um[::-1]
            kp, emanresu = mu.split(':', 1)

            pk = kp[::-1]
            username = emanresu[::-1]

            user_matching[username] = pk

        api_url, api_username, api_password = self.get_params(args)

        site = wikitools.wiki.Wiki(api_url)
        site.login(api_username, api_password)

        pages = self.get_all_pages(wikitools.api, site)

        current_site = Site.objects.get_current()
        url_root = URLPath.root()

        for page in pages:
            self.import_page(
                wikitools.api,
                site,
                page,
                current_site,
                url_root,
                user_matching,
                options['replace_existing'])

        self.update_links()
Example #12
0
def initialize_wiki():
    try:
        root = URLPath.root()
    except NoRootURL:
        print("Root URL not found, creating...")
        root = URLPath.create_root(title="QUOREM Wiki",
                                   content=get_content_from_file(
                                       "quorem/static/markdown/docs/root.md"))
    article_revision = ArticleRevision(
        title=root.article.current_revision.title,
        content=get_content_from_file("quorem/static/markdown/docs/root.md"))
    root.article.add_revision(article_revision)
    try:
        investigation = URLPath.get_by_path("investigation")
    except URLPath.DoesNotExist:
        print("Investigation page not found, creating...")
        URLPath.create_urlpath(root,
                               slug="investigation",
                               title="List of Investigations",
                               content="""This page lists the 
        investigations that are present in your QUOREM database. You may
        edit anything on this page, except the Automated Report 
        section.\r\n\r\n""")

    try:
        protocol = URLPath.get_by_path("protocol")
    except URLPath.DoesNotExist:
        print("Protocol page not found, creating...")
        URLPath.create_urlpath(root,
                               slug="protocol",
                               title="List of Protocols",
                               content="""This page lists the 
        protocols that are present in your QUOREM database. You may
        edit anything on this page, except the Automated Report 
        section.\r\n\r\n""")

    try:
        pipeline = URLPath.get_by_path("pipeline")
    except URLPath.DoesNotExist:
        print("Pipeline page not found, creating...")
        URLPath.create_urlpath(root,
                               slug="pipeline",
                               title="List of Pipelines",
                               content="""This page lists the 
        pipelines that are present in your QUOREM database. You may
        edit anything on this page, except the Automated Report 
        section.\r\n\r\n""")
    try:
        sample = URLPath.get_by_path("sample")
    except URLPath.DoesNotExist:
        print("Sample page not found, creating...")
        URLPath.create_urlpath(
            root,
            slug="sample",
            title="List of Samples",
            content=
            "This page lists the samples that are present in your QUOREM database. You may edit anything on this page, except the Automated Report section.\r\n\r\n"
        )

    initialize_documentation(root)
Example #13
0
def initialize_documentation(root):
    try:
        URLPath.get_by_path("use")
    except:
        URLPath.create_urlpath(root,
                               slug="use",
                               title="Using QUOREM",
                               content=get_content_from_file(
                                   "quorem/static/markdown/docs/use.md"))
    try:
        URLPath.get_by_path("develop")
    except:
        URLPath.create_urlpath(root,
                               slug="develop",
                               title="Developing QUOREM",
                               content=get_content_from_file(
                                   "quorem/static/markdown/docs/develop.md"))
    try:
        URLPath.get_by_path("deploy")
    except:
        URLPath.create_urlpath(root,
                               slug="deploy",
                               title="Deploying QUOREM",
                               content=get_content_from_file(
                                   "quorem/static/markdown/docs/deploy.md"))
 def create_article(self, parent, slug, title):
     from wiki.models.urlpath import URLPath
     return URLPath.create_article(parent, slug, title=title, article_kwargs={
         'group_write': True,
         'other_write': True,
     })
Example #15
0
 def _create_root(self):
     root = URLPath.create_root(title="QUOR'em Wiki",
                                content=self.content)
     return root