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)
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)
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 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 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)
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