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

chore: Refactor unnecessary else / elif when if block has a return statement #7331

Merged
merged 1 commit into from
Oct 6, 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
2 changes: 1 addition & 1 deletion app/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def login_user(provider):
200,
)

elif provider == 'google':
if provider == 'google':
provider_class = GoogleOAuth()
payload = {
'client_id': provider_class.get_client_id(),
Expand Down
7 changes: 3 additions & 4 deletions app/api/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def celery_task(task_id):
# check if is error
if '__error' in info:
return info['result']
# return normal
# return normal
return jsonify(state='SUCCESS', result=info)
elif state == 'FAILURE':
return jsonify(state=state)
else:
if state == 'FAILURE':
return jsonify(state=state)
return jsonify(state=state)
22 changes: 10 additions & 12 deletions app/api/custom/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ def resend_emails():
order_identifier
),
)
else:
raise UnprocessableEntityError(
{'source': 'data/order'},
"Only placed and completed orders have confirmation",
)
raise UnprocessableEntityError(
{'source': 'data/order'},
"Only placed and completed orders have confirmation",
)
else:
raise ForbiddenError({'source': ''}, "Co-Organizer Access Required")

Expand Down Expand Up @@ -190,7 +189,7 @@ def complete_order(order_id):
jsonify(status='Access Forbidden', error='You can only cancel an order.'),
403,
)
elif data['status'] == 'cancelled':
if data['status'] == 'cancelled':
order.status = 'cancelled'
db.session.add(order)
attendees = (
Expand Down Expand Up @@ -221,12 +220,11 @@ def complete_order(order_id):
),
422,
)
else:
attendees = (
db.session.query(TicketHolder)
.filter_by(order_id=order_id, deleted_at=None)
.all()
)
attendees = (
db.session.query(TicketHolder)
.filter_by(order_id=order_id, deleted_at=None)
.all()
)
form_fields = (
db.session.query(CustomForms)
.filter_by(event_id=order.event_id, form='attendee', is_included=True)
Expand Down
8 changes: 3 additions & 5 deletions app/api/event_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def create_paypal_payment_invoice(invoice_identifier):

if status:
return jsonify(status=True, payment_id=response)
else:
return jsonify(status=False, error=response)
return jsonify(status=False, error=response)


@order_misc_routes.route(
Expand Down Expand Up @@ -206,6 +205,5 @@ def charge_paypal_payment_invoice(invoice_identifier):
save_to_db(event_invoice)

return jsonify(status="Charge Successful", payment_id=paypal_payment_id)
else:
# return the error message from Paypal
return jsonify(status="Charge Unsuccessful", error=error)
# return the error message from Paypal
return jsonify(status="Charge Unsuccessful", error=error)
17 changes: 7 additions & 10 deletions app/api/helpers/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ def get_or_create(model, **kwargs):
instance = db.session.query(model).filter_by(**kwargs).first()
if instance:
return instance, was_created
else:
instance = model(**kwargs)
db.session.add(instance)
db.session.commit()
was_created = True
return instance, was_created
instance = model(**kwargs)
db.session.add(instance)
db.session.commit()
was_created = True
return instance, was_created


def get_count(query):
Expand Down Expand Up @@ -141,8 +140,7 @@ def get_new_slug(model, name):
count = get_count(model.query.filter_by(slug=slug))
if count == 0:
return slug
else:
return f'{slug}-{uuid.uuid4().hex}'
return f'{slug}-{uuid.uuid4().hex}'


def get_new_identifier(model, length=None):
Expand All @@ -153,5 +151,4 @@ def get_new_identifier(model, length=None):
count = get_count(model.query.filter_by(identifier=identifier))
if not identifier.isdigit() and count == 0:
return identifier
else:
return get_new_identifier(model)
return get_new_identifier(model)
3 changes: 1 addition & 2 deletions app/api/helpers/export_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ def export_event_json(event_id, settings):
def get_current_user():
if current_user:
return current_user
else:
return current_logged_user
return current_logged_user


# HELPERS
Expand Down
3 changes: 1 addition & 2 deletions app/api/helpers/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def jwt_authenticate(email, password):
auth_ok = user.facebook_login_hash == password or user.is_correct_password(password)
if auth_ok:
return user
else:
return None
return None


def jwt_user_loader(identity):
Expand Down
26 changes: 10 additions & 16 deletions app/api/helpers/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ def get_credentials(event=None):
'SECRET_KEY': settings['stripe_test_secret_key'],
'PUBLISHABLE_KEY': settings["stripe_test_publishable_key"],
}
elif settings['stripe_secret_key'] and settings["stripe_publishable_key"]:
if settings['stripe_secret_key'] and settings["stripe_publishable_key"]:
return {
'SECRET_KEY': settings['stripe_secret_key'],
'PUBLISHABLE_KEY': settings["stripe_publishable_key"],
}
else:
return None
return None
else:
if represents_int(event):
authorization = StripeAuthorization.query.filter_by(
Expand All @@ -68,8 +67,7 @@ def get_credentials(event=None):
'SECRET_KEY': authorization.stripe_secret_key,
'PUBLISHABLE_KEY': authorization.stripe_publishable_key,
}
else:
return None
return None

@staticmethod
def get_event_organizer_credentials_from_stripe(stripe_auth_code):
Expand Down Expand Up @@ -225,8 +223,7 @@ def create_payment(order, return_url, cancel_url, payee_email=None):

if payment.create():
return True, payment.id
else:
return False, payment.error
return False, payment.error

@staticmethod
def verify_payment(payment_id, order):
Expand All @@ -252,14 +249,13 @@ def verify_payment(payment_id, order):

if float(amount_server) != order.amount:
return False, 'Payment amount does not match order'
elif currency_server != order.event.payment_currency:
if currency_server != order.event.payment_currency:
return False, 'Payment currency does not match order'
elif sale_state != 'completed':
if sale_state != 'completed':
return False, 'Sale not completed'
elif PayPalPaymentsManager.used_payment(payment_id, order):
if PayPalPaymentsManager.used_payment(payment_id, order):
return False, 'Payment already been verified'
else:
return True, None
return True, None
except paypalrestsdk.ResourceNotFound:
return False, 'Payment Not Found'

Expand All @@ -272,8 +268,7 @@ def used_payment(payment_id, order):
order.paypal_token = payment_id
save_to_db(order)
return False
else:
return True
return True

@staticmethod
def execute_payment(paypal_payer_id, paypal_payment_id):
Expand All @@ -288,8 +283,7 @@ def execute_payment(paypal_payer_id, paypal_payment_id):

if payment.execute({"payer_id": paypal_payer_id}):
return True, 'Successfully Executed'
else:
return False, payment.error
return False, payment.error


class AliPayPaymentsManager:
Expand Down
7 changes: 3 additions & 4 deletions app/api/helpers/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def can_edit_after_cfs_ends(event_id):
or has_access('is_coorganizer', event_id=event_id)
)
)
else:
raise ForbiddenError(
{'source': '/data/event-id'}, f'Speaker Calls for event {event_id} not found',
)
raise ForbiddenError(
{'source': '/data/event-id'}, f'Speaker Calls for event {event_id} not found',
)
5 changes: 2 additions & 3 deletions app/api/helpers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ def upload(uploaded_file, key, upload_dir='static/media/', **kwargs):
return upload_to_aws(
aws_bucket_name, aws_region, aws_key, aws_secret, uploaded_file, key, **kwargs
)
elif gs_bucket_name and gs_key and gs_secret and storage_place == 'gs':
if gs_bucket_name and gs_key and gs_secret and storage_place == 'gs':
return upload_to_gs(
gs_bucket_name, gs_key, gs_secret, uploaded_file, key, **kwargs
)
else:
return upload_local(uploaded_file, key, upload_dir, **kwargs)
return upload_local(uploaded_file, key, upload_dir, **kwargs)


