* [gentoo-commits] proj/grumpy:master commit in: frontend/, frontend/templates/, /, backend/
@ 2016-11-22 23:58 Mart Raudsepp
0 siblings, 0 replies; only message in thread
From: Mart Raudsepp @ 2016-11-22 23:58 UTC (permalink / raw
To: gentoo-commits
commit: 971600fca7c3fd6599d4133d10e32d27d3cfc6e5
Author: Mart Raudsepp <leio <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 22 23:54:03 2016 +0000
Commit: Mart Raudsepp <leio <AT> gentoo <DOT> org>
CommitDate: Tue Nov 22 23:58:04 2016 +0000
URL: https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=971600fc
Make the dummy initial web frontend pretty
Now uses extra Flask-Classy dependency for nicer routing and organization.
Stylesheet is Gentoo Tyrian loaded from standard CDN location.
Reorganizes some of frontend to frontend module, which necessitates telling
Flask it's "frontend", not "backend" (for templates to work without passing
custom paths). If reorganization goes this route and completes, all the
flask parts should end up in frontend module, making this hack obsolete.
Though backend might want to use Flask-Sqlalchemy too, so needing the Flask
app object, but not sure yet.
backend/__init__.py | 16 +++--------
frontend/__init__.py | 5 ++++
frontend/grumpy.py | 12 +++++++++
frontend/templates/base.html | 62 +++++++++++++++++++++++++++++++++++++++++++
frontend/templates/index.html | 22 +++++++++++++++
requirements.txt | 1 +
6 files changed, 106 insertions(+), 12 deletions(-)
diff --git a/backend/__init__.py b/backend/__init__.py
index b03432b..46a4007 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -1,20 +1,12 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
-app = Flask(__name__)
-app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///grumpy.db" # FIXME: configuration support
+app = Flask("frontend") # FIXME: Finish rearranging frontend/backend modules properly instead of pretending to be frontend in backend/__init__ because jinja templates are looked for from <what_is_passed_here>/templates
+app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///../backend/grumpy.db" # FIXME: configuration support; weird ../ because of claiming we are "frontend" to Flask and want to keep the path the same it was before for now. But this problem should go away with config, at least for postgres :)
db = SQLAlchemy(app)
-from .lib import models
-
-
-@app.route("/")
-def hello_world():
- categories = models.Category.query.all()
- text = ""
- for cat in categories:
- text += "<b>%s</b>: %s<br>" % (cat.name, cat.description)
- return "Hello World! These are the package categories I know about:<br>%s" % text
+from frontend import *
+GrumpyView.register(app)
__all__ = ["app", "db"]
diff --git a/frontend/__init__.py b/frontend/__init__.py
new file mode 100644
index 0000000..79078b8
--- /dev/null
+++ b/frontend/__init__.py
@@ -0,0 +1,5 @@
+from .grumpy import GrumpyView
+
+__all__ = [
+ "GrumpyView",
+]
\ No newline at end of file
diff --git a/frontend/grumpy.py b/frontend/grumpy.py
new file mode 100644
index 0000000..007748e
--- /dev/null
+++ b/frontend/grumpy.py
@@ -0,0 +1,12 @@
+from flask import render_template, request
+from flask_classy import FlaskView
+
+from backend.lib import models
+
+
+class GrumpyView(FlaskView):
+ route_base='/'
+
+ def index(self):
+ categories = models.Category.query.all()
+ return render_template("index.html", categories=categories)
diff --git a/frontend/templates/base.html b/frontend/templates/base.html
new file mode 100644
index 0000000..62288f5
--- /dev/null
+++ b/frontend/templates/base.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>{% block title %}Grumpy{% endblock %}</title>
+ <link rel="stylesheet" href="https://assets.gentoo.org/tyrian/bootstrap.min.css"/>
+ <link rel="stylesheet" href="https://assets.gentoo.org/tyrian/tyrian.min.css"/>
+ <meta name="theme-color" content="#54487a"/>
+</head>
+<body>
+<header>
+ <div class="site-title">
+ <div class="container">
+ <div class="row">
+ <div class="site-title-buttons">
+ <div class="btn-group btn-group-sm">
+ <a href="https://get.gentoo.org" role="button" class="btn get-gentoo"><span class="fa fa-fw fa-download"></span><strong>Get Gentoo!</strong></a>
+ {# TODO: Add the standard "gentoo.org sites" snippet (via jinja macro?); is there some API to use to get this list instead of hardcoding? #}
+ </div>
+ </div>
+ <div class="logo">
+ <a href="/" title="Back to the homepage" class="site-logo">
+ <object data="https://assets.gentoo.org/tyrian/site-logo.svg" type="image/svg+xml">
+ <img src="https://assets.gentoo.org/tyrian/site-logo.png" alt="Gentoo Linux Logo">
+ </object>
+ </a>
+ <span class="site-label">Grumpy</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ <nav class="tyrian-navbar" role="navigation">
+ <div class="container">
+ <div class="row">
+ <div class="navbar-header">
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
+ <span class="sr-only">Toggle navigation</span>
+ <span class="icon-bar"></span>{# FIXME: What are these supposed to do in Tyrian? #}
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </button>
+ </div>
+ <div class="collapse navbar-collapse navbar-main-collapse">
+ <ul class="nav navbar-nav">
+ {# FIXME: Add class="active" to "li" when we are on the given page already #}
+ <li><a href="/">Home</a></li>
+ {# TODO: Add other pages, potentially by iterating FlaskView's + some metadata in them (sequence or hide_navigation) instead of hardcoding #}
+ </ul>
+ </div>
+ </div>
+ </nav>
+
+<div class="container">
+ <div class="row">
+ <div class="col-xs-12">
+ {% block content %}{% endblock %}
+ </div>
+ </div>
+</div>
+
+</header>
+</body>
+</html>
\ No newline at end of file
diff --git a/frontend/templates/index.html b/frontend/templates/index.html
new file mode 100644
index 0000000..782f407
--- /dev/null
+++ b/frontend/templates/index.html
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+{% block content %}
+
+<div class="panel panel-default">
+ <div class="panel-heading">
+ <h3 class="panel-title">
+ <span class="fa fa-fw fa-cubes"></span>Known categories
+ </h3>
+ </div>
+ <div class="table-responsive">
+ <table class="table table-striped">
+ {% for category in categories -%}
+ <tr>
+ <td class="text-nowrap">{{ category.name }}</td>
+ <td>{{ category.description }}</td>
+ </tr>
+ {%- endfor %}
+ </table>
+ </div>
+</div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 78e4b2b..e1076e2 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,5 @@
Flask
Flask-SQLAlchemy
+Flask-Classy
Flask-Script #manage.py
requests
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-11-22 23:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-22 23:58 [gentoo-commits] proj/grumpy:master commit in: frontend/, frontend/templates/, /, backend/ Mart Raudsepp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox