def html_lines(self, level=1): if self.number is None: title = self.title else: title = "%s %s" % (self.get_full_number(), self.title) if True: if self.parent is not None: title = restify(self.memo2rst(title)).strip() if title.startswith('<p>') and title.endswith('</p>'): title = title[3:-4] #~ logger.info("20120311 title is %r", title) else: raise Exception("20120311 title is %r" % title) yield htmlgen.H(level, title) else: tag = "H%d" % level title = title.replace("<p>", "<" + tag + ">") title = title.replace("</p>", "</" + tag + ">") yield title #~ yield "<H%d>%s</H%d>" % (level,,level) if self.intro: yield restify(self.memo2rst(self.intro)) if self.children: for s in self.children: for ln in s.html_lines(level + 1): yield ln for chunk in self.body: yield restify(self.memo2rst(chunk))
def milestone(self, ref, date, body=None, raw_html=False, **kw): if not raw_html: body = restify(doc2rst(body)) kw.update(ref=ref) #~ kw.update(checkin=checkin) #~ kw.update(description=body) if self.project: kw.setdefault('project', self.current_project) return self.add_object(tickets.Milestone(**kw))
def project(self, ref, title, body, raw_html=False, **kw): if not raw_html: body = restify(doc2rst(body)) kw.update(ref=ref) kw.update(description=body) kw.update(name=title) if self.project: kw.setdefault('parent', self.current_project) return self.add_object(tickets.Project(**kw))
def entry(self, ticket, time, title, body, raw_html=False, **kw): if isinstance(time, (basestring, int)): time = i2t(time) kw.update(created=datetime.datetime.combine(self.date, time)) if not raw_html: body = restify(doc2rst(body)) kw.update(user=self.user) kw.update(body=body) kw.update(title=title) kw.update(ticket=ticket) return self.add_object(blogs.Entry(**kw))
def restify_func(self, unicode_string, **kw): if not unicode_string: return '' html = restify(unicode_string, output_encoding='utf-8') #~ try: #~ html = restify(unicode_string,output_encoding='utf-8') #~ except Exception as e: #~ print unicode_string #~ traceback.print_exc() #~ print repr(html) #~ print html return self.renderXhtml(html, **kw)
def ticket(self, project_ref, title, body, raw_html=False, **kw): if not raw_html: body = restify(doc2rst(body)) kw.update(description=body) kw.update(summary=title) project = tickets.Project.get_by_ref(project_ref) #~ try: #~ project=tickets.Project.objects.get(ref=project_ref) #~ except tickets.Project.DoesNotExist,e: #~ raise Exception("No project with reference %r" % project_ref) kw.update(project=project) #~ kw.update(project=tickets.Project.objects.get(ref=project_ref)) return self.add_object(tickets.Ticket(**kw))
def html_lines(self,level=1): for ln in Section.html_lines(self,level): yield ln words = [w for w in self.words if w.parent is None] if words: t = htmlgen.TABLE([col.label for col in self.columns], show_headers=self.show_headers) def row(w): return [col.word2html(w,self) for col in self.columns] rows = [row(w) for w in words] for ln in t.html_lines(rows): yield ln for chunk in self.after: yield restify(self.memo2rst(chunk))
def render_node(request, node, template_name='pages/node.html', **context): context.update(node=node) heading = dbutils.babelattr(node, 'title', '') if heading: context.update(heading=heading) context.update(title=heading + ' · ' + settings.SITE.title) else: context.update(heading=settings.SITE.title) context.update(title=settings.SITE.title) body = dbutils.babelattr(node, 'body', '') if not node.raw_html: body = restify(doc2rst(body)) #~ logger.info("20121227 render_node %s -> body is %s",node,body) context.update(body=body) return web.render_from_request(request, template_name, **context)
def html_lines(self, level=1): for ln in Section.html_lines(self, level): yield ln words = [w for w in self.words if w.parent is None] if words: t = htmlgen.TABLE([col.label for col in self.columns], show_headers=self.show_headers) def row(w): return [col.word2html(w, self) for col in self.columns] rows = [row(w) for w in words] for ln in t.html_lines(rows): yield ln for chunk in self.after: yield restify(self.memo2rst(chunk))
def rich_text_to_elems(ar, description): """A RichTextField can contain HTML markup or plain text.""" if description.startswith("<"): # desc = E.raw('<div>%s</div>' % self.description) desc = E.raw(ar.parse_memo(description)) return [desc] # desc = E.raw('<div>%s</div>' % self.description) html = restify(ar.parse_memo(description)) # dd.logger.info("20160704b restified --> %s", html) desc = E.raw(html) # dd.logger.info( # "20160704c parsed --> %s", E.tostring(desc)) if desc.tag == 'body': # happens if it contains more than one paragraph return list(desc) # .children return [desc]
def rich_text_to_elems(ar, description): if description.startswith("<"): # desc = E.raw('<div>%s</div>' % self.description) desc = lxml_html.fragments_fromstring(ar.parse_memo(description)) return desc # desc = E.raw('<div>%s</div>' % self.description) html = restify(ar.parse_memo(description)) # logger.info(u"20180320 restify %s --> %s", description, html) # html = html.strip() try: desc = lxml_html.fragments_fromstring(html) except Exception as e: raise Exception("Could not parse {!r} : {}".format(html, e)) # logger.info( # "20160704c parsed --> %s", tostring(desc)) return desc
def rich_text_to_elems(ar, description): """ A RichTextField can contain HTML markup or plain text. """ if description.startswith("<"): # desc = E.raw('<div>%s</div>' % self.description) desc = lxml_html.fragments_fromstring(ar.parse_memo(description)) return desc # desc = E.raw('<div>%s</div>' % self.description) html = restify(ar.parse_memo(description)) # logger.info(u"20180320 restify %s --> %s", description, html) # html = html.strip() try: desc = lxml_html.fragments_fromstring(html) except Exception as e: raise Exception( "Could not parse {!r} : {}".format(html, e)) # logger.info( # "20160704c parsed --> %s", tostring(desc)) return desc
def render_node(request, node, template_name='pages/node.html', **context): context.update(node=node) heading = dd.babelattr(node, 'title', '') if settings.SITE.title is None: title = settings.SITE.verbose_name else: title = settings.SITE.title if heading: context.update(heading=heading) context.update(title=heading + ' · ' + title) else: context.update(heading=title) context.update(title=title) body = dd.babelattr(node, 'body', '') if not node.raw_html: body = restify(doc2rst(body)) # dd.logger.info("20121227 render_node %s -> body is %s",node,body) context.update(body=body) # return web.render_from_request(request, template_name, **context) return dd.plugins.jinja.render_from_request( request, template_name, **context)
def render_node(request, node, template_name='pages/node.html', **context): context.update(node=node) heading = dd.babelattr(node, 'title', '') if settings.SITE.title is None: title = settings.SITE.verbose_name else: title = settings.SITE.title if heading: context.update(heading=heading) context.update(title=heading + ' · ' + title) else: context.update(heading=title) context.update(title=title) body = dd.babelattr(node, 'body', '') if not node.raw_html: body = restify(doc2rst(body)) #~ logger.info("20121227 render_node %s -> body is %s",node,body) context.update(body=body) # return web.render_from_request(request, template_name, **context) return dd.plugins.jinja.render_from_request(request, template_name, **context)