Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new manager option to create admin user with prompts #1

Merged
merged 4 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ def generate_fake(count=100, **kwargs):
except IntegrityError:
db.session.rollback()

@staticmethod
def create_confirmed_admin(first_name, last_name, email, password):
"""Create a confirmed admin with the given input properties."""
from sqlalchemy.exc import IntegrityError

u = User(
first_name=first_name,
last_name=last_name,
email=email,
password=password,
confirmed=True,
role=Role.query.filter_by(
permissions=Permission.ADMINISTER).first()
)
db.session.add(u)
try:
db.session.commit()
except IntegrityError:
db.session.rollback()

def __repr__(self):
return '<User \'%s\'>' % self.full_name()

Expand Down
7 changes: 7 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def setup_dev():
"""Runs the set-up needed for local development."""
setup_general()

admin_email = 'wvr@gmail.com'
if User.query.filter_by(email=admin_email).first() is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jondubin what he currently has is better than if not User.query.filter_by(email=email).first():

From PEP8:

Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators.

Also, beware of writing "if x" when you really mean "if x is not None" -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Facts

User.create_confirmed_admin('Default',
'Admin',
admin_email,
'password')


@manager.command
def setup_prod():
Expand Down