Gentoo Archives: gentoo-commits

From: Mart Raudsepp <leio@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/grumpy:master commit in: frontend/, /, frontend/templates/, backend/
Date: Mon, 05 Dec 2016 21:12:45
Message-Id: 1480972316.85f13c2845302158fb1853e34d095a122d84ac53.leio@gentoo
1 commit: 85f13c2845302158fb1853e34d095a122d84ac53
2 Author: Mart Raudsepp <leio <AT> gentoo <DOT> org>
3 AuthorDate: Mon Dec 5 21:11:56 2016 +0000
4 Commit: Mart Raudsepp <leio <AT> gentoo <DOT> org>
5 CommitDate: Mon Dec 5 21:11:56 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=85f13c28
7
8 frontend: Setup Flask-WTF and use it for following maintainer checkboxes display
9
10 No POST handling yet.
11
12 backend/__init__.py | 1 +
13 frontend/grumpy.py | 22 +++++++++++++++++++++-
14 frontend/templates/setup.html | 15 +++++++++++++--
15 requirements.txt | 1 +
16 4 files changed, 36 insertions(+), 3 deletions(-)
17
18 diff --git a/backend/__init__.py b/backend/__init__.py
19 index 4d78cd8..53cefe1 100644
20 --- a/backend/__init__.py
21 +++ b/backend/__init__.py
22 @@ -4,6 +4,7 @@ from flask_sqlalchemy import SQLAlchemy
23 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
24 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 :)
25 app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
26 +app.config['SECRET_KEY'] = 'Change me, you fool'
27 db = SQLAlchemy(app)
28
29 from frontend import *
30
31 diff --git a/frontend/grumpy.py b/frontend/grumpy.py
32 index ea18a98..0644fca 100644
33 --- a/frontend/grumpy.py
34 +++ b/frontend/grumpy.py
35 @@ -1,10 +1,20 @@
36 from flask import render_template, request
37 from flask_classy import FlaskView
38 from sqlalchemy.sql import collate
39 +from flask_wtf import FlaskForm
40 +from wtforms import SelectMultipleField, widgets
41 +
42
43 from backend.lib import models
44
45
46 +class MultiCheckboxField(SelectMultipleField):
47 + widget = widgets.ListWidget(prefix_label=False)
48 + option_widget = widgets.CheckboxInput()
49 +
50 +class FollowSetupForm(FlaskForm):
51 + maintainers = MultiCheckboxField('Followed maintainers', coerce=int)
52 +
53 class GrumpyView(FlaskView):
54 route_base='/'
55
56 @@ -14,4 +24,14 @@ class GrumpyView(FlaskView):
57
58 def setup(self):
59 maintainers = models.Maintainer.query.order_by(collate(models.Maintainer.email, 'NOCASE')).all()
60 - return render_template("setup.html", maintainers=maintainers)
61 + form = FollowSetupForm()
62 + choices = []
63 + form_mapping = {}
64 + for maintainer in maintainers:
65 + choices.append((maintainer.id, maintainer.email))
66 + form_mapping[maintainer.id] = maintainer
67 +
68 + form.maintainers.choices = choices
69 + form.process()
70 +
71 + return render_template("setup.html", mapping=form_mapping, form=form)
72
73 diff --git a/frontend/templates/setup.html b/frontend/templates/setup.html
74 index e167c22..de1cbc8 100644
75 --- a/frontend/templates/setup.html
76 +++ b/frontend/templates/setup.html
77 @@ -1,6 +1,9 @@
78 {% extends "base.html" %}
79 {% block content %}
80
81 +<form method="POST" action=".">
82 + {{ form.hidden_tag() }}
83 +
84 <div class="panel panel-default">
85 <div class="panel-heading">
86 <h3 class="panel-title">
87 @@ -9,8 +12,10 @@
88 </div>
89 <div class="table-responsive">
90 <table class="table table-striped">
91 - {% for maintainer in maintainers if maintainer.is_project -%}
92 + {% for item in form.maintainers if mapping[item.data].is_project -%}
93 + {%- set maintainer = mapping[item.data] -%}
94 <tr>
95 + <td>{{ item }}</td>
96 <td class="text-nowrap">{{ maintainer.email }}</td>
97 <td>{{ maintainer.name }}</td>
98 </tr>
99 @@ -27,8 +32,10 @@
100 </div>
101 <div class="table-responsive">
102 <table class="table table-striped">
103 - {% for maintainer in maintainers if not maintainer.is_project -%}
104 + {% for item in form.maintainers if not mapping[item.data].is_project -%}
105 + {%- set maintainer = mapping[item.data] -%}
106 <tr>
107 + <td>{{ item }}</td>
108 <td class="text-nowrap">{{ maintainer.email }}</td>
109 <td>{{ maintainer.name }}</td>
110 </tr>
111 @@ -37,4 +44,8 @@
112 </div>
113 </div>
114
115 +<input type="submit" value="Save follows"/>
116 +
117 +</form>
118 +
119 {% endblock %}
120
121 diff --git a/requirements.txt b/requirements.txt
122 index e1076e2..f692f3c 100644
123 --- a/requirements.txt
124 +++ b/requirements.txt
125 @@ -1,5 +1,6 @@
126 Flask
127 Flask-SQLAlchemy
128 Flask-Classy
129 +Flask-WTF
130 Flask-Script #manage.py
131 requests