def save(self, *args, **kwargs): self.slug = slugify(self.title) super(Collection, self).save(*args, **kwargs)
def save(self, path): os.makedirs(path, exist_ok=True) n = len(self.charts) for i in range(n): ch = self.charts[i] if ch.title is None: ch.title = '{}_{:02d}'.format('Chart' if isinstance(ch, Chart) else ('Text' if isinstance(ch, Text) else 'Selector'), i) ch.save('{}/{}'.format(path, slugify(ch.title))) doc, tag, text, line = Doc().ttl() doc.asis('<!DOCTYPE html>') with tag('html'): with tag('head'): with tag('title'): text(self.title or 'Selector') with tag('script'): doc.asis(""" function loader(target, file) { var element = document.getElementById(target); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if(xmlhttp.status == 200 && xmlhttp.readyState == 4){ var txt = xmlhttp.responseText; var next_file = "" var matches = txt.match(/<script>loader\\('.*', '(.*)'\\)<\\/script>/); if (matches) { next_file = matches[1]; }; txt = txt.replace(/^[\s\S]*<body>/, "").replace(/<\/body>[\s\S]*$/, ""); txt = txt.replace(/src=\\"fig_/g, "src=\\"" + file + "/fig_"); txt = txt.replace(/loader\\('/g, "loader('" + file.replace("/", "-") + "-"); txt = txt.replace(/div id=\\"/, "div id=\\"" + file.replace("/", "-") + "-"); txt = txt.replace(/content', '/g, "content', '" + file + "/"); element.innerHTML = txt; if (next_file) { loader(file.replace("/", "-") + "-content", file.replace("/", "-") + "/" + next_file); }; }; }; xmlhttp.open("GET", file + "/page.htm", true); xmlhttp.send(); } """) with tag('body'): with tag('h1'): text(self.title or 'Selector') with tag('div'): for ch in self.charts: #line('a', ch.title, href='{}/page.html'.format(slugify(ch.title)), target='iframe') line('button', ch.title, type='button', onclick='loader(\'content\', \'{}\')'.format(slugify(ch.title))) with tag('div', id='content'): text('') with tag('script'): doc.asis('loader(\'content\', \'{}\')'.format(slugify(self.charts[0].title))) file = open('{}/page.htm'.format(path), 'w', encoding='utf-8') file.write(indent(doc.getvalue())) file.close()
def save(self, *args, **kwargs): self.slug = '%s-%s' % ( slugify(self.source.title), slugify(self.quote)) super(Quote, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = slugify(self.title) super(Source, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = slugify(self.name) super(Author, self).save(*args, **kwargs)