diff --git a/app/api/auth.py b/app/api/auth.py index 381fa913ab..780381092c 100644 --- a/app/api/auth.py +++ b/app/api/auth.py @@ -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(), diff --git a/app/api/celery_tasks.py b/app/api/celery_tasks.py index 6b716a7863..3f60ad37cb 100644 --- a/app/api/celery_tasks.py +++ b/app/api/celery_tasks.py @@ -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) diff --git a/app/api/custom/orders.py b/app/api/custom/orders.py index 07d3d1f20d..a331664835 100644 --- a/app/api/custom/orders.py +++ b/app/api/custom/orders.py @@ -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") @@ -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 = ( @@ -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) diff --git a/app/api/event_invoices.py b/app/api/event_invoices.py index b064f0203c..874db4ebc8 100644 --- a/app/api/event_invoices.py +++ b/app/api/event_invoices.py @@ -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( @@ -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) diff --git a/app/api/helpers/db.py b/app/api/helpers/db.py index 12c485744c..4d566cbf60 100644 --- a/app/api/helpers/db.py +++ b/app/api/helpers/db.py @@ -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): @@ -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): @@ -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) diff --git a/app/api/helpers/export_helpers.py b/app/api/helpers/export_helpers.py index 8eabf2031e..9c78e511f0 100644 --- a/app/api/helpers/export_helpers.py +++ b/app/api/helpers/export_helpers.py @@ -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 diff --git a/app/api/helpers/jwt.py b/app/api/helpers/jwt.py index 2c429ab2ad..9c8fb6921e 100644 --- a/app/api/helpers/jwt.py +++ b/app/api/helpers/jwt.py @@ -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): diff --git a/app/api/helpers/payment.py b/app/api/helpers/payment.py index 294eab83a9..b57c733a57 100644 --- a/app/api/helpers/payment.py +++ b/app/api/helpers/payment.py @@ -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( @@ -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): @@ -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): @@ -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' @@ -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): @@ -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: diff --git a/app/api/helpers/speaker.py b/app/api/helpers/speaker.py index dc4341df7b..62d145f359 100644 --- a/app/api/helpers/speaker.py +++ b/app/api/helpers/speaker.py @@ -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', + ) diff --git a/app/api/helpers/storage.py b/app/api/helpers/storage.py index efb0548451..31bfbe64d3 100644 --- a/app/api/helpers/storage.py +++ b/app/api/helpers/storage.py @@ -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): diff --git a/app/api/helpers/ticketing.py b/app/api/helpers/ticketing.py index 973b6a731e..5eb1a537e4 100644 --- a/app/api/helpers/ticketing.py +++ b/app/api/helpers/ticketing.py @@ -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): @@ -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 diff --git a/app/api/imports.py b/app/api/imports.py index ef6e0b04dd..24316007f1 100644 --- a/app/api/imports.py +++ b/app/api/imports.py @@ -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 diff --git a/app/api/orders.py b/app/api/orders.py index 043cf2f810..eadffab266 100644 --- a/app/api/orders.py +++ b/app/api/orders.py @@ -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 @@ -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( @@ -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') @@ -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( diff --git a/app/api/users.py b/app/api/users.py index 398032e95f..3607bab587 100644 --- a/app/api/users.py +++ b/app/api/users.py @@ -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)) diff --git a/app/models/event.py b/app/models/event.py index 92b285ab3a..2984361c57 100644 --- a/app/models/event.py +++ b/app/models/event.py @@ -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): diff --git a/app/models/helpers/versioning.py b/app/models/helpers/versioning.py index 65a49c6a94..f1cf920f97 100644 --- a/app/models/helpers/versioning.py +++ b/app/models/helpers/versioning.py @@ -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 diff --git a/app/models/order.py b/app/models/order.py index c50489c5df..bd153280d3 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -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 diff --git a/app/models/setting.py b/app/models/setting.py index 14fe00101c..12173119f5 100644 --- a/app/models/setting.py +++ b/app/models/setting.py @@ -198,10 +198,9 @@ def is_paypal_activated(self): and self.paypal_sandbox_secret ): return True - elif self.paypal_client and self.paypal_secret: + if self.paypal_client and self.paypal_secret: return True - else: - return False + return False @hybrid_property def is_stripe_activated(self): @@ -222,10 +221,9 @@ def is_omise_activated(self): and self.omise_test_secret ): return True - elif self.omise_live_public and self.omise_live_secret: + if self.omise_live_public and self.omise_live_secret: return True - else: - return False + return False @property def is_billing_paypal_activated(self): diff --git a/app/models/social_link.py b/app/models/social_link.py index 4fd6e3c7bd..648ea148a7 100644 --- a/app/models/social_link.py +++ b/app/models/social_link.py @@ -16,8 +16,7 @@ def get_new_social_link_identifier(length=8): count = get_count(SocialLink.query.filter_by(identifier=identifier)) if count == 0: return identifier - else: - return get_new_social_link_identifier(length) + return get_new_social_link_identifier(length) class SocialLink(SoftDeletionModel): diff --git a/app/models/user.py b/app/models/user.py index 741d2601a1..4f78d99e79 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -196,8 +196,7 @@ def has_role(self, event_id): ).first() if uer is None: return False - else: - return True + return True def _is_role(self, role_name, event_id=None): """ @@ -210,8 +209,7 @@ def _is_role(self, role_name, event_id=None): uer = UER.query.filter_by(user=self, role=role).first() if not uer: return False - else: - return True + return True def is_owner(self, event_id): return self._is_role(OWNER, event_id) diff --git a/app/views/healthcheck.py b/app/views/healthcheck.py index e9cc3d395c..f6074ead62 100644 --- a/app/views/healthcheck.py +++ b/app/views/healthcheck.py @@ -86,8 +86,7 @@ def health_check_migrations(): result = current_app.config['MIGRATION_STATUS'].split(',') if result[0] == 'success': return True, result[1] - else: - # the exception will be caught in check_migrations function, so no need for sentry catching exception here - return False, result[1] + # the exception will be caught in check_migrations function, so no need for sentry catching exception here + return False, result[1] else: return False, 'The health_check_migration test is still running'