diff options
author | Mart Raudsepp <leio@gentoo.org> | 2016-12-05 23:11:56 +0200 |
---|---|---|
committer | Mart Raudsepp <leio@gentoo.org> | 2016-12-05 23:11:56 +0200 |
commit | 85f13c2845302158fb1853e34d095a122d84ac53 (patch) | |
tree | 2be1a34d7c26a7fe221e21ef69a4b66ee31dba7e | |
parent | sync: return empty dict on projects retrieval error, so the caller won't error (diff) | |
download | grumpy-85f13c2845302158fb1853e34d095a122d84ac53.tar.gz grumpy-85f13c2845302158fb1853e34d095a122d84ac53.tar.bz2 grumpy-85f13c2845302158fb1853e34d095a122d84ac53.zip |
frontend: Setup Flask-WTF and use it for following maintainer checkboxes display
No POST handling yet.
-rw-r--r-- | backend/__init__.py | 1 | ||||
-rw-r--r-- | frontend/grumpy.py | 22 | ||||
-rw-r--r-- | frontend/templates/setup.html | 15 | ||||
-rw-r--r-- | 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 <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 :) 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 method="POST" action="."> + {{ form.hidden_tag() }} + <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"> @@ -9,8 +12,10 @@ </div> <div class="table-responsive"> <table class="table table-striped"> - {% for maintainer in maintainers if maintainer.is_project -%} + {% for item in form.maintainers if mapping[item.data].is_project -%} + {%- set maintainer = mapping[item.data] -%} <tr> + <td>{{ item }}</td> <td class="text-nowrap">{{ maintainer.email }}</td> <td>{{ maintainer.name }}</td> </tr> @@ -27,8 +32,10 @@ </div> <div class="table-responsive"> <table class="table table-striped"> - {% 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] -%} <tr> + <td>{{ item }}</td> <td class="text-nowrap">{{ maintainer.email }}</td> <td>{{ maintainer.name }}</td> </tr> @@ -37,4 +44,8 @@ </div> </div> +<input type="submit" value="Save follows"/> + +</form> + {% 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 |