Example #1
0
def create_article_or_page():
    data = dict(request.POST.decode())
    category = u'resultats'
    page = None

    for key, val in data.items():
        if key.startswith(u'cat_add_'):
            category = key[len(u'cat_add_'):]
            break
        if key.startswith(u'page_add_'):
            page = key[len(u'page_add_'):]
            break

    title = data.get('title', u'').strip()
    if len(title) == 0:
        # nope
        app.add_alert(_('A title is required.'))
        if page is None:
            redirect('/category/%s' % category)
        else:
            redirect('/page/%s' % page)
        return

    article = Article()
    article['title'] = data['title']
    article['body'] = data.get('content', DEFAULT_BODY)
    date = datetime.datetime.now()
    article.set_metadata('date', date)

    if page is None:
        # it's an article
        cat_info = dict(app.vars['categories'])[category]
        article.set_metadata('category', cat_info['title'])
        path = cat_info['path']
    else:
        # it's a page
        path = dict(app.vars['pages'])[page]['path']

    # XXX we might want to put it under the year directory
    i = 1
    filename = slugify(article['title'])
    fullfilename = os.path.join(path, filename)
    while os.path.exists(fullfilename + '.rst'):
        fullfilename += str(i)
        i += 1

    with open(fullfilename + '.rst', 'w') as f:
        f.write(article.render().encode('utf8'))

    emit(EVENT_CREATED_CONTENT, article_path=fullfilename)
    if page is None:
        redirect('/category/%s/%s' % (category, filename + '.rst'))
    else:
        redirect('/page/%s/%s' % (page, filename + '.rst'))
Example #2
0
def upload_file():
    files = request.files.values()

    # adding file
    if len(files) == 1:
        media_dir = app._config['henet']['media_dir']
        file_ = files[0]
        filename = file_.filename.decode('utf8')
        path = os.path.join(media_dir, filename)
        file_.save(path)
        emit(EVENT_CREATED_CONTENT, filename=file_.filename)

    # Page?
    redirect('/media')
Example #3
0
def new_comment():
    data = request.json
    comments_dir = app._config['henet']['comments_dir']
    article_uuid = data['source_path']
    article_thread = ArticleThread(comments_dir, article_uuid)
    article_thread.add_comment(text=data['text'],
                               author=data['author'])

    article_thread.save()
    notifs = app._config['notifications']
    moderator = notifs.get('moderate_comment')
    if moderator is not None:
        app.send_email([moderator], u'Nouveau commentaire',
                       MODERATE_BODY)

    emit(EVENT_CREATED_COMMENT, article_uuid=article_uuid)
    return {'result': 'OK'}
Example #4
0
def post_page(page, article):
    data = dict(request.POST.decode())
    cache_dir = app._config['henet']['cache_dir']
    page_path = dict(app.vars['pages'])[page]['path']
    article_path = os.path.join(page_path, article)
    article = parse_article(article_path, cache_dir, page_path)

    # XXX all this update crap should be in a Document() class
    if 'title' in data:
        article['title'] = data['title']
    if 'content' in data:
        article['body'] = data['content']
    if 'date' in data:
        article.set_metadata('date', data['date'])

    with open(article_path, 'w') as f:
        f.write(article.render().encode('utf8'))

    emit(EVENT_CHANGED_CONTENT, article_path=article_path)
    redirect('/page/%s/%s' % (page, article['filename']))
Example #5
0
def post_article(category, article):
    data = dict(request.POST.decode())
    cache_dir = app._config['henet']['cache_dir']
    cat_path = dict(app.vars['categories'])[category]['path']
    article_path = os.path.join(cat_path, article)
    article = parse_article(article_path, cache_dir, cat_path)

    # XXX all this update crap should be in a Document() class
    if 'title' in data:
        article['title'] = data['title']
    if 'content' in data:
        article['body'] = data['content']

    for meta in ('location', 'date', 'eventdate'):
        if meta in data:
            article.set_metadata(meta, data[meta])

    with open(article_path, 'w') as f:
        f.write(article.render().encode('utf8'))

    emit(EVENT_CHANGED_CONTENT, article_path=article_path)
    redirect('/category/%s/%s' % (category, article['filename']))
Example #6
0
def del_media(filename):
    filename = filename.decode('utf8')

    # removing file
    media_dir = app._config['henet']['media_dir']
    path = os.path.join(media_dir, filename)
    if os.path.exists(path):
        os.remove(path)
        emit(EVENT_DELETED_CONTENT, filename=path)

    # removing any thumbnail
    thumbnails_dir = app._config['henet']['thumbnails_dir']
    for thumbname in os.listdir(thumbnails_dir):
        if not thumbname.endswith('-' + filename):
            continue
        thumbnail_file = os.path.join(thumbnails_dir, thumbname)
        if os.path.exists(thumbnail_file):
            os.remove(thumbnail_file)
            emit(EVENT_DELETED_CONTENT, filename=thumbname)

    # Page?
    redirect('/media')
Example #7
0
def build():

    if app.workers.in_progress('build-pelican'):
        emit(EVENT_ALREADY_BUILDING)
        redirect('/')
        return

    cache_dir = app._config['henet']['cache_dir']
    content_dir = app._config['henet']['pelican_content_path']
    cmd = app._config['henet']['build_command']
    cmd_dir = app._config['henet'].get('build_working_dir', os.getcwd())

    client_id = request.remote_addr

    def done_building(client_id, *args):
        save_build_hash(content_dir, cache_dir)
        emit(EVENT_BUILT, client_id=client_id)

    done_building = partial(done_building, client_id)

    app.workers.apply_async('build-pelican', _run, (cmd, cmd_dir),
                            done_building)
    emit(EVENT_START_BUILDING)
    redirect('/')
Example #8
0
 def done_building(client_id, *args):
     save_build_hash(content_dir, cache_dir)
     emit(EVENT_BUILT, client_id=client_id)
Example #9
0
def del_page(page, article):
    page_path = dict(app.vars['pages'])[page]['path']
    article_path = os.path.join(page_path, article)
    os.remove(article_path)
    emit(EVENT_DELETED_CONTENT, article_path=article_path)
    redirect('/page/%s' % page)
Example #10
0
def del_article(category, article):
    cat_path = dict(app.vars['categories'])[category]['path']
    article_path = os.path.join(cat_path, article)
    os.remove(article_path)
    emit(EVENT_DELETED_CONTENT, article_path=article_path)
    redirect('/category/%s' % category)