From 3a9da9f28a2bdc42b09447f7f99f770111d384d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 7 Jul 2017 00:00:08 +0200 Subject: [PATCH] Fix some styling thanks to Flake8. --- ihatemoney/forms.py | 3 +-- ihatemoney/manage.py | 3 ++- ihatemoney/models.py | 7 +++++-- ihatemoney/run.py | 1 + ihatemoney/tests/tests.py | 1 + ihatemoney/utils.py | 4 ++-- ihatemoney/web.py | 5 +++-- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index a3b3b12d..ead5586d 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -6,7 +6,6 @@ from wtforms.validators import Email, Required, ValidationError from flask_babel import lazy_gettext as _ from flask import request -from wtforms.widgets import html_params from datetime import datetime from jinja2 import Markup @@ -155,7 +154,7 @@ class MemberForm(FlaskForm): if (not form.edit and Person.query.filter( Person.name == field.data, Person.project == form.project, - Person.activated == True).all()): + Person.activated == True).all()): # NOQA raise ValidationError(_("This project already have this member")) def save(self, project, person): diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 862f36b3..6f63a98c 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -20,12 +20,13 @@ class GeneratePasswordHash(Command): def main(): app = create_app() - migrate = Migrate(app, db) + Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) manager.add_command('generate_password_hash', GeneratePasswordHash) manager.run() + if __name__ == '__main__': main() diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 1def44fa..6c71a576 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -11,8 +11,10 @@ db = SQLAlchemy() class Project(db.Model): - _to_serialize = ("id", "name", "password", "contact_email", - "members", "active_members", "balance") + _to_serialize = ( + "id", "name", "password", "contact_email", "members", "active_members", + "balance" + ) id = db.Column(db.String(64), primary_key=True) @@ -230,6 +232,7 @@ class Person(db.Model): def __repr__(self): return "" % (self.name, self.project.name) + # We need to manually define a join table for m2m relations billowers = db.Table( 'billowers', diff --git a/ihatemoney/run.py b/ihatemoney/run.py index 30570646..22cf235f 100644 --- a/ihatemoney/run.py +++ b/ihatemoney/run.py @@ -139,5 +139,6 @@ def main(): app = create_app() app.run(host="0.0.0.0", debug=True) + if __name__ == '__main__': main() diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index 5df508a7..271477aa 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -1174,5 +1174,6 @@ class ServerTestCase(APITestCase): req = self.client.get("/foo/") self.assertStatus(200, req) + if __name__ == "__main__": unittest.main() diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index ee77f01d..4e79a37b 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -1,6 +1,5 @@ import base64 import re -import inspect from io import BytesIO, StringIO from jinja2 import filters @@ -118,7 +117,7 @@ def list_of_dicts2csv(dict_to_convert): for dic in dict_to_convert: csv_data.append( [dic[h].encode('utf8') - if isinstance(dic[h], unicode) else str(dic[h]).encode('utf8') + if isinstance(dic[h], unicode) else str(dic[h]).encode('utf8') # NOQA for h in dict_to_convert[0].keys()]) except (KeyError, IndexError): csv_data = [] @@ -129,5 +128,6 @@ def list_of_dicts2csv(dict_to_convert): csv_file = BytesIO(csv_file.getvalue().encode('utf-8')) return csv_file + # base64 encoding that works with both py2 and py3 and yield no warning base64_encode = base64.encodestring if six.PY2 else base64.encodebytes diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 3afb0360..65c0ed61 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -228,7 +228,8 @@ def remind_password(): # send the password reminder password_reminder = "password_reminder.%s" % get_locale().language - current_app.mail.send(Message("password recovery", + current_app.mail.send(Message( + "password recovery", body=render_template(password_reminder, project=project), recipients=[project.contact_email])) flash(_("a mail has been sent to you with the password")) @@ -388,7 +389,7 @@ def reactivate(member_id): def remove_member(member_id): member = g.project.remove_member(member_id) if member: - if member.activated == False: + if not member.activated: flash(_("User '%(name)s' has been deactivated. It will still " "appear in the users list until its balance " "becomes zero.", name=member.name))