def upload_local(uploaded_file, key, upload_dir='static/media/', **kwargs):
Expand Down
30 changes: 14 additions & 16 deletions app/api/helpers/ticketing.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,15 @@ def charge_stripe_order_payment(order, token_id):
)

return True, 'Charge successful'
else:
# payment failed hence expire the order
order.status = 'expired'
save_to_db(order)
# payment failed hence expire the order
order.status = 'expired'
save_to_db(order)

# delete related attendees to unlock the tickets
delete_related_attendees_for_order(order)
# delete related attendees to unlock the tickets
delete_related_attendees_for_order(order)

# return the failure message from stripe.
return False, charge.failure_message
# return the failure message from stripe.
return False, charge.failure_message

@staticmethod
def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id):
Expand Down Expand Up @@ -373,13 +372,12 @@ def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id):
)

return True, 'Charge successful'
else:
# payment failed hence expire the order
order.status = 'expired'
save_to_db(order)
# payment failed hence expire the order
order.status = 'expired'
save_to_db(order)

# delete related attendees to unlock the tickets
delete_related_attendees_for_order(order)
# delete related attendees to unlock the tickets
delete_related_attendees_for_order(order)

# return the error message from Paypal
return False, error
# return the error message from Paypal
return False, error
4 changes: 1 addition & 3 deletions app/api/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ def import_event_task_base(task_handle, file_path, source_type='json', creator_i
if new_event:
url = make_frontend_url(path=f'/events/{new_event.identifier}')
return {'url': url, 'id': new_event.id, 'event_name': new_event.name}

else:
return None
return None
13 changes: 5 additions & 8 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def is_payment_valid(order, mode):
and order.last4
and order.exp_month
)
elif mode == 'paypal':
if mode == 'paypal':
return (order.paid_via == 'paypal') and order.transaction_id


