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

Sourcery Starbot ⭐ refactored ahmadfikrimasyhur/flask-admin #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/flask-admin master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -141 to +146
tmp_email = first_names[i].lower() + "." + last_names[i].lower() + "@example.com"
tmp_pass = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(10))
tmp_email = f"{first_names[i].lower()}.{last_names[i].lower()}@example.com"
tmp_pass = ''.join(
random.choice(string.ascii_lowercase + string.digits)
for _ in range(10)
)

Copy link
Author

Choose a reason for hiding this comment

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

Function build_sample_db refactored with the following changes:

SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE_FILE
SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_FILE}'
Copy link
Author

Choose a reason for hiding this comment

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

Lines 6-6 refactored with the following changes:

Comment on lines -111 to +115
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
return super(MyAdminIndexView, self).index()
return (
super(MyAdminIndexView, self).index()
if login.current_user.is_authenticated
else redirect(url_for('.login_view'))
)
Copy link
Author

Choose a reason for hiding this comment

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

Function MyAdminIndexView.index refactored with the following changes:

Comment on lines -204 to +213
user.email = user.login + "@example.com"
user.password = generate_password_hash(''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(10)))
user.email = f"{user.login}@example.com"
user.password = generate_password_hash(
''.join(
random.choice(string.ascii_lowercase + string.digits)
for _ in range(10)
)
)

Copy link
Author

Choose a reason for hiding this comment

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

Function build_sample_db refactored with the following changes:

override = request.args.get('lang')

if override:
if override := request.args.get('lang'):
Copy link
Author

Choose a reason for hiding this comment

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

Function get_locale refactored with the following changes:

user.email = first_names[i].lower() + "@example.com"
user.email = f"{first_names[i].lower()}@example.com"
Copy link
Author

Choose a reason for hiding this comment

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

Function build_sample_db refactored with the following changes:

tmp = u"""
return u"""
Copy link
Author

Choose a reason for hiding this comment

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

Function index refactored with the following changes:

Comment on lines -53 to +56
return Markup("<nobr>{}</nobr>".format(model.phone_number)) if model.phone_number else None
return (
Markup(f"<nobr>{model.phone_number}</nobr>")
if model.phone_number
else None
)
Copy link
Author

Choose a reason for hiding this comment

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

Function phone_number_formatter refactored with the following changes:

Comment on lines -57 to +58
return "+{} ({}) {} {} {}".format(self.dialling_code, number[0], number[1:3], number[3:6], number[6::])
return f"+{self.dialling_code} ({number[0]}) {number[1:3]} {number[3:6]} {number[6::]}"

Copy link
Author

Choose a reason for hiding this comment

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

Function User.phone_number refactored with the following changes:

Comment on lines -61 to +65
def phone_number(cls):
return sql.operators.ColumnOperators.concat(cast(cls.dialling_code, db.String), cls.local_phone_number)
def phone_number(self):
return sql.operators.ColumnOperators.concat(
cast(self.dialling_code, db.String), self.local_phone_number
)
Copy link
Author

Choose a reason for hiding this comment

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

Function User.phone_number refactored with the following changes:

Comment on lines -65 to +68
return "{}, {}".format(self.last_name, self.first_name)
return f"{self.last_name}, {self.first_name}"
Copy link
Author

Choose a reason for hiding this comment

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

Function User.__str__ refactored with the following changes:

Comment on lines -68 to +71
return "{}: {}".format(self.id, self.__str__())
return f"{self.id}: {self.__str__()}"
Copy link
Author

Choose a reason for hiding this comment

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

Function User.__repr__ refactored with the following changes:

Comment on lines -93 to +96
return "{}".format(self.title)
return f"{self.title}"
Copy link
Author

Choose a reason for hiding this comment

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

Function Post.__str__ refactored with the following changes:

Comment on lines -101 to +104
return "{}".format(self.name)
return f"{self.name}"
Copy link
Author

Choose a reason for hiding this comment

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

Function Tag.__str__ refactored with the following changes:

Comment on lines -113 to +116
return "{}".format(self.name)
return f"{self.name}"
Copy link
Author

Choose a reason for hiding this comment

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

Function Tree.__str__ refactored with the following changes:

Comment on lines -83 to +99
def __init__(cls, classname, bases, fields):
type.__init__(cls, classname, bases, fields)
def __init__(self, classname, bases, fields):
type.__init__(self, classname, bases, fields)

