From 51d53b70ed9f5c0b6be0bebfd42157ba398795d4 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 16 Jul 2024 17:37:05 +0530 Subject: [PATCH] rename get_route_url() -> get_app_route_url() --- bots/admin.py | 5 ++--- daras_ai_v2/billing.py | 22 +++++++++++----------- daras_ai_v2/bot_integration_widgets.py | 21 +++++++++------------ daras_ai_v2/fastapi_tricks.py | 6 +++--- daras_ai_v2/send_email.py | 4 ++-- payments/models.py | 4 ++-- payments/tasks.py | 8 ++++---- routers/account.py | 4 ++-- routers/paypal.py | 6 +++--- 9 files changed, 38 insertions(+), 42 deletions(-) diff --git a/bots/admin.py b/bots/admin.py index 73fd8463a..59260e4e5 100644 --- a/bots/admin.py +++ b/bots/admin.py @@ -31,8 +31,7 @@ Workflow, ) from bots.tasks import create_personal_channels_for_all_members -from celeryapp.tasks import runner_task -from daras_ai_v2.fastapi_tricks import get_route_url +from daras_ai_v2.fastapi_tricks import get_app_route_url from gooeysite.custom_actions import export_to_excel, export_to_csv from gooeysite.custom_filters import ( related_json_field_summary, @@ -277,7 +276,7 @@ def api_integration_stats_url(self, bi: BotIntegration): integration_id = bi.api_integration_id() return open_in_new_tab( - url=get_route_url( + url=get_app_route_url( integrations_stats_route, path_params=dict( page_slug=VideoBotsPage.slug_versions[-1], diff --git a/daras_ai_v2/billing.py b/daras_ai_v2/billing.py index 709fde926..0e16d25db 100644 --- a/daras_ai_v2/billing.py +++ b/daras_ai_v2/billing.py @@ -7,7 +7,7 @@ from app_users.models import AppUser, PaymentProvider from daras_ai_v2 import icons, settings, paypal from daras_ai_v2.base import RedirectException -from daras_ai_v2.fastapi_tricks import get_route_url +from daras_ai_v2.fastapi_tricks import get_app_route_url from daras_ai_v2.grid_layout_widget import grid_layout from daras_ai_v2.settings import templates from daras_ai_v2.user_date_widgets import render_local_date_attrs @@ -55,7 +55,7 @@ def render_payments_setup(): st.html( templates.get_template("payment_setup.html").render( settings=settings, - payment_processing_url=get_route_url(payment_processing_route), + payment_processing_url=get_app_route_url(payment_processing_route), ) ) @@ -319,13 +319,13 @@ def change_subscription(user: AppUser, new_plan: PricingPlan, **kwargs): current_plan = PricingPlan.from_sub(user.subscription) if new_plan == current_plan: - raise RedirectException(get_route_url(account_route), status_code=303) + raise RedirectException(get_app_route_url(account_route), status_code=303) if new_plan == PricingPlan.STARTER: user.subscription.cancel() user.subscription.delete() raise RedirectException( - get_route_url(payment_processing_route), status_code=303 + get_app_route_url(payment_processing_route), status_code=303 ) match user.subscription.payment_provider: @@ -347,7 +347,7 @@ def change_subscription(user: AppUser, new_plan: PricingPlan, **kwargs): proration_behavior="none", ) raise RedirectException( - get_route_url(payment_processing_route), status_code=303 + get_app_route_url(payment_processing_route), status_code=303 ) case PaymentProvider.PAYPAL: @@ -469,8 +469,8 @@ def stripe_addon_checkout_redirect(user: AppUser, dollat_amt: int): checkout_session = stripe.checkout.Session.create( line_items=[line_item], mode="payment", - success_url=get_route_url(payment_processing_route), - cancel_url=get_route_url(account_route), + success_url=get_app_route_url(payment_processing_route), + cancel_url=get_app_route_url(account_route), customer=user.get_or_create_stripe_customer(), invoice_creation={"enabled": True}, allow_promotion_codes=True, @@ -512,8 +512,8 @@ def stripe_subscription_checkout_redirect(user: AppUser, plan: PricingPlan): checkout_session = stripe.checkout.Session.create( line_items=[(plan.get_stripe_line_item())], mode="subscription", - success_url=get_route_url(payment_processing_route), - cancel_url=get_route_url(account_route), + success_url=get_app_route_url(payment_processing_route), + cancel_url=get_app_route_url(account_route), customer=user.get_or_create_stripe_customer(), metadata=metadata, subscription_data={"metadata": metadata}, @@ -598,8 +598,8 @@ def change_payment_method(user: AppUser): setup_intent_data={ "metadata": {"subscription_id": user.subscription.external_id}, }, - success_url=get_route_url(payment_processing_route), - cancel_url=get_route_url(account_route), + success_url=get_app_route_url(payment_processing_route), + cancel_url=get_app_route_url(account_route), ) raise RedirectException(session.url, status_code=303) case _: diff --git a/daras_ai_v2/bot_integration_widgets.py b/daras_ai_v2/bot_integration_widgets.py index 6d482ef9c..b6324ce5f 100644 --- a/daras_ai_v2/bot_integration_widgets.py +++ b/daras_ai_v2/bot_integration_widgets.py @@ -11,7 +11,7 @@ from bots.models import BotIntegration, BotIntegrationAnalysisRun, Platform from daras_ai_v2 import settings, icons from daras_ai_v2.api_examples_widget import bot_api_example_generator -from daras_ai_v2.fastapi_tricks import get_route_path +from daras_ai_v2.fastapi_tricks import get_app_route_url from daras_ai_v2.workflow_url_input import workflow_url_input from recipes.BulkRunner import list_view_editor from recipes.CompareLLM import CompareLLMPage @@ -247,24 +247,21 @@ def get_bot_test_link(bi: BotIntegration) -> str | None: elif bi.fb_page_name: return (furl("https://www.facebook.com/") / bi.fb_page_id).tostr() elif bi.platform == Platform.WEB: - return str( - furl(settings.APP_BASE_URL) - / get_route_path( - chat_route, - dict( - integration_id=bi.api_integration_id(), - integration_name=slugify(bi.name) or "untitled", - ), - ) + return get_app_route_url( + chat_route, + path_params=dict( + integration_id=bi.api_integration_id(), + integration_name=slugify(bi.name) or "untitled", + ), ) else: return None def get_web_widget_embed_code(bi: BotIntegration) -> str: - lib_src = furl(settings.APP_BASE_URL) / get_route_path( + lib_src = get_app_route_url( chat_lib_route, - dict( + path_params=dict( integration_id=bi.api_integration_id(), integration_name=slugify(bi.name) or "untitled", ), diff --git a/daras_ai_v2/fastapi_tricks.py b/daras_ai_v2/fastapi_tricks.py index 9cf5693ba..b98314161 100644 --- a/daras_ai_v2/fastapi_tricks.py +++ b/daras_ai_v2/fastapi_tricks.py @@ -57,7 +57,7 @@ def resolve_url(url: str) -> ResolverMatch | None: def get_api_route_url( - route_fn: typing.Callable, path_params: dict = None, *, query_params: dict = None + route_fn: typing.Callable, *, path_params: dict = None, query_params: dict = None ) -> str: return str( furl(settings.API_BASE_URL, query_params=query_params) @@ -65,8 +65,8 @@ def get_api_route_url( ) -def get_route_url( - route_fn: typing.Callable, path_params: dict = None, *, query_params: dict = None +def get_app_route_url( + route_fn: typing.Callable, *, path_params: dict = None, query_params: dict = None ) -> str: return str( furl(settings.APP_BASE_URL, query_params=query_params) diff --git a/daras_ai_v2/send_email.py b/daras_ai_v2/send_email.py index 64ba2d7b6..1a6c4a860 100644 --- a/daras_ai_v2/send_email.py +++ b/daras_ai_v2/send_email.py @@ -12,7 +12,7 @@ from app_users.models import AppUser from daras_ai_v2 import settings from daras_ai_v2.exceptions import raise_for_status -from daras_ai_v2.fastapi_tricks import get_route_url +from daras_ai_v2.fastapi_tricks import get_app_route_url from daras_ai_v2.settings import templates from gooey_ui import UploadedFile @@ -56,7 +56,7 @@ def send_low_balance_email( recipeints = "support@gooey.ai, devs@gooey.ai" html_body = templates.get_template("low_balance_email.html").render( user=user, - url=get_route_url(account_route), + url=get_app_route_url(account_route), total_credits_consumed=total_credits_consumed, settings=settings, ) diff --git a/payments/models.py b/payments/models.py index 3ce730793..a7deadc5e 100644 --- a/payments/models.py +++ b/payments/models.py @@ -9,7 +9,7 @@ from app_users.models import PaymentProvider from daras_ai_v2 import paypal, settings -from daras_ai_v2.fastapi_tricks import get_route_url +from daras_ai_v2.fastapi_tricks import get_app_route_url from .plans import PricingPlan, stripe_get_addon_product @@ -289,7 +289,7 @@ def get_external_management_url(self) -> str: case PaymentProvider.STRIPE: portal = stripe.billing_portal.Session.create( customer=self.stripe_get_customer_id(), - return_url=get_route_url(account_route), + return_url=get_app_route_url(account_route), ) return portal.url case PaymentProvider.PAYPAL: diff --git a/payments/tasks.py b/payments/tasks.py index 6c8b046d5..252064541 100644 --- a/payments/tasks.py +++ b/payments/tasks.py @@ -4,7 +4,7 @@ from app_users.models import AppUser from celeryapp import app from daras_ai_v2 import settings -from daras_ai_v2.fastapi_tricks import get_route_url +from daras_ai_v2.fastapi_tricks import get_app_route_url from daras_ai_v2.send_email import send_email_via_postmark from daras_ai_v2.settings import templates @@ -28,7 +28,7 @@ def send_monthly_spending_notification_email(user_id: int): "monthly_spending_notification_threshold_email.html" ).render( user=user, - account_url=get_route_url(account_route), + account_url=get_app_route_url(account_route), ), ) @@ -47,7 +47,7 @@ def send_monthly_budget_reached_email(user: AppUser): email_body = templates.get_template("monthly_budget_reached_email.html").render( user=user, - account_url=get_route_url(account_route), + account_url=get_app_route_url(account_route), ) send_email_via_postmark( from_address=settings.SUPPORT_EMAIL, @@ -71,7 +71,7 @@ def send_auto_recharge_failed_email(user: AppUser): email_body = templates.get_template("auto_recharge_failed_email.html").render( user=user, - account_url=get_route_url(account_route), + account_url=get_app_route_url(account_route), ) send_email_via_postmark( from_address=settings.SUPPORT_EMAIL, diff --git a/routers/account.py b/routers/account.py index 1d99d3d0a..bee214915 100644 --- a/routers/account.py +++ b/routers/account.py @@ -13,7 +13,7 @@ from daras_ai_v2 import icons, paypal from daras_ai_v2.base import RedirectException from daras_ai_v2.billing import billing_page -from daras_ai_v2.fastapi_tricks import get_route_path, get_route_url +from daras_ai_v2.fastapi_tricks import get_route_path, get_app_route_url from daras_ai_v2.grid_layout_widget import grid_layout from daras_ai_v2.manage_api_keys_widget import manage_api_keys from daras_ai_v2.meta_content import raw_build_meta_tags @@ -68,7 +68,7 @@ def payment_processing_route( }, waitingTimeMs); """, waitingTimeMs=waiting_time_sec * 1000, - redirectUrl=(get_route_url(account_route)), + redirectUrl=get_app_route_url(account_route), ) return dict( diff --git a/routers/paypal.py b/routers/paypal.py index c59668fc1..797812fae 100644 --- a/routers/paypal.py +++ b/routers/paypal.py @@ -15,7 +15,7 @@ from app_users.models import PaymentProvider, TransactionReason from daras_ai_v2 import paypal, settings from daras_ai_v2.exceptions import raise_for_status -from daras_ai_v2.fastapi_tricks import fastapi_request_json, get_route_url +from daras_ai_v2.fastapi_tricks import fastapi_request_json, get_app_route_url from payments.models import PricingPlan from payments.webhooks import PaypalWebhookHandler, add_balance_for_payment from routers.account import payment_processing_route, account_route @@ -139,8 +139,8 @@ def create_subscription(request: Request, payload: dict = fastapi_request_json): application_context={ "brand_name": "Gooey.AI", "shipping_preference": "NO_SHIPPING", - "return_url": get_route_url(payment_processing_route), - "cancel_url": get_route_url(account_route), + "return_url": get_app_route_url(payment_processing_route), + "cancel_url": get_app_route_url(account_route), }, ) return JSONResponse(content=jsonable_encoder(pp_subscription), status_code=200)