Expand Down Expand Up @@ -694,8 +694,7 @@ def create_paypal_payment(order_identifier):

if status:
return jsonify(status=True, payment_id=response)
else:
return jsonify(status=False, error=response)
return jsonify(status=False, error=response)


@order_misc_routes.route(
Expand Down Expand Up @@ -760,8 +759,7 @@ def alipay_return_uri(order_identifier):
order.status = 'completed'
save_to_db(order)
return redirect(make_frontend_url(f'/orders/{order_identifier}/view'))
else:
return jsonify(status=False, error='Charge object failure')
return jsonify(status=False, error='Charge object failure')
except TypeError:
return jsonify(status=False, error='Source object status error')

Expand Down Expand Up @@ -801,10 +799,9 @@ def omise_checkout(order_identifier):
charge.failure_message, charge.failure_code
),
)
else:
logging.info(f"Successful charge: {charge.id}. Order ID: {order_identifier}")
logging.info(f"Successful charge: {charge.id}. Order ID: {order_identifier}")

return redirect(make_frontend_url(f'orders/{order_identifier}/view'))
return redirect(make_frontend_url(f'orders/{order_identifier}/view'))


@order_misc_routes.route(
Expand Down
3 changes: 1 addition & 2 deletions app/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ def is_email_available():
if email:
if get_count(db.session.query(User).filter_by(email=email)):
return jsonify(result="False")
else:
return jsonify(result="True")
return jsonify(result="True")
else:
abort(make_response(jsonify(error="Email field missing"), 422))

Expand Down
5 changes: 2 additions & 3 deletions app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ def __setattr__(self, name, value):
def set_default_event_image(cls, event_topic_id):
if event_topic_id is None:
return None
else:
event_topic = EventTopic.query.filter_by(id=event_topic_id).first()
return event_topic.system_image_url
event_topic = EventTopic.query.filter_by(id=event_topic_id).first()
return event_topic.system_image_url

@property
def fee(self):
Expand Down
3 changes: 1 addition & 2 deletions app/models/helpers/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def clean_up_string(target_string):
if target_string:
if not re.search('[a-zA-Z]', target_string):
return strip_line_breaks(target_string).strip().replace(" ", "")
else:
return remove_line_breaks(target_string).strip()
return remove_line_breaks(target_string).strip()
return target_string


Expand Down
3 changes: 1 addition & 2 deletions app/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def get_revenue(self):
return self.amount - min(
self.amount * (self.event.fee / 100.0), self.event.maximum_fee
)
else:
return 0.0
return 0.0

# Saves the order and generates and sends appropriate
# documents and notifications
Expand Down
Loading