예제 #1
0
def render(template_name, data):
    template = JINJA_ENVIRONMENT.get_template(template_name)
    
    if 'user' not in data or data['user'] is not type(model.WikiUser):
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(os.environ['PATH_INFO'])
    else:
        data['log_in_url'] = users.create_login_url(os.environ['PATH_INFO'])
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()

    # While Django is okay with no page object being there silently; the template
    # renderer for Jinja2 is more strict and throws errors during rendering.
    if 'page' not in data:
        data['page'] = model.EmptyPage(data['user'] or None)
    return template.render(data)
예제 #2
0
파일: view.py 프로젝트: ilkerde/gaewiki
def render(template_name, data):
    def _get_template_filename():
        name = os.path.join(os.path.dirname(__file__), 'templates')
        if settings.get('theme'):
            theme = os.path.join(name, settings.get('theme'))
            if os.path.exists(theme):
                name = theme
        return os.path.join(name, template_name)

    filename = _get_template_filename()
    path_info = os.environ.get('PATH_INFO')
    path_info = '' if path_info is None else path_info

    if not os.path.exists(filename):
        raise Exception('Template %s not found.' % template_name)
    if 'user' not in data:
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(quote(path_info))
    else:
        data['log_in_url'] = users.create_login_url(quote(path_info))
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()
    return template.render(filename, data)
예제 #3
0
def render(template_name, data):
    filename = os.path.join(os.path.dirname(__file__), 'templates', template_name)
    if not os.path.exists(filename):
        raise Exception('Template %s not found.' % template_name)
    if 'user' not in data:
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(os.environ['PATH_INFO'])
    else:
        data['log_in_url'] = users.create_login_url(os.environ['PATH_INFO'])
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'header' not in data:
        data['header'] = get_header()
    if 'menu' not in data:
        data['menu'] = get_menu()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()
    return template.render(filename, data)
예제 #4
0
    def get(self):
        content = "# Manage this page in gaewiki:robots.txt\n"
        content += "Sitemap: %s/sitemap.xml\n" % util.get_base_url()
        content += "User-agent: *\n"
        content += "Disallow: /gae-wiki-static/\n"
        content += "Disallow: /w/\n"

        page = model.WikiContent.get_by_title("gaewiki:robots.txt")
        body = model.WikiContent.parse_body(page.body or content)
        content_type = str(body.get("content-type", "text/plain"))
        self.reply(body["text"], content_type=content_type)
예제 #5
0
파일: view.py 프로젝트: ewestern/GAEWiki
def render(template_name, data):
    template = environment.get_template(template_name)
    if 'user' not in data:
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(os.environ['PATH_INFO'])
    else:
        data['log_in_url'] = users.create_login_url(os.environ['PATH_INFO'])
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()
    return template.render(data)
예제 #6
0
def render(template_name, data):
    filename = os.path.join(os.path.dirname(__file__), 'templates', template_name)
    if not os.path.exists(filename):
        raise Exception('Template %s not found.' % template_name)
    if 'user' not in data:
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(quote(os.environ['PATH_INFO']))
    else:
        data['log_in_url'] = users.create_login_url(quote(os.environ['PATH_INFO']))
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()
    return template.render(filename, data)
예제 #7
0
def render(template_name, data):
    filename = os.path.join(os.path.dirname(__file__), "templates", template_name)
    if not os.path.exists(filename):
        raise Exception("Template %s not found." % template_name)
    if "user" not in data:
        data["user"] = model.WikiUser.get_or_create(users.get_current_user())
    if data["user"]:
        data["log_out_url"] = users.create_logout_url(quote(os.environ["PATH_INFO"]))
    else:
        data["log_in_url"] = users.create_login_url(quote(os.environ["PATH_INFO"]))
    if "is_admin" not in data:
        data["is_admin"] = users.is_current_user_admin()
    if "sidebar" not in data:
        data["sidebar"] = get_sidebar()
    if "footer" not in data:
        data["footer"] = get_footer()
    if "settings" not in data:
        data["settings"] = settings.get_all()
    if "base" not in data:
        data["base"] = util.get_base_url()
    return template.render(filename, data)
