Skip to content

Commit

Permalink
Format (w/ autopep8).
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Aug 29, 2017
1 parent 14e757f commit 07db907
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 102 deletions.
2 changes: 1 addition & 1 deletion abilian/core/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, logging_file=None):
if not os.path.exists(db_dir):
os.mkdir(db_dir)
self.SQLALCHEMY_DATABASE_URI = \
"sqlite:///{}/data/db.sqlite".format(current_app.instance_path)
"sqlite:///{}/data/db.sqlite".format(current_app.instance_path)

if logging_file:
self.LOGGING_CONFIG_FILE = logging_file
Expand Down
10 changes: 5 additions & 5 deletions abilian/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class Indexable(object):
'object_type',
(
(
'object_type',
ID(
stored=True,
unique=False,
),
'object_type',
ID(
stored=True,
unique=False,
),
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions abilian/core/models/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class Principal(IdMixin, TimestampedMixin, Indexable):
index_to = __indexation_args__.setdefault('index_to', ())
__indexation_args__['index_to'] += (
(
'name',
('name', 'name_prefix', 'text'),
'name',
('name', 'name_prefix', 'text'),
),
)
del index_to
Expand Down
4 changes: 2 additions & 2 deletions abilian/core/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def filter_cols(model, *filtered_columns):
m = sa.orm.class_mapper(model)
return list(
{p.key
for p in m.iterate_properties
if hasattr(p, 'columns')}.difference(filtered_columns),
for p in m.iterate_properties
if hasattr(p, 'columns')}.difference(filtered_columns),
)


Expand Down
8 changes: 4 additions & 4 deletions abilian/core/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ class MyRestrictedType(Entity):
.filter(PA.object == obj)

assert query.filter(PA.permission == security.READ).all() \
== [(security.Anonymous,)]
== [(security.Anonymous,)]

assert query.filter(PA.permission == security.WRITE).all() \
== [(security.Owner,)]
== [(security.Owner,)]

assert query.filter(PA.permission == security.DELETE).all() \
== [(security.Owner,)]
== [(security.Owner,)]

# special case:
assert query.filter(PA.permission == security.CREATE).all() \
== []
== []

security_svc = self.app.services['security']
permissions = security_svc.get_permissions_assignments(obj)
Expand Down
14 changes: 7 additions & 7 deletions abilian/services/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def _user_photo_icon_args(icon, url_args):
condition=is_authenticated,
items=(
NavItem(
'user',
'logout',
title=_l('Logout'),
icon='log-out',
url=lambda context: url_for('login.logout'),
divider=True,
'user',
'logout',
title=_l('Logout'),
icon='log-out',
url=lambda context: url_for('login.logout'),
divider=True,
),
),
)
Expand Down Expand Up @@ -219,7 +219,7 @@ def update_user_session_data(self):
# too much.
now = datetime.utcnow()
if (user.last_active is None or
(now - user.last_active) > timedelta(minutes=1)):
(now - user.last_active) > timedelta(minutes=1)):
user.last_active = now
db.session.add(user)
db.session.commit()
Expand Down
4 changes: 2 additions & 2 deletions abilian/services/conversion/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def convert(self, blob, **kw):
tmp_dir = self.TMP_DIR
cur_dir = os.getcwd()
with make_temp_file(blob, suffix=".doc") as in_fn,\
make_temp_file(suffix='.txt') as out_fn:
make_temp_file(suffix='.txt') as out_fn:
try:
os.chdir(str(tmp_dir))
subprocess.check_call([
Expand Down Expand Up @@ -181,7 +181,7 @@ class AbiwordPDFHandler(Handler):
def convert(self, blob, **kw):
cur_dir = os.getcwd()
with make_temp_file(blob, suffix=".doc") as in_fn,\
make_temp_file(suffix='.pdf') as out_fn:
make_temp_file(suffix='.pdf') as out_fn:
try:
os.chdir(bytes(self.TMP_DIR))
subprocess.check_call([
Expand Down
8 changes: 4 additions & 4 deletions abilian/services/security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ class PermissionAssignment(db.Model):
__tablename__ = 'permission_assignment'
__table_args__ = (
UniqueConstraint(
'permission',
'role',
'object_id',
name='assignments_unique',
'permission',
'role',
'object_id',
name='assignments_unique',
),
)

Expand Down
30 changes: 15 additions & 15 deletions abilian/services/security/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def query_pa_no_flush(session, permission, role, obj):
PermissionAssignment.permission == permission,
PermissionAssignment.role == role,
PermissionAssignment.object == obj,
) \
) \
.first()


Expand Down Expand Up @@ -445,7 +445,7 @@ def has_role(self, principal, role, object=None):
return True

if (principal is AnonymousRole or
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
# anonymous user, and anonymous role isn't in valid_roles
return False

Expand Down Expand Up @@ -493,7 +493,7 @@ def grant_role(self, principal, role, obj=None):
)

if (principal is AnonymousRole or
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
args['anonymous'] = True
elif isinstance(principal, User):
args['user'] = principal
Expand Down Expand Up @@ -555,7 +555,7 @@ def ungrant_role(self, principal, role, object=None):
)

if (principal is AnonymousRole or
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
(hasattr(principal, 'is_anonymous') and principal.is_anonymous)):
args['anonymous'] = True
query.filter(
RoleAssignment.anonymous == False,
Expand Down Expand Up @@ -734,24 +734,24 @@ def query_entity_with_permission(self, permission, user=None, Model=Entity):
RA = sa.sql.select([RA], principal_filter).cte()
permission_exists = \
sa.sql.exists([1]) \
.where(sa.sql.and_(
PA.permission == permission,
PA.object_id == id_column,
(RA.c.role == PA.role) | (PA.role == AnonymousRole),
(RA.c.object_id == PA.object_id) | (RA.c.object_id == None),
))
.where(sa.sql.and_(
PA.permission == permission,
PA.object_id == id_column,
(RA.c.role == PA.role) | (PA.role == AnonymousRole),
(RA.c.object_id == PA.object_id) | (RA.c.object_id == None),
))

# is_admin: self-explanatory. It search for local or global admin
# role, but PermissionAssignment is not involved, thus it can match on
# entities that don't have *any permission assignment*, whereas previous
# expressions cannot.
is_admin = \
sa.sql.exists([1]) \
.where(sa.sql.and_(
RA.c.role == Admin,
(RA.c.object_id == id_column) | (RA.c.object_id == None),
principal_filter,
))
.where(sa.sql.and_(
RA.c.role == Admin,
(RA.c.object_id == id_column) | (RA.c.object_id == None),
principal_filter,
))

filter_expr = permission_exists | is_admin

Expand Down
4 changes: 2 additions & 2 deletions abilian/services/security/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ def test_query_entity_with_permission(self):
self.session.flush()

assert set(base_query.filter(get_filter(READ, user=user)).all()) == \
{obj_reader, obj_none}
{obj_reader, obj_none}
assert set(base_query.filter(get_filter(WRITE, user=user)).all()) == \
{obj_reader, obj_none}
{obj_reader, obj_none}

# 2: global role
security.ungrant_role(user, Admin, object=obj_reader)
Expand Down
2 changes: 1 addition & 1 deletion abilian/services/vocabularies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class BaseVocabulary(db.Model):

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

Expand Down
12 changes: 6 additions & 6 deletions abilian/web/admin/panels/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def data(self, q, *args, **kwargs):
'text':
'{} {} ({})'.format(obj.first_name, obj.last_name, obj.email),
}
for obj in query.values(
User.id,
User.first_name,
User.last_name,
User.email,
)],
for obj in query.values(
User.id,
User.first_name,
User.last_name,
User.email,
)],
}
return result

