Ejemplo n.º 1
0
def admin_articles_mod(req, id):
    check_login(req)
    match_right(req, module_rights)

    article = Article(id)
    if not article.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    if (not do_check_right(req, right_editor)
            and article.author_id != req.login.id):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    Codebook = build_class('tags')
    pager = Pager(order='value', limit=-1)
    tags = Codebook.list(req, Codebook, pager)

    if req.method == 'POST':
        article.bind(req.form)
        error = article.mod(req)
        if error != article:
            return generate_page(req, "admin/articles_mod.html",
                                 article=article, error=error)

        if not article.get(req):
            raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    return generate_page(req, "admin/articles_mod.html", article=article,
                         token=create_token(req), tags=tags)
Ejemplo n.º 2
0
def admin_pages_mod(req, id):
    """Edit page could:

    * author of page, if still have pages_author right
    * admin with pages_modify right
    * admin with pages_listall right and right which must have page too
    """
    check_login(req)
    match_right(req, module_rights)
    token = do_create_token(req, '/admin/pages/%d' % id)

    page = Page(id)
    if (not do_check_right(req, 'pages_modify')) \
            and (not page.check_right(req)):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    if req.method == 'POST':
        check_token(req, req.form.get('token'))
        page.bind(req.form)
        error = page.mod(req)
        if error:
            return generate_page(req, "admin/pages_mod.html", token=token,
                                 page=page, rights=rights, error=error,
                                 extra_rights=req.cfg.pages_extra_rights)
    # endif
    if not page.get(req):
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    return generate_page(req, "admin/pages_mod.html", token=token,
                         page=page, rights=rights,
                         extra_rights=req.cfg.pages_extra_rights)
Ejemplo n.º 3
0
def admin_articles(req):
    check_login(req)
    match_right(req, module_rights)

    show = req.args.getfirst('show', '', uni)

    pager = Pager(sort='desc')
    pager.bind(req.args)

    kwargs = {}

    if show == 'ready':
        pager.set_params(show=show)
        kwargs['state'] = 2
        kwargs['public_date'] = 0
    elif show == 'drafts':
        pager.set_params(show=show)
        kwargs['state'] = 1
    else:
        show = None

    if not do_check_right(req, right_editor):
        kwargs['author_id'] = req.login.id

    items = Article.list(req, pager, **kwargs)
    return generate_page(req, "admin/articles.html", pager=pager, items=items,
                         show=show)
Ejemplo n.º 4
0
def admin_articles_add(req):
    check_login(req)
    match_right(req, module_rights)

    article = Article()
    if req.method == 'POST':
        article.bind(req.form, req.login.id)
        error = article.add(req)

        if error:
            return generate_page(req, "admin/articles_mod.html",
                                 article=article, error=error)

        redirect(req, '/admin/articles/%d' % article.id)
    # end

    article.state = 2 if do_check_right(req, right_editor) else 1
    return generate_page(req, "admin/articles_mod.html", article=article)
Ejemplo n.º 5
0
def admin_jobs(req):
    check_login(req)
    check_right(req, 'super')

    pager = Pager()
    pager.bind(req.args)

    rows = Job.list(req, pager)
    return generate_page(req, "admin/jobs.html", pager=pager, rows=rows)
Ejemplo n.º 6
0
def admin_menu(req):
    check_login(req)
    check_right(req, module_right)

    pager = Pager(limit=-1)
    items = MenuItem.list(req, pager)

    return generate_page(
        req, "admin/page_menu.html", token=do_create_token(req, "/admin/menu"), pager=pager, items=items
    )
Ejemplo n.º 7
0
def articles_rss(req):
    pager = Pager(limit=5, sort='desc', order='create_date')
    items = Article.list(req, pager, perex=True, public=1)
    for it in items:
        if it.format == FORMAT_RST:
            it.perex = rst2html(it.perex)
    return generate_page(req, "articles_rss.xml",
                         content_type="application/xml", pager=pager,
                         items=items, lang=get_lang(req), tzname=tzname,
                         webmaster=req.server_admin)
Ejemplo n.º 8
0
def admin_pagse_add(req):
    check_login(req)
    match_right(req, ('pages_author', 'pages_modify'))
    token = do_create_token(req, '/admin/pages/add')

    if req.method == 'POST':
        check_token(req, req.form.get('token'))
        page = Page()
        page.bind(req.form, req.login.id)
        error = page.add(req)

        if error:
            return generate_page(req, "admin/pages_mod.html", token=token,
                                 rights=rights, page=page, error=error)

        redirect(req, '/admin/pages/%d' % page.id)
    # end

    return generate_page(req, "admin/pages_mod.html", token=token,
                         rights=rights)
Ejemplo n.º 9
0
def articles_list_full(req, locale=None, tag=None):
    pager = Pager(limit=5, sort='desc', order='create_date')
    pager.bind(req.args)

    kwargs = {'locale': (locale, '')} if locale else {}
    items = Article.list(req, pager, perex=True, public=1, tag=tag, **kwargs)
    for it in items:
        if it.format == FORMAT_RST:
            it.perex = rst2html(it.perex)

    lang = locale if locale else get_lang(req)
    return generate_page(req, "articles_list.html", pager=pager, items=items,
                         lang=lang, staticmenu=req.cfg.get_static_menu(req))
Ejemplo n.º 10
0
def runtime_file(req):
    text = None
    if req.uri == '/':
        text = Page.text_by_name(req, 'index.html')
    elif req.uri.endswith('.html'):
        text = Page.text_by_name(req, req.uri[req.uri.rfind('/')+1:])
    else:       # without .html
        text = Page.text_by_name(req, req.uri[req.uri.rfind('/')+1:]+'.html')
    if text is None:
        text = Page.text_by_name(req, req.uri[req.uri.rfind('/')+1:]+'.rst')
        if text is None:
            raise SERVER_RETURN(state.HTTP_NOT_FOUND)
        text = rst2html(text)

    return generate_page(req, 'runtime_file.html', text=text, runtime=True)
Ejemplo n.º 11
0
def admin_pages(req):
    check_login(req)
    match_right(req, module_rights)

    error = req.args.getfirst('error', 0, int)

    pager = Pager()
    pager.bind(req.args)

    if not do_match_right(req, ('pages_modify', 'pages_listall')):
        rows = Page.list(req, pager, author_id=req.login.id)
    else:
        rows = Page.list(req, pager)
    return generate_page(req, "admin/pages.html",
                         token=do_create_token(req, '/admin/pages'),
                         pager=pager, rows=rows, error=error)
Ejemplo n.º 12
0
    def regenerate(self, req):
        if req.cfg.pages_runtime:
            return              # not need where runtime is True
        with open(req.cfg.pages_source + '/' + self.name, 'r') as f:
            self.text = f.read().decode('utf-8')

        target = req.cfg.pages_out + '/' + self.name
        if self.format == FORMAT_RST:
            self.html = rst2html(self.text)
            target += '.html'

        with open(target + '.tmp', 'w+') as tmp:
            tmp.write(generate_page(
                req, "page_file.html", page=self,
                staticmenu=req.cfg.get_static_menu(req)).encode('utf-8'))
        rename(target + '.tmp', target)
Ejemplo n.º 13
0
def admin_redirects(req):
    check_login(req)
    check_right(req, module_right)

    search = req.args.getfirst('search', fce=nuni)

    pager = Pager(order='value')
    pager.bind(req.args)

    if search:
        pager.set_params(search=search)

    items = Redirect.list(req, pager, search=search)

    return generate_page(req, "admin/redirects.html",
                         token=create_token(req),
                         pager=pager, items=items, search=search)
Ejemplo n.º 14
0
def articles_detail_internal(req, article, **kwargs):
    if article.format == FORMAT_RST:
        article.perex = rst2html(article.perex)
        article.body = rst2html(article.body)

    if article.data.get('discussion', True):
        discussion = ArticleComment.list(req, article.id, Pager(limit=-1))
    else:
        discussion = []

    qid = randint(0, len(robot_questions)-1)
    question, answer = robot_questions[qid]
    return generate_page(req, "articles_detail.html", article=article,
                         discussion=discussion,
                         question=question,  answer=answer, qid=hex(qid),
                         staticmenu=req.cfg.get_static_menu(req),
                         styles=('tiny-writer',), **kwargs)
Ejemplo n.º 15
0
def admin_attachments(req):
    check_login(req)
    check_right(req, R_ADMIN)

    pager = Pager(order='timestamp', sort='desc')
    pager.bind(req.args)

    kwargs = {}

    if 'obty' in req.args:
        kwargs['object_type'] = req.args.getfirst('obty', fce=uni) or None
        pager.set_params(obty=kwargs['object_type'])
    if 'obid' in req.args:
        kwargs['object_id'] = req.args.getfirst('obid', fce=int)
        pager.set_params(obid=kwargs['object_id'])

    rows = Attachment.list(req, pager, **kwargs)
    return generate_page(req, "admin/attachments.html",
                         pager=pager, rows=rows)
Ejemplo n.º 16
0
def admin_options(req):
    check_login(req)
    check_right(req, module_right)

    section = req.args.getfirst('section', '', uni)
    module = req.args.getfirst('module', '', uni)
    kwargs = {}
    if section != 'all':
        kwargs['section'] = section
    if module != 'all':
        kwargs['module'] = module

    pager = Pager()
    pager.bind(req.args)
    options = Option.list(req, pager, **kwargs)
    for option in options:
        option.defaults_json = json.dumps(list(option.defaults))

    return generate_page(req, "admin/options.html", pager=pager,
                         options=options, sections=Option.sections_list(req),
                         modules=Option.modules_list(req), section=section,
                         module=module)
Ejemplo n.º 17
0
    def save(self, req):
        source = req.cfg.pages_source + '/' + self.name
        with open(source + '.tmp', 'w+') as tmp:
            tmp.write(self.text.encode('utf-8'))
        if exists(source):      # backup old file
            backup = req.cfg.pages_history + '/' + self.name
            copyfile(source, backup + '.' + datetime.now().isoformat())
        rename(source + '.tmp', source)

        if req.cfg.pages_runtime:
            return              # not need when paeges are runtime generated

        target = req.cfg.pages_out + '/' + self.name
        if self.format == FORMAT_RST:
            self.html = rst2html(self.text)
            target += '.html'

        with open(target + '.tmp', 'w+') as tmp:
            tmp.write(generate_page(
                req, "page_file.html", page=self,
                staticmenu=req.cfg.get_static_menu(req)).encode('utf-8'))
        rename(target + '.tmp', target)
Ejemplo n.º 18
0
def articles_tags_list(req):
    Codebook = build_class('tags')
    pager = Pager(order='value', limit=-1)
    tags = Codebook.list(req, Codebook, pager)
    return generate_page(req, "articles_tags.html", tags=tags)