Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Aug 29, 2017
1 parent 2106a46 commit 14e757f
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 62 deletions.
9 changes: 6 additions & 3 deletions abilian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,22 @@ def __init__(self, name=None, config=None, *args, **kwargs):

self._assets_bundles = {
'css': {
'options': dict(
'options':
dict(
filters=('less', 'cssmin'),
output='style-%(version)s.min.css',
),
},
'js-top': {
'options': dict(
'options':
dict(
output='top-%(version)s.min.js',
filters=js_filters,
),
},
'js': {
'options': dict(
'options':
dict(
output='app-%(version)s.min.js',
filters=js_filters,
),
Expand Down
3 changes: 1 addition & 2 deletions abilian/core/commands/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def reindex(clear=False, progressive=False, batch_size=None):
indexed.add(object_key)

if batch_size is not None and (
count_current %
batch_size
count_current % batch_size
) == 0:
bar.update(1)
strategy.send(COMMIT)
Expand Down
8 changes: 5 additions & 3 deletions abilian/core/extensions/upstream_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def init_app(self, app):
config[key] = val

def request_started(self, app):
_request_ctx_stack.top.upstream_info = {'Username': 'Anonymous',}
_request_ctx_stack.top.upstream_info = {
'Username': 'Anonymous',
}

def request_finished(self, app, response):
info = _request_ctx_stack.top.upstream_info
Expand All @@ -48,8 +50,8 @@ def request_finished(self, app, response):

for key, val in info.items():
if (
default_enabled and key in disabled or not default_enabled and
key not in enabled
default_enabled and key in disabled or
not default_enabled and key not in enabled
):
continue

Expand Down
4 changes: 3 additions & 1 deletion abilian/core/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class Tag(IdMixin, Model):
backref=sa.orm.backref(TAGS_ATTR, collection_class=set),
)

__mapper_args__ = {'order_by': label,}
__mapper_args__ = {
'order_by': label,
}

__table_args__ = (
sa.UniqueConstraint(ns, label),
Expand Down
7 changes: 3 additions & 4 deletions abilian/services/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ def user_logged_in(self, app, user):
g.user = g.logged_user = user
is_anonymous = user is None or user.is_anonymous
security = app.services.get('security')
g.is_manager = (user and not is_anonymous and (
(security.has_role(user, 'admin') or
security.has_role(user, 'manager'))
))
g.is_manager = (user and not is_anonymous and
((security.has_role(user, 'admin') or
security.has_role(user, 'manager'))))

def user_logged_out(self, app, user):
if hasattr(g, 'user'):
Expand Down
9 changes: 3 additions & 6 deletions abilian/services/conversion/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def to_pdf(self, digest, blob, mime_type):
self.cache[cache_key] = pdf
return pdf
raise HandlerNotFound(
"No handler found to convert from %s to PDF" %
mime_type,
"No handler found to convert from %s to PDF" % mime_type,
)

def to_text(self, digest, blob, mime_type):
Expand Down Expand Up @@ -163,8 +162,7 @@ def to_text(self, digest, blob, mime_type):
return text

raise HandlerNotFound(
"No handler found to convert from %s to text" %
mime_type,
"No handler found to convert from %s to text" % mime_type,
)

def has_image(self, digest, mime_type, index, size=500):
Expand Down Expand Up @@ -216,8 +214,7 @@ def to_image(self, digest, blob, mime_type, index, size=500):
return converted_images[index]

raise HandlerNotFound(
"No handler found to convert from %s to image" %
mime_type,
"No handler found to convert from %s to image" % mime_type,
)

def get_metadata(self, digest, content, mime_type):
Expand Down
3 changes: 2 additions & 1 deletion abilian/services/indexing/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ def register_classes(self):
state = self.app_state
classes = (
cls for cls in db.Model._decl_class_registry.values()
if isclass(cls) and issubclass(cls, Indexable) and cls.__indexable__
if isclass(cls) and issubclass(cls, Indexable) and
cls.__indexable__
)
for cls in classes:
if cls not in state.indexed_classes:
Expand Down
10 changes: 8 additions & 2 deletions abilian/services/security/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ def test_add_list_delete_permissions(self):

# set/get/delete global permission
security.add_permission(READ, Writer)
assert security.get_permissions_assignments() == {READ: {Writer,},}
assert security.get_permissions_assignments() == {
READ: {
Writer,
},
}

def test_has_permission_on_objects(self):
has_permission = security.has_permission
Expand Down Expand Up @@ -546,7 +550,9 @@ def test_add_delete_permissions_expunged_obj(self):
security.add_permission(READ, Owner, None)
obj = DummyModel()
# override default permission at instance level
obj.__default_permissions__ = frozenset({(READ, frozenset({Owner})),})
obj.__default_permissions__ = frozenset({
(READ, frozenset({Owner})),
})
# core.entities._setup_default_permissions creates
self.session.add(obj)
# permissions
Expand Down
4 changes: 3 additions & 1 deletion abilian/services/vocabularies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class BaseVocabulary(db.Model):
position = Column(sa.Integer, nullable=False, unique=True)

__table_args__ = (
sa.CheckConstraint(sa.sql.func.trim(sa.sql.text('label')) != ''),
sa.CheckConstraint(
sa.sql.func.trim(sa.sql.text('label')) != '',
),
)

@sa.ext.declarative.declared_attr
Expand Down
26 changes: 20 additions & 6 deletions abilian/services/vocabularies/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,23 @@ def test_vocabulary_creator(self):
assert IMMEDIATE.label == 'Immediate'

# test default ordering
assert ([i.label for i in PriorityVoc.query.active().all()] ==
['Immediate', 'Urgent', 'High', 'Normal', 'Low'])
assert ([i.label for i in PriorityVoc.query.active().all()] == [
'Immediate',
'Urgent',
'High',
'Normal',
'Low',
])

# no default ordering when using .values(): explicit ordering required
query = PriorityVoc.query.active().order_by(PriorityVoc.position.asc())
assert ([i.label for i in query.values(PriorityVoc.label)] ==
['Immediate', 'Urgent', 'High', 'Normal', 'Low'])
assert ([i.label for i in query.values(PriorityVoc.label)] == [
'Immediate',
'Urgent',
'High',
'Normal',
'Low',
])

# test db-side constraint for non-empty labels
try:
Expand Down Expand Up @@ -123,8 +133,12 @@ def test_vocabulary_creator(self):
item = PriorityVoc.query.by_position(URGENT.position)
assert item is URGENT
item.active = False
assert ([i.label for i in PriorityVoc.query.active().all()] ==
['Immediate', 'High', 'Normal', 'Low'])
assert ([i.label for i in PriorityVoc.query.active().all()] == [
'Immediate',
'High',
'Normal',
'Low',
])
assert PriorityVoc.query.active().by_position(URGENT.position) is None

# test by_label()
Expand Down
5 changes: 3 additions & 2 deletions abilian/web/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ def endpoint(self):
assert isinstance(kwargs, dict)
endpoint = self.Endpoint(endpoint, **kwargs)
else:
raise ValueError('Invalid endpoint specifier: "%s"' %
repr(endpoint))
raise ValueError(
'Invalid endpoint specifier: "%s"' % repr(endpoint),
)

return endpoint

Expand Down
3 changes: 2 additions & 1 deletion abilian/web/admin/panels/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def data(self, q, *args, **kwargs):

result = {
'results': [{
'id': obj.id,
'id':
obj.id,
'text':
'{} {} ({})'.format(obj.first_name, obj.last_name, obj.email),
}
Expand Down
3 changes: 2 additions & 1 deletion abilian/web/admin/panels/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class BaseUserAdminForm(Form):
validators=(optional(),),
multiple=True,
collection_class=set,
query_factory=lambda: Group.query.order_by(sa.sql.func.lower(Group.name).asc()),
query_factory=
lambda: Group.query.order_by(sa.sql.func.lower(Group.name).asc()),
get_label='name',
)

Expand Down
5 changes: 4 additions & 1 deletion abilian/web/admin/panels/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def data(self, *args, **kw):
}
columns = list(SORT_COLS.get(sort_col, []))
columns.extend(
[func.lower(User.last_name), func.lower(User.first_name)],
[
func.lower(User.last_name),
func.lower(User.first_name),
],
)

direction = asc if sort_dir == 'asc' else desc
Expand Down
34 changes: 21 additions & 13 deletions abilian/web/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ def render_line(self, entity):
cell = Markup('<a href="%s">%s</a>' %
(build_url(entity), cgi.escape(text_type(value))))
elif isinstance(value, Entity):
cell = Markup('<a href="%s">%s</a>' %
(build_url(value), cgi.escape(value.name)))
cell = Markup('<a href="%s">%s</a>' % (
build_url(value),
cgi.escape(value.name),
))
elif isinstance(value, string_types) \
and (value.startswith("http://") or value.startswith("www.")):
cell = Markup(linkify_url(value))
Expand Down Expand Up @@ -437,11 +439,15 @@ def render_line(self, entity):
if has_custom_display:
cell = value
elif column_name == 'name':
cell = Markup('<a href="%s">%s</a>' %
(url_for(entity), cgi.escape(value)))
cell = Markup('<a href="%s">%s</a>' % (
url_for(entity),
cgi.escape(value),
))
elif isinstance(value, Entity):
cell = Markup('<a href="%s">%s</a>' %
(url_for(value), cgi.escape(value.name)))
cell = Markup('<a href="%s">%s</a>' % (
url_for(value),
cgi.escape(value.name),
))
elif (isinstance(value, string_types) and
(value.startswith("http://") or value.startswith("www."))):
cell = Markup(linkify_url(value))
Expand Down Expand Up @@ -961,8 +967,10 @@ def render_option(cls, value, label, selected, **kwargs):
if selected:
options['selected'] = True
return HTMLString(
'<option %s>%s</option>' %
(html_params(**options), cgi.escape(text_type(label))),
'<option %s>%s</option>' % (
html_params(**options),
cgi.escape(text_type(label)),
),
)


Expand All @@ -977,9 +985,9 @@ def __call__(self, field, **kwargs):
if 'value' not in kwargs:
kwargs['value'] = field._value()

return HTMLString('<input %s>' % self.html_params(
name=field.name, **kwargs
))
return HTMLString(
'<input %s>' % self.html_params(name=field.name, **kwargs),
)


class DateInput(Input):
Expand Down Expand Up @@ -1446,8 +1454,8 @@ def render_view(self, field, **kwargs):
data = (
[
label for v, label, checked in field.iter_choices() if checked
] if hasattr(field, 'iter_choices') and callable(field.iter_choices)
else field.object_data
] if hasattr(field, 'iter_choices') and
callable(field.iter_choices) else field.object_data
)
else:
data = []
Expand Down
3 changes: 2 additions & 1 deletion abilian/web/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def can_create(self):
button='default',
condition=lambda ctx: ctx['view'].can_edit,
icon=FAIcon('edit'),
url=lambda ctx: url_for('.entity_edit', **{ctx['view'].pk: ctx['view'].obj.id}),
url=
lambda ctx: url_for('.entity_edit', **{ctx['view'].pk: ctx['view'].obj.id}),
)

DELETE_ACTION = Action(
Expand Down
10 changes: 8 additions & 2 deletions abilian/web/tags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ def form_valid(self, redirect_to=None):


entity_bp.route('/<int:object_id>/add')(
EntityTagManage.as_view('add', mode='add'),
EntityTagManage.as_view(
'add',
mode='add',
),
)
entity_bp.route('/<int:object_id>/remove')(
EntityTagManage.as_view('remove', mode='remove'),
EntityTagManage.as_view(
'remove',
mode='remove',
),
)


Expand Down
12 changes: 8 additions & 4 deletions abilian/web/tools/debug_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ def content(self):
ns_name = var_name
for signal_name, signal in ns.items():
d = {
'module_name': module_name,
'ns_name': ns_name,
'signal_name': signal_name,
'signal': signal,
'module_name':
module_name,
'ns_name':
ns_name,
'signal_name':
signal_name,
'signal':
signal,
'receivers':
[text_type(r) for r in signal.receivers.values()],
}
Expand Down
3 changes: 1 addition & 2 deletions abilian/web/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def get(self, attach, *args, **kwargs):
"""
response = self.make_response(*args, **kwargs)
response.headers['content-type'] = self.get_content_type(
*args,
**kwargs
*args, **kwargs
)

if attach:
Expand Down
3 changes: 1 addition & 2 deletions abilian/web/views/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ def make_response(self, user, image, size, *args, **kwargs):
if image:
# user has set a photo
return super(UserMugshot, self).make_response(
image, size, *args,
**kwargs
image, size, *args, **kwargs
)

# render svg avatar
Expand Down
6 changes: 4 additions & 2 deletions etc/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ flake8-mutable
pylint
pre-commit

# Format
yapf==0.15.2
# Formatting (update version explicitely when needed)
isort==4.2.15
yapf==0.17.0
autopep8==1.3.2
add-trailing-comma

# These two plugins try too hard..
Expand Down
Loading

0 comments on commit 14e757f

Please sign in to comment.