예제 #8
0
 def convert_url(url):
     if url.startswith('#'):
         return url
     elif url.startswith('//'):#for links starts with '//',this link is same with the page's crx protocol
         url = 'http:' + url
     elif not url.startswith('http'):
         tmp_url = refer_url if base_url is None else base_url
         if url.startswith('/'):
             url = util.get_base_url(tmp_url) + url
         elif url.startswith('..'):
             url = convert_rel_url(url,tmp_url)
         elif url.startswith('./'):
             url1 = get_current(tmp_url)
             url2 = url.replace('.','',1)
             url = url1 + '/' + url2
         else:
             url1 = get_current(tmp_url)
             url = url1 + '/' + url
     f = lambda x: '' if x is None else '&nojs=1'
     url = util.get_chs_lnk(url,charset)
     return ''.join([pre1,util.my_quote_plus(url),f(nojs)])
예제 #9
0
 def get(self):
     content = "Sitemap: %s/sitemap.xml\n" % util.get_base_url()
     content += "User-agent: *\n"
     content += "Disallow: /gae-wiki-static/\n"
     content += "Disallow: /w/\n"
     self.reply(content, 'text/plain')
예제 #10
0
 def get(self):
     content = "Sitemap: %s/sitemap.xml\n" % util.get_base_url()
     content += "User-agent: *\n"
     content += "Disallow: /gae-wiki-static/\n"
     content += "Disallow: /w/\n"
     self.reply(content, 'text/plain')
예제 #11
0
파일: view.py 프로젝트: PerceptumNL/ka-wiki
def render(template_name, data):
    filename = os.path.join(os.path.dirname(__file__), 'templates', template_name)

    if not os.path.exists(filename):
        raise Exception('Template %s not found.' % template_name)
    if 'user' not in data:
        data['user'] = model.WikiUser.get_or_create(users.get_current_user())
    if data['user']:
        data['log_out_url'] = users.create_logout_url(quote(os.environ['PATH_INFO']))
    else:
        data['log_in_url'] = users.create_login_url(quote(os.environ['PATH_INFO']))
    if 'is_admin' not in data:
        data['is_admin'] = users.is_current_user_admin()
    if 'sidebar' not in data:
        data['sidebar'] = get_sidebar()
    if 'footer' not in data:
        data['footer'] = get_footer()
    if 'settings' not in data:
        data['settings'] = settings.get_all()
    if 'base' not in data:
        data['base'] = util.get_base_url()
    if 'code_editor' not in data:
        data['code_editor'] = False
        data['code_lang'] = ''

    if 'page' in data:
        title = data['page'].title
    else:
        title = None
      
    if title == "stylecss":
        data['code_editor'] = True
        data['code_lang'] = 'css'
    elif title == "js":
        data['code_editor'] = True
        data['code_lang'] = 'javascript'
    elif title == "macros":
        data['code_editor'] = True
        data['code_lang'] = 'jinja2'

    try:
        path = os.path.join(os.path.dirname(__file__), 'templates/%s' % template_name)
        template_fdata = file(path, 'r').read().decode('utf-8')
        if "rss" in template_name:
            macro_fdata = ""
        else:
            macro_fdata = model.WikiContent.get_by_title("macros").body
        template = jinja_environment.from_string(macro_fdata + template_fdata)
    except:
        logging.warning("Page 'macros' doesn't exists")
        template = jinja_environment.get_template(template_name)

    try:
        stylecss = model.WikiContent.get_by_title("stylecss").body
        data['stylecss'] = stylecss
    except:
        logging.warning("Page 'stylecss' doesn't exists")

    try:
        js = model.WikiContent.get_by_title("js").body
        data['js'] = js
    except:
        logging.warning("Page 'js' doesn't exists")

    return template.render(data)