def content(path):
    #Temporarily, hard-code the main page (THIS MUST BE REMOVED FOR PRODUCTION USE)
    try:
        return render_template(path + '.html', curpage=path.split("/")[0])
    except jinja2.exceptions.TemplateNotFound:
        pass

    print("Querying the content table for url='" + path + "'")
    item = Content.query.filter_by(url=path).first()

    if not item:
        abort(404)

    if item.required_priv_level == Auth.permission_member and not is_loggedin():
        return redirect('/login')

    if item.required_priv_level == Auth.permission_admin and not is_admin():
        return redirect('/members')

    parser = DocParser()
    ast = parser.parse(item.data_blob)

    renderer = HTMLRenderer()

    if item.required_priv_level == Auth.permission_admin:
        return render_template('admin/admin.html', content=renderer.render(ast), title=item.title)

    if item.required_priv_level == Auth.permission_member:
        return render_template('members/members.html', content=renderer.render(ast), title=item.title)

    return render_template('page-sidebar.html', content=renderer.render(ast), title=item.title)
def pull_in_markdown(mdid):
    print("Template pulling in content from a .md file.")
    f = 'pages/' + mdid + '.md'
    if os.path.exists(f):
        print("  Found a matching .md file in /pages")
        fp = open(f, 'r')
        c = fp.read()
        fp.close()
        parser = DocParser()
        ast = parser.parse(c)
        renderer = HTMLRenderer()
        return renderer.render(ast)
    else:
        return ""
Beispiel #3
0
def render_blob(blob, datatype):
  # This must return a string that is ready to insert directly into the page, without any further escaping
  try:
    if datatype == Block.MARKDOWN:
      parser = DocParser()
      ast = parser.parse(blob)
      renderer = HTMLRenderer()
      # No escaping, since markdown has already parsed everything
      return '<div class="markdown-body">%s</div>' % renderer.render(ast)
    elif datatype == Block.HTML:
      # No escaping; we want the original
      return blob
    elif datatype == Block.TEXT:
      # Escape the blob, so all characters will be preserved
      return format_html('<div style="white-space:pre-wrap">{}</div>', blob)
    elif datatype == Block.JSON:
      return '{No rendering for JSON blobs}'
    else:
      return '{Unable to render block}'
  except:
    return '{Error rendering block}'
Beispiel #4
0
def render_blob(blob, datatype):
  # This must return a string that is ready to insert directly into the page, without any further escaping
  try:
    if datatype == Block.MARKDOWN:
      parser = DocParser()
      ast = parser.parse(blob)
      renderer = HTMLRenderer()
      # No escaping, since markdown has already parsed everything
      return '<div class="markdown-body">%s</div>' % renderer.render(ast)
    elif datatype == Block.HTML:
      # No escaping; we want the original
      return blob
    elif datatype == Block.TEXT:
      # Escape the blob, so all characters will be preserved
      return format_html('<div style="white-space:pre-wrap">{}</div>', blob)
    elif datatype == Block.JSON:
      return '{No rendering for JSON blobs}'
    else:
      return '{Unable to render block}'
  except:
    return '{Error rendering block}'
Beispiel #5
0
def content(path):
    #Temporarily, hard-code the main page (THIS MUST BE REMOVED FOR PRODUCTION USE)
    try:
        return render_template(path + '.html', curpage=path.split("/")[0])
    except jinja2.exceptions.TemplateNotFound:
        pass

    print("Querying the content table for url='" + path + "'")
    item = Content.query.filter_by(url=path).first()

    if not item:
        abort(404)

    if item.required_priv_level == Auth.permission_member and not is_loggedin(
    ):
        return redirect('/login')

    if item.required_priv_level == Auth.permission_admin and not is_admin():
        return redirect('/members')

    parser = DocParser()
    ast = parser.parse(item.data_blob)

    renderer = HTMLRenderer()

    if item.required_priv_level == Auth.permission_admin:
        return render_template('admin/admin.html',
                               content=renderer.render(ast),
                               title=item.title)

    if item.required_priv_level == Auth.permission_member:
        return render_template('members/members.html',
                               content=renderer.render(ast),
                               title=item.title)

    return render_template('page-sidebar.html',
                           content=renderer.render(ast),
                           title=item.title)
def content(path):
    try:
        f = 'pages/' + path + '.md'
        if os.path.exists(f):
            fp = open(f, 'r')
            # <!-- This is development code...
            tmpl = fp.readline().strip()
            title = fp.readline().strip()
            # -->
            c = fp.read()
            fp.close()
            parser = DocParser()
            ast = parser.parse(c)
            renderer = HTMLRenderer()
            return render_template(tmpl, content=renderer.render(ast), title=title)
        else:
            f = 'templates/' + path + '.tmpl'
            if os.path.exists(f):
                fp = open(f, 'r')
                c = fp.read()
                fp.close()
                return render_template(path + ".tmpl", curpage=path.split("/")[0])
            else:
                abort(404)
    except jinja2.exceptions.TemplateNotFound:
        abort(500)




    item = Content.query.filter_by(url=path).first()

    if not item:
        abort(404)

    if item.required_priv_level == Auth.permission_member and not is_loggedin():
        return redirect('/login')

    if item.required_priv_level == Auth.permission_admin and not is_admin():
        return redirect('/members')

    parser = DocParser()
    ast = parser.parse(item.data_blob)

    renderer = HTMLRenderer()

    if item.required_priv_level == Auth.permission_admin:
        return render_template('admin/admin.tmpl', content=renderer.render(ast), title=item.title)

    if item.required_priv_level == Auth.permission_member:
        return render_template('members/members.tmpl', content=renderer.render(ast), title=item.title)

    return render_template('page-sidebar.tmpl', content=renderer.render(ast), title=item.title)