diff options
author | 2016-11-23 01:54:03 +0200 | |
---|---|---|
committer | 2016-11-23 01:58:04 +0200 | |
commit | 971600fca7c3fd6599d4133d10e32d27d3cfc6e5 (patch) | |
tree | 8643b701fa5d074797f30fffcaa413f5bcc82cf9 | |
parent | Add parsed project members to the result dict (diff) | |
download | grumpy-971600fca7c3fd6599d4133d10e32d27d3cfc6e5.tar.gz grumpy-971600fca7c3fd6599d4133d10e32d27d3cfc6e5.tar.bz2 grumpy-971600fca7c3fd6599d4133d10e32d27d3cfc6e5.zip |
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.
-rw-r--r-- | backend/__init__.py | 16 | ||||
-rw-r--r-- | frontend/__init__.py | 5 | ||||
-rw-r--r-- | frontend/grumpy.py | 12 | ||||
-rw-r--r-- | frontend/templates/base.html | 62 | ||||
-rw-r--r-- | frontend/templates/index.html | 22 | ||||
-rw-r--r-- | 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 |