Expand Down
3 changes: 1 addition & 2 deletions abilian/web/admin/panels/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ 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
62 changes: 31 additions & 31 deletions abilian/web/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,8 @@ def render_option(cls, value, label, selected, **kwargs):
options['selected'] = True
return HTMLString(
'<option %s>%s</option>' % (
html_params(**options),
cgi.escape(text_type(label)),
html_params(**options),
cgi.escape(text_type(label)),
),
)

Expand Down Expand Up @@ -1172,19 +1172,19 @@ def __call__(self, field, **kwargs):
date=date_value,
time=time_value,
)) \
+ self.date(
field,
id=field_id + '-date',
name=field_name + '-date',
value=date_value,
) \
+ self.time(
field,
id=field_id + '-time',
name=field_name + '-time',
value=time_value,
) \
+ Markup('</div>')
+ self.date(
field,
id=field_id + '-date',
name=field_name + '-date',
value=date_value,
) \
+ self.time(
field,
id=field_id + '-time',
name=field_name + '-time',
value=time_value,
) \
+ Markup('</div>')


class DefaultViewWidget(object):
Expand All @@ -1202,19 +1202,19 @@ class BooleanWidget(wtforms.widgets.CheckboxInput):
# valid data-* options when using boostrap-switch
_ON_OFF_VALID_OPTIONS = frozenset(
(
'animate',
'indeterminate',
'inverse',
'radio-all-off',
'on-color',
'off-color',
'on-text',
'off-text',
'label-text',
'handle-width',
'label-width',
'base-class',
'wrapper-class',
'animate',
'indeterminate',
'inverse',
'radio-all-off',
'on-color',
'off-color',
'on-text',
'off-text',
'label-text',
'handle-width',
'label-width',
'base-class',
'wrapper-class',
),
)

Expand Down Expand Up @@ -1296,8 +1296,8 @@ def render_view(self, field, **kwargs):
objs = [objs]
return ', '.join(
'<a href="{}">{}</a>'.format(
url_for(o),
cgi.escape(o.name),
url_for(o),
cgi.escape(o.name),
) for o in objs if o
)

Expand Down Expand Up @@ -1455,7 +1455,7 @@ def render_view(self, field, **kwargs):
[
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
callable(field.iter_choices) else field.object_data
)
else:
data = []
Expand Down
11 changes: 5 additions & 6 deletions abilian/web/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ 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 Expand Up @@ -434,8 +433,8 @@ class Module(object):
blueprint = None
search_criterions = (
search.TextSearchCriterion(
"name",
attributes=('name', 'nom'),
"name",
attributes=('name', 'nom'),
),
)
# used mostly to change datatable search_label
Expand Down Expand Up @@ -731,8 +730,8 @@ def ordered_query(self, request, query=None):
if isinstance(sort_col, _DateAffinity):
sort_dir = 'asc' if sort_dir == 'desc' else 'desc'
elif isinstance(sort_col, sa.types.String) or \
hasattr(sort_col, 'property') and \
isinstance(sort_col.property.columns[0].type, sa.types.String):
hasattr(sort_col, 'property') and \
isinstance(sort_col.property.columns[0].type, sa.types.String):
sort_col = func.lower(sort_col)

try:
Expand Down
2 changes: 1 addition & 1 deletion abilian/web/tags/criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def valid_tags(self):
Tag.ns == self.ns,
Tag.id.in_(model_tags),
)\
.all()
.all()

def get_request_values(self, request):
tag_ids = []
Expand Down
Loading

0 comments on commit 07db907

Please sign in to comment.