Skip to content

Commit

Permalink
rename get_route_url() -> get_app_route_url()
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jul 16, 2024
1 parent fdcf478 commit 51d53b7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 42 deletions.
5 changes: 2 additions & 3 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
22 changes: 11 additions & 11 deletions daras_ai_v2/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
)

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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 _:
Expand Down
21 changes: 9 additions & 12 deletions daras_ai_v2/bot_integration_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
),
Expand Down
6 changes: 3 additions & 3 deletions daras_ai_v2/fastapi_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ 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)
/ get_route_path(route_fn, path_params=path_params)
)


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)
Expand Down
4 changes: 2 additions & 2 deletions daras_ai_v2/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -56,7 +56,7 @@ def send_low_balance_email(
recipeints = "[email protected], [email protected]"
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,
)
Expand Down
4 changes: 2 additions & 2 deletions payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions payments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),
),
)

Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions routers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions routers/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 51d53b7

Please sign in to comment.