From 26e909f63b4617ea3b508803050b5a193b9be0e8 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Wed, 19 Oct 2016 21:13:31 +0200 Subject: [PATCH 1/4] Fixed tab indentation --- budget/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/budget/models.py b/budget/models.py index 852b3e19..2b3e44a4 100644 --- a/budget/models.py +++ b/budget/models.py @@ -224,11 +224,11 @@ class Bill(db.Model): def pay_each(self): """Compute what each share has to pay""" - if self.owers: + if self.owers: # FIXME: SQL might dot that more efficiently - return self.amount / sum(i.weight for i in self.owers) - else: - return 0 + return self.amount / sum(i.weight for i in self.owers) + else: + return 0 def __repr__(self): return "" % (self.amount, From ef1f3b29ecab5d9574323a8065649f77a80f6a57 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Wed, 19 Oct 2016 21:17:25 +0200 Subject: [PATCH 2/4] Update for Flask --- budget/api.py | 2 +- budget/forms.py | 24 +++++++++++++----------- budget/models.py | 2 +- budget/requirements.txt | 8 ++++---- budget/run.py | 4 ++-- budget/web.py | 4 ++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/budget/api.py b/budget/api.py index 0c62b292..ec664b6b 100644 --- a/budget/api.py +++ b/budget/api.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from flask import Blueprint, request -from flask.ext.rest import RESTResource, need_auth +from flask_rest import RESTResource, need_auth from models import db, Project, Person, Bill from forms import (ProjectForm, EditProjectForm, MemberForm, diff --git a/budget/forms.py b/budget/forms.py index 4b59a36b..f1972a4d 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -1,7 +1,9 @@ -from flask.ext.wtf import DateField, DecimalField, Email, Form, PasswordField, \ - Required, SelectField, SelectMultipleField, SubmitField, TextAreaField, \ - TextField, ValidationError -from flask.ext.babel import lazy_gettext as _ +from flask_wtf.form import FlaskForm +from wtforms.fields.core import SelectField, SelectMultipleField +from wtforms.fields.html5 import DateField, DecimalField +from wtforms.fields.simple import PasswordField, SubmitField, TextAreaField, TextField +from wtforms.validators import Email, Required, ValidationError +from flask_babel import lazy_gettext as _ from flask import request from wtforms.widgets import html_params @@ -57,7 +59,7 @@ class CommaDecimalField(DecimalField): return super(CommaDecimalField, self).process_formdata(value) -class EditProjectForm(Form): +class EditProjectForm(FlaskForm): name = TextField(_("Project name"), validators=[Required()]) password = TextField(_("Private code"), validators=[Required()]) contact_email = TextField(_("Email"), validators=[Required(), Email()]) @@ -97,13 +99,13 @@ class ProjectForm(EditProjectForm): "that you will be able to remember."))) -class AuthenticationForm(Form): +class AuthenticationForm(FlaskForm): id = TextField(_("Project identifier"), validators=[Required()]) password = PasswordField(_("Private code"), validators=[Required()]) submit = SubmitField(_("Get in")) -class PasswordReminder(Form): +class PasswordReminder(FlaskForm): id = TextField(_("Project identifier"), validators=[Required()]) submit = SubmitField(_("Send me the code by email")) @@ -112,7 +114,7 @@ class PasswordReminder(Form): raise ValidationError(_("This project does not exists")) -class BillForm(Form): +class BillForm(FlaskForm): date = DateField(_("Date"), validators=[Required()], default=datetime.now) what = TextField(_("What?"), validators=[Required()]) payer = SelectField(_("Payer"), validators=[Required()], coerce=int) @@ -147,7 +149,7 @@ class BillForm(Form): raise ValidationError(_("Bills can't be null")) -class MemberForm(Form): +class MemberForm(FlaskForm): name = TextField(_("Name"), validators=[Required()]) weight = CommaDecimalField(_("Weight"), default=1) @@ -180,7 +182,7 @@ class MemberForm(Form): self.weight.data = member.weight -class InviteForm(Form): +class InviteForm(FlaskForm): emails = TextAreaField(_("People to notify")) submit = SubmitField(_("Send invites")) @@ -192,7 +194,7 @@ class InviteForm(Form): email=email)) -class CreateArchiveForm(Form): +class CreateArchiveForm(FlaskForm): name = TextField(_("Name for this archive (optional)"), validators=[]) start_date = DateField(_("Start date"), validators=[Required()]) end_date = DateField(_("End date"), validators=[Required()], default=datetime.now) diff --git a/budget/models.py b/budget/models.py index 2b3e44a4..a45fea1b 100644 --- a/budget/models.py +++ b/budget/models.py @@ -1,7 +1,7 @@ from collections import defaultdict from datetime import datetime -from flask.ext.sqlalchemy import SQLAlchemy, BaseQuery +from flask_sqlalchemy import SQLAlchemy, BaseQuery from flask import g from sqlalchemy import orm diff --git a/budget/requirements.txt b/budget/requirements.txt index d49767e5..1c35283b 100644 --- a/budget/requirements.txt +++ b/budget/requirements.txt @@ -1,10 +1,10 @@ -flask>=0.9 -flask-wtf==0.8 +flask>=0.11 +flask-wtf>=0.13 flask-sqlalchemy flask-mail>=0.8 -Flask-Migrate==1.8.0 +Flask-Migrate>=1.8.0 flask-babel flask-rest -jinja2==2.6 +jinja2>=2.6 raven blinker diff --git a/budget/run.py b/budget/run.py index 8f29f35e..f006ae91 100644 --- a/budget/run.py +++ b/budget/run.py @@ -2,8 +2,8 @@ import os import warnings from flask import Flask, g, request, session -from flask.ext.babel import Babel -from flask.ext.migrate import Migrate, upgrade, stamp +from flask_babel import Babel +from flask_migrate import Migrate, upgrade, stamp from raven.contrib.flask import Sentry from web import main, db, mail diff --git a/budget/web.py b/budget/web.py index 63fbe4d5..64747119 100644 --- a/budget/web.py +++ b/budget/web.py @@ -11,8 +11,8 @@ and `add_project_id` for a quick overview) from flask import Blueprint, current_app, flash, g, redirect, \ render_template, request, session, url_for -from flask.ext.mail import Mail, Message -from flask.ext.babel import get_locale, gettext as _ +from flask_mail import Mail, Message +from flask_babel import get_locale, gettext as _ from smtplib import SMTPRecipientsRefused import werkzeug From a256bca39854b197829c51d426c42084d5cc0637 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Wed, 19 Oct 2016 21:20:31 +0200 Subject: [PATCH 3/4] Py3 fixes --- budget/tests.py | 2 +- budget/utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/budget/tests.py b/budget/tests.py index eea75372..b80ea99d 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -56,7 +56,7 @@ class TestCase(unittest.TestCase): }) def create_project(self, name): - models.db.session.add(models.Project(id=name, name=unicode(name), + models.db.session.add(models.Project(id=name, name=name, password=name, contact_email="%s@notmyidea.org" % name)) models.db.session.commit() diff --git a/budget/utils.py b/budget/utils.py index c849af0c..2a8e59ae 100644 --- a/budget/utils.py +++ b/budget/utils.py @@ -12,10 +12,10 @@ def slugify(value): Copy/Pasted from ametaireau/pelican/utils itself took from django sources. """ - if type(value) == unicode: + if type(value) == str: import unicodedata - value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') - value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) + value = unicodedata.normalize('NFKD', value) + value = re.sub('[^\w\s-]', '', value).strip().lower() return re.sub('[-\s]+', '-', value) From 45d2e3349922b4f0b6c0c64063a45cb511012c21 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Wed, 19 Oct 2016 21:22:43 +0200 Subject: [PATCH 4/4] Fixed tab indentation --- budget/tests.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/budget/tests.py b/budget/tests.py index b80ea99d..668354da 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -1,4 +1,4 @@ - # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- try: import unittest2 as unittest except ImportError: @@ -292,10 +292,10 @@ class BudgetTestCase(TestCase): self.assertTrue(models.Project.query.get("demo") is not None) def test_authentication(self): - # try to authenticate without credentials should redirect - # to the authentication page - resp = self.app.post("/authenticate") - self.assertIn("Authentication", resp.data) + # try to authenticate without credentials should redirect + # to the authentication page + resp = self.app.post("/authenticate") + self.assertIn("Authentication", resp.data) # raclette that the login / logout process works self.create_project("raclette")