# Gather exposed views
cls._urls = []
cls._default_view = None
self._urls = []
self._default_view = None

for p in dir(cls):
attr = getattr(cls, p)
for p in dir(self):
attr = getattr(self, p)

if hasattr(attr, '_urls'):
# Collect methods
for url, methods in attr._urls:
cls._urls.append((url, p, methods))
self._urls.append((url, p, methods))

if url == '/':
cls._default_view = p
self._default_view = p

# Wrap views
setattr(cls, p, _wrap_view(attr))
setattr(self, p, _wrap_view(attr))
Copy link
Author

Choose a reason for hiding this comment

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

Function AdminViewMeta.__init__ refactored with the following changes:

Comment on lines -208 to +207
raise Exception(u'Attempted to instantiate admin view %s without default view' % self.__class__.__name__)
raise Exception(
f'Attempted to instantiate admin view {self.__class__.__name__} without default view'
)
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseView.__init__ refactored with the following changes:

Comment on lines -215 to +214
if endpoint:
return endpoint

return self.__class__.__name__.lower()
return endpoint or self.__class__.__name__.lower()
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseView._get_endpoint refactored with the following changes:

Comment on lines -225 to +226
if admin.url != '/':
url = '%s/%s' % (admin.url, self.endpoint)
if admin.url == '/':
url = '/' if self == admin.index_view else f'/{self.endpoint}'
else:
if self == admin.index_view:
url = '/'
else:
url = '/%s' % self.endpoint
else:
if not url.startswith('/'):
url = '%s/%s' % (admin.url, url)
url = f'{admin.url}/{self.endpoint}'
elif not url.startswith('/'):
url = f'{admin.url}/{url}'
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseView._get_view_url refactored with the following changes:

Comment on lines -394 to +386
if not self.admin or not self.admin.app:
return False

return self.admin.app.debug
return False if not self.admin or not self.admin.app else self.admin.app.debug
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseView._debug refactored with the following changes:

Comment on lines -505 to +494
self._menu_categories = dict()
self._menu_categories = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function Admin.__init__ refactored with the following changes:

Comment on lines -725 to +714
self.app.extensions = dict()
self.app.extensions = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function Admin._init_extension refactored with the following changes:

Comment on lines -54 to +59
for validator in field.validators:
if isinstance(validator, (DataRequired, InputRequired, FieldListInputRequired)):
return True
return False
return any(
isinstance(
validator, (DataRequired, InputRequired, FieldListInputRequired)
)
for validator in field.validators
)
Copy link
Author

Choose a reason for hiding this comment

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

Function is_required_form_field refactored with the following changes:

  • Use any() instead of for loop (use-any)

Comment on lines -107 to +109
errors = form[field_name].label.text + u": " + u", ".join(errors)
errors = f"{form[field_name].label.text}: " + u", ".join(errors)
Copy link
Author

Choose a reason for hiding this comment

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

Function flash_errors refactored with the following changes:

for c in self._children:
if c.is_active(view):
return True

return False
return any(c.is_active(view) for c in self._children)
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseMenu.is_active refactored with the following changes:

  • Use any() instead of for loop (use-any)

Comment on lines -191 to +195
return self._error('Cli: %s' % err)
return self._error(f'Cli: {err}')
except Exception as ex:
log.exception(ex)
return self._error('Cli: %s' % ex)
return self._error(f'Cli: {ex}')
Copy link
Author

Choose a reason for hiding this comment

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

Function RedisCli.execute_view refactored with the following changes:

form_class = wt_ndb.model_form(
return wt_ndb.model_form(
Copy link
Author

Choose a reason for hiding this comment

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

Function NdbModelView.scaffold_form refactored with the following changes:

Comment on lines -74 to +73
result = create_editable_list_form(Form, form_class, widget)
return result
return create_editable_list_form(Form, form_class, widget)
Copy link
Author

Choose a reason for hiding this comment

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

Function NdbModelView.scaffold_list_form refactored with the following changes:

Comment on lines -182 to +180
sort_field = "-" + sort_field
sort_field = f"-{sort_field}"
Copy link
Author

Choose a reason for hiding this comment

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

Function DbModelView.get_list refactored with the following changes:

Comment on lines -235 to +233
raise ValueError("Unsupported model: %s" % model)
raise ValueError(f"Unsupported model: {model}")
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelView refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant