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

ref: Reformat and pre-commit configuration #7344

Merged
merged 2 commits into from
Oct 9, 2020
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
8 changes: 8 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file can be used for git blame using --ignore-revs-file
# or by setting blame.ignoreRevsFile in the git config.

ref: Reformat files with black and configure hooks
5bce86c394b5eea6043c071fd017427398c6290e

ref: Format files using black
830d81a61c5a1c0a098091ef24fef968e5bff367
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
exclude: '.venv|migrations'
repos:
- repo: https://github.com/hadialqattan/pycln
rev: v0.0.1-alpha.3
hooks:
- id: pycln
args: [--config=pyproject.toml]
- repo: https://github.com/pycqa/isort
rev: 5.5.4
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: stable
rev: 20.8b1
hooks:
- id: black
exclude:
- .venv/
- migrations/
- manage.py
- instance.py
- hook_main.py
language_version: python3.7
4 changes: 3 additions & 1 deletion app/api/access_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def query(self, view_kwargs):
data_layer = {
'session': db.session,
'model': AccessCode,
'methods': {'query': query,},
'methods': {
'query': query,
},
}


Expand Down
12 changes: 10 additions & 2 deletions app/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class ActivityList(ResourceList):
methods = [
'GET',
]
decorators = (api.has_permission('is_admin',),)
decorators = (
api.has_permission(
'is_admin',
),
)
data_layer = {'session': db.session, 'model': Activity}


Expand All @@ -28,5 +32,9 @@ class ActivityDetail(ResourceDetail):
methods = [
'GET',
]
decorators = (api.has_permission('is_admin',),)
decorators = (
api.has_permission(
'is_admin',
),
)
data_layer = {'session': db.session, 'model': Activity}
24 changes: 12 additions & 12 deletions app/api/attendees.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_sold_and_reserved_tickets_count(ticket_id):

class AttendeeListPost(ResourceList):
"""
List and create Attendees through direct URL
List and create Attendees through direct URL
"""

def before_post(self, args, kwargs, data):
Expand Down Expand Up @@ -128,7 +128,10 @@ def query(self, view_kwargs):

if view_kwargs.get('order_identifier'):
order = safe_query_kwargs(
Order, view_kwargs, 'order_identifier', 'identifier',
Order,
view_kwargs,
'order_identifier',
'identifier',
)
if not has_access('is_registrar', event_id=order.event_id) and not has_access(
'is_user_itself', user_id=order.user_id
Expand Down Expand Up @@ -232,24 +235,21 @@ def before_update_object(self, obj, data, kwargs):
{'pointer': '/data/attributes/checkin_times'},
"Check in time missing while trying to check in attendee",
)
if obj.checkin_times and data[
'checkin_times'
] not in obj.checkin_times.split(","):
if obj.checkin_times and data['checkin_times'] not in obj.checkin_times.split(
","
):
data['checkin_times'] = '{},{}'.format(
obj.checkin_times, data['checkin_times']
)
elif obj.checkin_times and data[
'checkin_times'
] in obj.checkin_times.split(","):
elif obj.checkin_times and data['checkin_times'] in obj.checkin_times.split(
","
):
raise UnprocessableEntityError(
{'pointer': '/data/attributes/checkin_times'},
"Check in time already present",
)

if (
'device_name_checkin' in data
and data['device_name_checkin'] is not None
):
if 'device_name_checkin' in data and data['device_name_checkin'] is not None:
if obj.device_name_checkin is not None:
data['device_name_checkin'] = '{},{}'.format(
obj.device_name_checkin, data['device_name_checkin']
Expand Down
6 changes: 4 additions & 2 deletions app/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def redirect_uri(provider):
client_id = provider_class.get_client_id()
if not client_id:
return make_response(
jsonify(message=f"{provider} client id is not configured on the server"), 404,
jsonify(message=f"{provider} client id is not configured on the server"),
404,
)

url = (
Expand Down Expand Up @@ -436,7 +437,8 @@ def change_password():
def return_file(file_name_prefix, file_path, identifier):
response = make_response(send_file(file_path))
response.headers['Content-Disposition'] = 'attachment; filename={}-{}.pdf'.format(
file_name_prefix, identifier,
file_name_prefix,
identifier,
)
return response

Expand Down
7 changes: 3 additions & 4 deletions app/api/custom/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def create_order():

if not tickets:
raise UnprocessableEntityError(
{'source': 'tickets'}, "Tickets missing in Order request",
{'source': 'tickets'},
"Tickets missing in Order request",
)

event = tickets[0].event
Expand Down Expand Up @@ -220,9 +221,7 @@ def complete_order(order_id):
422,
)
attendees = (
db.session.query(TicketHolder)
.filter_by(order_id=order_id, deleted_at=None)
.all()
db.session.query(TicketHolder).filter_by(order_id=order_id, deleted_at=None).all()
)
form_fields = (
db.session.query(CustomForms)
Expand Down
5 changes: 4 additions & 1 deletion app/api/custom_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def before_get_object(self, view_kwargs):
event = safe_query_kwargs(Event, view_kwargs, 'event_id')
elif view_kwargs.get('event_identifier'):
event = safe_query_kwargs(
Event, view_kwargs, 'event_identifier', 'identifier',
Event,
view_kwargs,
'event_identifier',
'identifier',
)

if event:
Expand Down
12 changes: 9 additions & 3 deletions app/api/custom_placeholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def query(self, view_kwargs):
query_ = self.session.query(CustomPlaceholder)
if view_kwargs.get('event_sub_topic_id'):
event_sub_topic = safe_query_kwargs(
EventSubTopic, view_kwargs, 'event_sub_topic_id',
EventSubTopic,
view_kwargs,
'event_sub_topic_id',
)
query_ = query_.join(EventSubTopic).filter(
EventSubTopic.id == event_sub_topic.id
Expand All @@ -39,7 +41,9 @@ def before_create_object(self, data, view_kwargs):
"""
if view_kwargs.get('event_sub_topic_id'):
event_sub_topic = safe_query_kwargs(
EventSubTopic, view_kwargs, 'event_sub_topic_id',
EventSubTopic,
view_kwargs,
'event_sub_topic_id',
)
data['event_sub_topic_id'] = event_sub_topic.id

Expand Down Expand Up @@ -87,7 +91,9 @@ def before_get_object(self, view_kwargs):
event_sub_topic = None
if view_kwargs.get('event_sub_topic_id'):
event_sub_topic = safe_query_kwargs(
EventSubTopic, view_kwargs, 'event_sub_topic_id',
EventSubTopic,
view_kwargs,
'event_sub_topic_id',
)

if event_sub_topic:
Expand Down
14 changes: 11 additions & 3 deletions app/api/discount_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def query(self, view_kwargs):

if view_kwargs.get('event_identifier'):
event = safe_query_kwargs(
Event, view_kwargs, 'event_identifier', 'identifier',
Event,
view_kwargs,
'event_identifier',
'identifier',
)
view_kwargs['event_id'] = event.id

Expand Down Expand Up @@ -316,7 +319,10 @@ def before_get_object(self, view_kwargs):
"""
if view_kwargs.get('event_identifier'):
event = safe_query_kwargs(
Event, view_kwargs, 'event_identifier', 'identifier',
Event,
view_kwargs,
'event_identifier',
'identifier',
)
view_kwargs['event_id'] = event.id

Expand All @@ -329,7 +335,9 @@ def before_get_object(self, view_kwargs):

if view_kwargs.get('event_invoice_id') and has_access('is_admin'):
event_invoice = safe_query_kwargs(
EventInvoice, view_kwargs, 'event_invoice_id',
EventInvoice,
view_kwargs,
'event_invoice_id',
)
if event_invoice.discount_code_id:
view_kwargs['id'] = event_invoice.discount_code_id
Expand Down
4 changes: 3 additions & 1 deletion app/api/event_sub_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def before_get_object(self, view_kwargs):

if view_kwargs.get('custom_placeholder_id'):
custom_placeholder = safe_query_kwargs(
CustomPlaceholder, view_kwargs, 'custom_placeholder_id',
CustomPlaceholder,
view_kwargs,
'custom_placeholder_id',
)
if custom_placeholder.event_sub_topic_id:
view_kwargs['id'] = custom_placeholder.event_sub_topic_id
Expand Down
4 changes: 3 additions & 1 deletion app/api/event_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def before_get_object(self, view_kwargs):

if view_kwargs.get('event_sub_topic_id'):
event_sub_topic = safe_query_kwargs(
EventSubTopic, view_kwargs, 'event_sub_topic_id',
EventSubTopic,
view_kwargs,
'event_sub_topic_id',
)
if event_sub_topic.event_topic_id:
view_kwargs['id'] = event_sub_topic.event_topic_id
Expand Down
23 changes: 18 additions & 5 deletions app/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ def query(self, view_kwargs):
):
raise ForbiddenError({'source': ''}, 'Access Forbidden')
user = safe_query(
User, 'id', view_kwargs['user_track_organizer_id'], 'user_organizer_id',
User,
'id',
view_kwargs['user_track_organizer_id'],
'user_organizer_id',
)
query_ = (
query_.join(Event.roles)
Expand Down Expand Up @@ -341,7 +344,11 @@ def after_create_object(self, event, data, view_kwargs):

# This permission decorator ensures, you are logged in to create an event
# and have filter ?withRole to get events associated with logged in user
decorators = (api.has_permission('create_event',),)
decorators = (
api.has_permission(
'create_event',
),
)
schema = EventSchema
data_layer = {
'session': db.session,
Expand Down Expand Up @@ -369,7 +376,9 @@ def get_id(view_kwargs):

if view_kwargs.get('user_favourite_event_id') is not None:
user_favourite_event = safe_query_kwargs(
UserFavouriteEvent, view_kwargs, 'user_favourite_event_id',
UserFavouriteEvent,
view_kwargs,
'user_favourite_event_id',
)
if user_favourite_event.event_id is not None:
view_kwargs['id'] = user_favourite_event.event_id
Expand Down Expand Up @@ -450,7 +459,9 @@ def get_id(view_kwargs):

if view_kwargs.get('stripe_authorization_id') is not None:
stripe_authorization = safe_query_kwargs(
StripeAuthorization, view_kwargs, 'stripe_authorization_id',
StripeAuthorization,
view_kwargs,
'stripe_authorization_id',
)
if stripe_authorization.event_id is not None:
view_kwargs['id'] = stripe_authorization.event_id
Expand Down Expand Up @@ -505,7 +516,9 @@ def get_id(view_kwargs):

if view_kwargs.get('users_events_role_id') is not None:
users_events_role = safe_query_kwargs(
UsersEventsRoles, view_kwargs, 'users_events_role_id',
UsersEventsRoles,
view_kwargs,
'users_events_role_id',
)
if users_events_role.event_id is not None:
view_kwargs['id'] = users_events_role.event_id
Expand Down
8 changes: 7 additions & 1 deletion app/api/faq_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ def query(self, view_kwargs):
'GET',
]
schema = FaqTypeSchema
data_layer = {'session': db.session, 'model': FaqType, 'methods': {'query': query,}}
data_layer = {
'session': db.session,
'model': FaqType,
'methods': {
'query': query,
},
}


class FaqTypeDetail(ResourceDetail):
Expand Down
4 changes: 3 additions & 1 deletion app/api/helpers/custom_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def get_schema(form_fields):

def validate_custom_form_constraints(form, obj, relationship_fields):
form_fields = CustomForms.query.filter_by(
form=form, event_id=obj.event_id, is_included=True,
form=form,
event_id=obj.event_id,
is_included=True,
).all()
required_form_fields = filter(lambda field: field.is_required, form_fields)
missing_required_fields = []
Expand Down
10 changes: 8 additions & 2 deletions app/api/helpers/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def safe_query_kwargs(model, kwargs, parameter_name, column_name='id'):
:param column_name: Name of column default is 'id'.
:return:
"""
return safe_query(model, column_name, kwargs[parameter_name], parameter_name,)
return safe_query(
model,
column_name,
kwargs[parameter_name],
parameter_name,
)


def safe_query_without_soft_deleted_entries(
Expand All @@ -71,7 +76,8 @@ def safe_query_without_soft_deleted_entries(
record = record.one()
except NoResultFound:
raise ObjectNotFound(
{'parameter': f'{parameter_name}'}, f"{model.__name__}: {value} not found",
{'parameter': f'{parameter_name}'},
f"{model.__name__}: {value} not found",
)
else:
return record
Expand Down
3 changes: 2 additions & 1 deletion app/api/helpers/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def send_order_cancel_email(order):
to=order.user.email,
action=TICKET_CANCELLED,
subject=MAILS[TICKET_CANCELLED]['subject'].format(
event_name=order.event.name, invoice_id=order.invoice_number,
event_name=order.event.name,
invoice_id=order.invoice_number,
),
html=MAILS[TICKET_CANCELLED]['message'].format(
event_name=order.event.name,
Expand Down
5 changes: 4 additions & 1 deletion app/api/helpers/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def send_notif_monthly_fee_payment(
notification = NOTIFS[key]
title = notification['subject'].format(date=previous_month, event_name=event_name)
message = notification['message'].format(
event_name=event_name, date=previous_month, amount=amount, app_name=app_name,
event_name=event_name,
date=previous_month,
amount=amount,
app_name=app_name,
)

send_notification(user, title, message, actions)
Expand Down
Loading