Browse Source

some bootstrap love

boyska 3 years ago
parent
commit
5df1bc00b2
5 changed files with 100 additions and 37 deletions
  1. 22 5
      app.py
  2. 15 0
      static/style.css
  3. 25 28
      templates/base.html
  4. 9 4
      templates/news.html
  5. 29 0
      templates/search_month.html

+ 22 - 5
app.py

@@ -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(

+ 15 - 0
static/style.css

@@ -0,0 +1,15 @@
+.pagination ul li {
+    display: inline;
+    padding: 0 0.5em;
+}
+
+.article-comment {
+    margin: 1em;
+}
+.meta {
+    text-align: right;
+    font-style: italic;
+    padding: 0.5em 1em;
+    font-family: sans-serif;
+}
+

+ 25 - 28
templates/base.html

@@ -1,31 +1,28 @@
-<html>
-    <body>
-<style>
-.pagination ul li {
-    display: inline;
-    padding: 0 0.5em;
-}
-.article-comment {
-    margin: 1em;
-    border: 1px solid blue;
-}
-header {
-    background-color: #003366;
-    color: white;
-}
-h3 { margin: 0 0 0 1em; }
-header .meta {
-    text-align: right;
-    font-style: italic;
-    padding: 0.5em 1em;
-    font-family: sans-serif;
-}
-</style>
-    </body>
-    <div>
+<!doctype html>
+<html lang="en">
+    <head>
+        <!-- Required meta tags -->
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+
+        <!-- Bootstrap CSS -->
+        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
+        <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" >
+
+        <title>Archivio di consultazione di indymedia 1.0{%block title_extra %}{% endblock %}</title>
+    </head>
+  <body>
+        {% block body %}
+        <div class="container-fluid">
         {% block content %}
         {% endblock %}
-</div>
-</html>
-
+        </div>
+        {% endblock %}
 
+    <!-- Optional JavaScript -->
+    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
+    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
+    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
+  </body>
+</html>

+ 9 - 4
templates/news.html

@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% block title_extra%} | News | {{n.title}} {% endblock %}
 {% block content %}
 <article class="article">
     <header> <h1>{{n.title}}</h1>
@@ -14,15 +15,19 @@
     </div>
     <div class="article-comments">
         {% for comm in comments %}
-        <div class="article-comment">
+        <div class="card article-comment">
+            <div class="card-body">
             <header>
-                <h3>{{comm.title}}</h3>
+                <h5 class="card-title">{{comm.title}}</h5>
                 <div class="meta">
-                    <div class="author">{{comm.author}}</div>
-                    <div class="published"><time>{{comm.published_datetime.strftime("%d %b %Y - %H:%M")}}</time></div>
+                    <div class="card-subtitle author">{{comm.author}}</div>
+                    <div class="card-subtitle published"><time>{{comm.published_datetime.strftime("%d %b %Y - %H:%M")}}</time></div>
                 </div>
             </header>
+            <div class="card-text">
             {{comm.body|safe}}
+            </div>
+            </div>
         </div>
         {% endfor %}
     </div>

+ 29 - 0
templates/search_month.html

@@ -0,0 +1,29 @@
+{% extends "base.html" %}
+
+{% block content %}
+<form method="POST">
+    <div class="form-group">
+        <label for="year">Anno</label>
+        <select  class="form-control" name="year">
+            <option>2000</option>
+            <option>2001</option>
+        </select>
+    </div>
+    <div class="form-group">
+        <label for="month">Mese</label>
+        <select class="form-control" name="month">
+            {% for i in range(1, 13) %}
+            <option>{{"%02d" | format(i)}}</option>
+            {% endfor %}
+        </select>
+    </div>
+    <div class="form-group">
+        <label for="include_hidden">Mostra nascosti</label>
+        <select class="form-control" name="include_hidden">
+            <option value="1">Si</option>
+            <option value="0">No</option>
+        </select>
+    </div>
+    <button type="submit" class="btn btn-primary">Cerca</button>
+</form>
+{% endblock %}