|
@@ -2,13 +2,12 @@ import os
|
|
|
from datetime import datetime
|
|
|
|
|
|
from flask import Flask, redirect, render_template, request, url_for
|
|
|
+from flask_paginate import Pagination
|
|
|
+from flask_sqlalchemy import SQLAlchemy
|
|
|
# from sqlalchemy import Column, Integer, String
|
|
|
# from sqlalchemy.ext.declarative import declarative_base
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
-from flask_paginate import Pagination
|
|
|
-from flask_sqlalchemy import SQLAlchemy
|
|
|
-
|
|
|
app = Flask(__name__)
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv(
|
|
|
"DB_URI", "sqlite:///news.db"
|
|
@@ -101,9 +100,25 @@ def search_home():
|
|
|
return "cerca cerca"
|
|
|
|
|
|
|
|
|
+@app.route("/search/by-month/")
|
|
|
+def search_by_month_form():
|
|
|
+ return render_template("search_month.html")
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/search/by-month/", methods=["POST"])
|
|
|
+def search_by_month_form_post():
|
|
|
+ return redirect(
|
|
|
+ url_for(
|
|
|
+ "search_by_month",
|
|
|
+ year=request.form["year"],
|
|
|
+ month=request.form["month"],
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/news/<int:year>/<int:month>/")
|
|
|
@app.route("/search/by-month/<int:year>/<int:month>")
|
|
|
def search_by_month(year, month):
|
|
|
- # TODO: proper pagination
|
|
|
page = int(request.args.get("page", "1")) - 1
|
|
|
first = page * 50
|
|
|
last = first + 50
|
|
@@ -119,7 +134,9 @@ def search_by_month(year, month):
|
|
|
News.published >= ts_from, News.published < ts_to
|
|
|
).order_by("published")
|
|
|
|
|
|
- pagination = Pagination(page=page, total=news.count(), per_page=50)
|
|
|
+ pagination = Pagination(
|
|
|
+ page=page, total=news.count(), per_page=50, bs_version=4
|
|
|
+ )
|
|
|
news = news[first:last]
|
|
|
|
|
|
return render_template(
|