From 43a4083eff4d9d51c77c599942390ac5f3a7d0e3 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sun, 8 Dec 2013 11:54:05 -0600 Subject: [PATCH] Add first_name and last_name --- .../{{cookiecutter.app_name}}/tests/test_models.py | 4 ++++ .../tests/webtest_tests.py | 2 +- .../{{cookiecutter.app_name}}/user/models.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/test_models.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/test_models.py index 8909efe..5b974f0 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/test_models.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/test_models.py @@ -25,5 +25,9 @@ class TestUser(DbTestCase): assert_true(user.check_password('foobarbaz123')) assert_false(user.check_password("barfoobaz")) + def test_full_name(self): + user = UserFactory(first_name="Foo", last_name="Bar") + assert_equal(user.full_name, "Foo Bar") + if __name__ == '__main__': unittest.main() diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py index 29ad412..2afc7cd 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py @@ -27,7 +27,7 @@ class TestLoggingIn(DbTestCase): form['username'] = self.user.username form['password'] = 'myprecious' # Submits - res = form.submit().follow() + res = form.submit().maybe_follow() assert_equal(res.status_code, 200) def test_sees_error_message_if_password_is_incorrect(self): diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py index 8d761b3..804689f 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py @@ -3,8 +3,8 @@ import datetime as dt from flask.ext.login import UserMixin -from {{cookiecutter.app_name}}.database import db, CRUDMixin -from {{cookiecutter.app_name}}.extensions import bcrypt +from myflaskapp.database import db, CRUDMixin +from myflaskapp.extensions import bcrypt class User(UserMixin, CRUDMixin, db.Model): @@ -14,10 +14,13 @@ class User(UserMixin, CRUDMixin, db.Model): email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String, nullable=False) # The hashed password created_at = db.Column(db.DateTime(), nullable=False) + first_name = db.Column(db.String(30), nullable=True) + last_name = db.Column(db.String(30), nullable=True) active = db.Column(db.Boolean()) is_admin = db.Column(db.Boolean()) def __init__(self, username=None, email=None, password=None, + first_name=None, last_name=None, active=False, is_admin=False): self.username = username self.email = email @@ -26,6 +29,8 @@ class User(UserMixin, CRUDMixin, db.Model): self.active = active self.is_admin = is_admin self.created_at = dt.datetime.utcnow() + self.first_name = first_name + self.last_name = last_name def set_password(self, password): self.password = bcrypt.generate_password_hash(password) @@ -33,5 +38,9 @@ class User(UserMixin, CRUDMixin, db.Model): def check_password(self, password): return bcrypt.check_password_hash(self.password, password) + @property + def full_name(self): + return "{0} {1}".format(self.first_name, self.last_name) + def __repr__(self): return ''.format(username=self.username)