Esempio n. 1
0
    def default(self):
        outdir = os.path.realpath(self.pargs.outdir[0])
        self.log.info("Compiling pages to {}".format(outdir))
        pages = Page.all(self.app.mdb)
        menus = {}
        for page in pages:
            dest_file = os.path.join(outdir, page.url[1:])
            dest_dir = os.path.dirname(dest_file)
            try:
                os.makedirs(dest_dir)
                self.log.info("[MKDIR] {}".format(dest_dir))

            except OSError as e:
                if e.errno != 17:
                    raise

            if hasattr(page, "redirect"):
                self.write_redirect(from_=page.url,
                                    to=page.redirect['url'],
                                    dest=dest_file)

            else:
                menus = self.write_page(page, dest_file, menus)

        # handle homepage redirect
        home_name = "{}.html".format(self.pargs.index)
        home = os.path.join(outdir, home_name)
        lang = self.app.request.registry.settings['mokacms.default_language']
        if not os.path.exists(home):
            to = Page.homepage(self.app.mdb, lang)
            if to:
                self.write_redirect(from_="/" + home_name,
                                    to=page.url,
                                    dest=home)
Esempio n. 2
0
    def default(self):
        outdir = os.path.realpath(self.pargs.outdir[0])
        self.log.info("Compiling pages to {}".format(outdir))
        pages = Page.all(self.app.mdb)
        menus = {}
        for page in pages:
            dest_file = os.path.join(outdir, page.url[1:])
            dest_dir = os.path.dirname(dest_file)
            try:
                os.makedirs(dest_dir)
                self.log.info("[MKDIR] {}".format(dest_dir))

            except OSError as e:
                if e.errno != 17:
                    raise

            if hasattr(page, "redirect"):
                self.write_redirect(from_=page.url, to=page.redirect['url'],
                                    dest=dest_file)

            else:
                menus = self.write_page(page, dest_file, menus)

        # handle homepage redirect
        home_name = "{}.html".format(self.pargs.index)
        home = os.path.join(outdir, home_name)
        lang = self.app.request.registry.settings['mokacms.default_language']
        if not os.path.exists(home):
            to = Page.homepage(self.app.mdb, lang)
            if to:
                self.write_redirect(from_="/" + home_name, to=page.url, dest=home)
Esempio n. 3
0
def default_homepage(request):
    default_lang = request.registry.settings['mokacms.default_language']
    log.debug("Redirecting to default language: /{}".format(default_lang))
    page = Page.homepage(request.mdb, default_lang)
    if not page:
        return HTTPNotFound()
    return HTTPFound(location=page.url)
Esempio n. 4
0
def serve_page(request):
    path = "/" + "/".join(request.matchdict['path'])
    try:
        page = Page.get(request.mdb, path)

    except:
        return HTTPNotFound()

    log.debug("Found page: {}".format(page))
    try:
        return HTTPRedirection(code=page.redirect['code'],
                                    location=page.redirect['url'])
    except AttributeError:
        menus = Menu.get(request.mdb, page.language)
        page_d = page.asdict()
        page_d['widgets'] = page.run_widgets(request)
        log.debug("Rendering template %s", page.template)
        return render_to_response(page.template,
                          {'page': page_d,
                           'menus': [menu.asdict() for menu in menus]},
                          request=request)
Esempio n. 5
0
def sitemap(request):
    return dict(pages=Page.all(request.mdb))