[gentoo-commits] proj/grumpy:master commit in: frontend/, /, frontend/templates/, backend/
commit: 85f13c2845302158fb1853e34d095a122d84ac53 Author: Mart Raudsepp gentoo org> AuthorDate: Mon Dec 5 21:11:56 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Mon Dec 5 21:11:56 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=85f13c28 frontend: Setup Flask-WTF and use it for following maintainer checkboxes display No POST handling yet. backend/__init__.py | 1 + frontend/grumpy.py| 22 +- frontend/templates/setup.html | 15 +-- requirements.txt | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 4d78cd8..53cefe1 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -4,6 +4,7 @@ from flask_sqlalchemy import SQLAlchemy 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 /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 :) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config['SECRET_KEY'] = 'Change me, you fool' db = SQLAlchemy(app) from frontend import * diff --git a/frontend/grumpy.py b/frontend/grumpy.py index ea18a98..0644fca 100644 --- a/frontend/grumpy.py +++ b/frontend/grumpy.py @@ -1,10 +1,20 @@ from flask import render_template, request from flask_classy import FlaskView from sqlalchemy.sql import collate +from flask_wtf import FlaskForm +from wtforms import SelectMultipleField, widgets + from backend.lib import models +class MultiCheckboxField(SelectMultipleField): +widget = widgets.ListWidget(prefix_label=False) +option_widget = widgets.CheckboxInput() + +class FollowSetupForm(FlaskForm): +maintainers = MultiCheckboxField('Followed maintainers', coerce=int) + class GrumpyView(FlaskView): route_base='/' @@ -14,4 +24,14 @@ class GrumpyView(FlaskView): def setup(self): maintainers = models.Maintainer.query.order_by(collate(models.Maintainer.email, 'NOCASE')).all() -return render_template("setup.html", maintainers=maintainers) +form = FollowSetupForm() +choices = [] +form_mapping = {} +for maintainer in maintainers: +choices.append((maintainer.id, maintainer.email)) +form_mapping[maintainer.id] = maintainer + +form.maintainers.choices = choices +form.process() + +return render_template("setup.html", mapping=form_mapping, form=form) diff --git a/frontend/templates/setup.html b/frontend/templates/setup.html index e167c22..de1cbc8 100644 --- a/frontend/templates/setup.html +++ b/frontend/templates/setup.html @@ -1,6 +1,9 @@ {% extends "base.html" %} {% block content %} + + {{ form.hidden_tag() }} + @@ -9,8 +12,10 @@ - {% for maintainer in maintainers if maintainer.is_project -%} + {% for item in form.maintainers if mapping[item.data].is_project -%} + {%- set maintainer = mapping[item.data] -%} +{{ item }} {{ maintainer.email }} {{ maintainer.name }} @@ -27,8 +32,10 @@ - {% for maintainer in maintainers if not maintainer.is_project -%} + {% for item in form.maintainers if not mapping[item.data].is_project -%} + {%- set maintainer = mapping[item.data] -%} +{{ item }} {{ maintainer.email }} {{ maintainer.name }} @@ -37,4 +44,8 @@ + + + + {% endblock %} diff --git a/requirements.txt b/requirements.txt index e1076e2..f692f3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Flask Flask-SQLAlchemy Flask-Classy +Flask-WTF Flask-Script #manage.py requests
[gentoo-commits] proj/grumpy:master commit in: frontend/, frontend/templates/, /, backend/
commit: 971600fca7c3fd6599d4133d10e32d27d3cfc6e5 Author: Mart Raudsepp gentoo org> AuthorDate: Tue Nov 22 23:54:03 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Tue Nov 22 23:58:04 2016 + 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 /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 += "%s: %s" % (cat.name, cat.description) -return "Hello World! These are the package categories I know about:%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 000..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 000..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 000..62288f5 --- /dev/null +++ b/frontend/templates/base.html @@ -0,0 +1,62 @@ + + + + {% block title %}Grumpy{% endblock %} + https://assets.gentoo.org/tyrian/bootstrap.min.css"/> + https://assets.gentoo.org/tyrian/tyrian.min.css"/> + + + + + + + + + +https://get.gentoo.org"; role="button" class="btn get-gentoo">Get Gentoo! +{# TODO: Add the standard "gentoo.org sites" snippet (via jinja macro?); is there some API to use to get this list instead of hardcoding? #} + + + + +https://assets.gentoo.org/tyrian/site-logo.svg"; type="image/svg+xml"> + https://assets.gentoo.org/tyrian/site-logo.png"; alt="Gentoo Linux Logo"> + + + Grumpy + + + + + + + + + +Toggle navigation +{# FIXME: What are these supposed to do in Tyrian? #} + + + + + + +{# FIXME: Add class="active" to "li" when we are on the given page already #} +Home +{# TODO: Add other pages, potentially by iterating FlaskView's + some metadata in them (sequence or hide_navigation) instead of hardcoding #} + + + + + + + + + {% block content %}{% endblock %} + + + + + + + \ No newline at end of file diff --git a/frontend/templates/index.html b/frontend/templates/index.html new file mode 100644 index 000..782f407 --- /dev/null +++ b/frontend/templates/index.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% block content %} + + + + + Known cate