[gentoo-commits] proj/grumpy:master commit in: frontend/
commit: 866287aefa418043337878676c60ca6469d8ed4b Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 18 23:45:28 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 18 23:45:28 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=866287ae frontend: Implement saving of followed maintainers/projects to cookie frontend/grumpy.py | 21 +++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/grumpy.py b/frontend/grumpy.py index 7e7a086..62ce9b1 100644 --- a/frontend/grumpy.py +++ b/frontend/grumpy.py @@ -1,5 +1,5 @@ -from flask import render_template, request -from flask_classy import FlaskView +from flask import current_app, redirect, render_template, request, url_for +from flask_classy import FlaskView, route from sqlalchemy.sql import collate from flask_wtf import FlaskForm from wtforms import SelectMultipleField, widgets @@ -23,16 +23,33 @@ class GrumpyView(FlaskView): return render_template("index.html", categories=categories) class SetupView(FlaskView): +@route('/', methods=['GET', 'POST']) # FIXME: Can we enable POST without giving a rule override from the automatic, or handle this some other better way with wtforms setup? def index(self): maintainers = models.Maintainer.query.order_by(collate(models.Maintainer.email, 'NOCASE')).all() form = FollowSetupForm() choices = [] +defaults = [] form_mapping = {} +follows = request.cookies.get('follows', '').split() for maintainer in maintainers: choices.append((maintainer.id, maintainer.email)) form_mapping[maintainer.id] = maintainer +if maintainer.email in follows: +defaults.append(maintainer.id) form.maintainers.choices = choices +form.maintainers.default = defaults + +if form.validate_on_submit(): +followed_maintainers = set() +for choice in choices: +if choice[0] in form.maintainers.data: +followed_maintainers.add(choice[1]) +response = current_app.make_response(redirect(url_for('GrumpyView:index'))) +# FIXME: This will fail with too many following (usually string value length above 4093); move this to session eventually. If that is delayed, we could at least make it fit more by omitting @gentoo.org in those cases (and suffixing it back after cookie read for defaults handling) +response.set_cookie('follows', value=' '.join(followed_maintainers)) +return response + form.process() return render_template("setup.html", mapping=form_mapping, form=form)
[gentoo-commits] proj/grumpy:master commit in: frontend/, backend/
commit: 7076144ff03e38dcf837bd774c6c19ca49f2c047 Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 18 23:15:19 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 18 23:15:19 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=7076144f frontend: move setup to a separate view class backend/__init__.py | 1 + frontend/__init__.py | 6 +++--- frontend/grumpy.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 53cefe1..f8bfd6a 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -10,5 +10,6 @@ db = SQLAlchemy(app) from frontend import * GrumpyView.register(app) +SetupView.register(app) __all__ = ["app", "db"] diff --git a/frontend/__init__.py b/frontend/__init__.py index 79078b8..04ee7ae 100644 --- a/frontend/__init__.py +++ b/frontend/__init__.py @@ -1,5 +1,5 @@ -from .grumpy import GrumpyView +from .grumpy import GrumpyView, SetupView __all__ = [ -"GrumpyView", -] \ No newline at end of file +"GrumpyView", "SetupView", +] diff --git a/frontend/grumpy.py b/frontend/grumpy.py index 0644fca..7e7a086 100644 --- a/frontend/grumpy.py +++ b/frontend/grumpy.py @@ -22,7 +22,8 @@ class GrumpyView(FlaskView): categories = models.Category.query.all() return render_template("index.html", categories=categories) -def setup(self): +class SetupView(FlaskView): +def index(self): maintainers = models.Maintainer.query.order_by(collate(models.Maintainer.email, 'NOCASE')).all() form = FollowSetupForm() choices = []
[gentoo-commits] proj/grumpy:master commit in: frontend/templates/
commit: bc03898a8c3c3fc730c8477dd35deb681cc16866 Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 18 21:37:18 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 18 21:37:36 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=bc03898a frontend: Hide @gentoo.org for developers listing in /setup frontend/templates/setup.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/templates/setup.html b/frontend/templates/setup.html index 6ea857a..c7a2f21 100644 --- a/frontend/templates/setup.html +++ b/frontend/templates/setup.html @@ -16,7 +16,7 @@ {%- set maintainer = mapping[item.data] -%} {{ item }} -{{ maintainer.email }} +{{ maintainer.email[0:-11] }}{# 11 is len('@gentoo.org'), which this is guaranteed to end with in this loop #} {{ maintainer.name|default('', True) }} {%- endfor %}
[gentoo-commits] proj/grumpy:master commit in: /, frontend/templates/
commit: c0c323a6f79529fe475aa08364066e1f3e691647 Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 18 21:28:12 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 18 21:29:07 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=c0c323a6 frontend: List proxy maintainers in a separate table for /setup Also display an empty cell instead of "None" when we don't have a name in the DB. Style the submit button a bit. Commit a manage.py TODO comment that's collecting dust. frontend/templates/setup.html | 30 +- manage.py | 2 ++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/frontend/templates/setup.html b/frontend/templates/setup.html index de1cbc8..6ea857a 100644 --- a/frontend/templates/setup.html +++ b/frontend/templates/setup.html @@ -7,6 +7,26 @@ + Known developers + + + + + {% for item in form.maintainers if not mapping[item.data].is_project and mapping[item.data].email.endswith('@gentoo.org') -%} + {%- set maintainer = mapping[item.data] -%} + +{{ item }} +{{ maintainer.email }} +{{ maintainer.name|default('', True) }} + + {%- endfor %} + + + + + + + Known projects @@ -17,7 +37,7 @@ {{ item }} {{ maintainer.email }} -{{ maintainer.name }} +{{ maintainer.name|default('', True) }} {%- endfor %} @@ -27,24 +47,24 @@ - Known developers + Known proxy maintainers - {% for item in form.maintainers if not mapping[item.data].is_project -%} + {% for item in form.maintainers if not mapping[item.data].is_project and not mapping[item.data].email.endswith('@gentoo.org') -%} {%- set maintainer = mapping[item.data] -%} {{ item }} {{ maintainer.email }} -{{ maintainer.name }} +{{ maintainer.name|default('', True) }} {%- endfor %} - + diff --git a/manage.py b/manage.py index a31b96c..8df47ee 100755 --- a/manage.py +++ b/manage.py @@ -6,6 +6,8 @@ from flask_script import Manager, Shell from backend import app, db from backend.lib import sync +# TODO: Replace this with flask 0.11 "flask" CLI and the extra commands support via click therein - http://flask.pocoo.org/docs/0.11/cli/ +# TODO: This would then allow FLASK_DEBUG=1 automatically reloading the server on code changes when launched with "flask run" manager = Manager(app)
[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/templates/
commit: d69d500d50aa8b22247bb341a9f82c5cde5347ae Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 4 07:18:12 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 4 07:18:12 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=d69d500d frontend: Add meta charset=utf-8 head tag frontend/templates/base.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/templates/base.html b/frontend/templates/base.html index 62288f5..5a50f03 100644 --- a/frontend/templates/base.html +++ b/frontend/templates/base.html @@ -2,9 +2,10 @@ {% block title %}Grumpy{% endblock %} + + https://assets.gentoo.org/tyrian/bootstrap.min.css"/> https://assets.gentoo.org/tyrian/tyrian.min.css"/> -
[gentoo-commits] proj/grumpy:master commit in: frontend/, frontend/templates/
commit: 40953ed104a9f49316360e261fa45bf7ff8ed57b Author: Mart Raudsepp gentoo org> AuthorDate: Sun Dec 4 07:09:18 2016 + Commit: Mart Raudsepp gentoo org> CommitDate: Sun Dec 4 07:09:18 2016 + URL:https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=40953ed1 frontend: add a /setup/ page for listing existing projects and devs Later we can convert this into a form to choose which projects/devs to follow; hence the "setup" naming. frontend/grumpy.py| 5 + frontend/templates/setup.html | 40 2 files changed, 45 insertions(+) diff --git a/frontend/grumpy.py b/frontend/grumpy.py index 007748e..ea18a98 100644 --- a/frontend/grumpy.py +++ b/frontend/grumpy.py @@ -1,5 +1,6 @@ from flask import render_template, request from flask_classy import FlaskView +from sqlalchemy.sql import collate from backend.lib import models @@ -10,3 +11,7 @@ class GrumpyView(FlaskView): def index(self): categories = models.Category.query.all() return render_template("index.html", categories=categories) + +def setup(self): +maintainers = models.Maintainer.query.order_by(collate(models.Maintainer.email, 'NOCASE')).all() +return render_template("setup.html", maintainers=maintainers) diff --git a/frontend/templates/setup.html b/frontend/templates/setup.html new file mode 100644 index 000..e167c22 --- /dev/null +++ b/frontend/templates/setup.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% block content %} + + + + + Known projects + + + + + {% for maintainer in maintainers if maintainer.is_project -%} + +{{ maintainer.email }} +{{ maintainer.name }} + + {%- endfor %} + + + + + + + + Known developers + + + + + {% for maintainer in maintainers if not maintainer.is_project -%} + +{{ maintainer.email }} +{{ maintainer.name }} + + {%- endfor %} + + + + +{% endblock %}
[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