Exemplo n.º 1
0
def posts_page(current_page: int = 1):
    total_pages = (NewsEntry.select().where(
        NewsEntry.state == "published").count() // config.NEWS_PER_PAGE) + 1
    posts = NewsEntry.select().where(NewsEntry.state == "published").paginate(
        current_page, config.NEWS_PER_PAGE)
    return render_template(
        "pages/posts.html",
        body_id="posts",
        posts=posts,
        title="Actualités",
        current_page=current_page,
        total_pages=total_pages,
    )
Exemplo n.º 2
0
def post_render(post_id: int):
    try:
        post = NewsEntry.get_by_id(post_id)
    except DoesNotExist:
        abort(404)
    return render_template("pages/post.html",
                           body_id="post",
                           post=post,
                           name=post.title)
Exemplo n.º 3
0
def status():
    return {
        "actualites": {
            "waiting":
            NewsEntry.select().where(NewsEntry.state == "waiting").count(),
        },
        "emplois": {
            "waiting":
            JobPost.select().where(JobPost.state == "waiting").count(),
        },
    }
Exemplo n.º 4
0
Arquivo: rss.py Projeto: Mindiell/site
def feed_rss(type):
    name = ""
    entries = []
    if type == "emplois":
        name = "Emplois"
        entries = JobPost.select().where(JobPost.state == "published")
    elif type == "actualites":
        name = "Actualités"
        entries = NewsEntry.select().where(NewsEntry.state == "published")
    else:
        abort(404)
    title = f"{name} AFPy.org"
    return render_template(
        "pages/rss.xml",
        entries=entries,
        title=title,
        description=title,
        link=url_for("rss.feed_rss", type=type, _external=True),
        type=type,
    )
Exemplo n.º 5
0
def new_post():
    form = NewsEntryForm()
    if form.validate_on_submit():
        title = form.title.data
        summary = form.summary.data
        content = form.content.data
        author = form.author.data
        author_email = form.author_email.data

        new_post = NewsEntry.create(
            title=title, summary=summary, content=content, author=author, author_email=author_email
        )
        flash("Merci ! Votre article apparaîtra après validation par un des administrateurs.", "success")

        if form.image.data:
            extension = secure_filename(form.image.data.filename).split(".")[-1].lower()
            filename = f"emplois.{new_post.id}.{extension}"
            filepath = f"{config.IMAGES_PATH}/{filename}"
            request.files[form.image.name].save(filepath)
            new_post.image_path = filename
            new_post.save()
        return redirect(url_for("posts.posts_page", current_page=1))
    return render_template("pages/edit_post.html", form=form, post=None, body_id="edit-post")
Exemplo n.º 6
0
 timestamp = post.get(FIELD_TIMESTAMP)
 if post.get(FIELD_IMAGE):
     image = POSTS_DIR / post.get(FIELD_IMAGE)
     name, ext = os.path.splitext(post.get(FIELD_IMAGE))
     post["image"] = f"{category}.{timestamp}{ext}"
     shutil.copy(str(image), str(IMAGE_DIR / post["image"]))
 if category == "actualites":
     new_post = NewsEntry.create(
         title=post.get("title", "(untitled)"),
         summary=post.get("summary"),
         content=html2text(post.get("content", "")),
         author="Admin",
         author_email=post.get("email"),
         image_path=post.get("image"),
         dt_published=parse(post.get("published")).replace(
             tzinfo=None) if state == "published" else None,
         dt_submitted=parse(
             post.get("published")).replace(tzinfo=None),
         dt_updated=parse(
             post.get("published")).replace(tzinfo=None),
         state=state,
         approved_by=admin_1 if state == "published"
         or state == "rejected" else None,
     )
     Slug.create(
         url=f"/posts/actualites/{post.get(FIELD_TIMESTAMP)}",
         newsentry=new_post)
     post_id = post.get("id")
     if post_id:
         Slug.create(url=post_id.split("afpy.org")[-1],
                     newsentry=new_post)
Exemplo n.º 7
0
def home_page():
    all_news = NewsEntry.select().where(
        NewsEntry.state == "published").order_by(
            NewsEntry.dt_submitted.desc()).limit(4)
    return render_template("pages/index.html", body_id="index", posts=all_news)