Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
lcduong committed Nov 18, 2024
1 parent baa65d0 commit 77c1c4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions server/venueless/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from urllib.parse import urlparse

def get_protocol(url):
parsed = urlparse(url)
protocol = parsed.scheme
return protocol.lower()
17 changes: 6 additions & 11 deletions server/venueless/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from venueless.core.services.world import notify_schedule_change, notify_world_change

from ..core.models import Room, World
from .utils import get_protocol

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -123,12 +124,6 @@ class CreateWorldView(APIView):
authentication_classes = [] # disables authentication
permission_classes = []

@staticmethod
def get_protocol(url):
parsed = urlparse(url)
protocol = parsed.scheme
return protocol.lower()

@staticmethod
def post(request, *args, **kwargs) -> JsonResponse:
payload = CreateWorldView.get_payload_from_token(request)
Expand Down Expand Up @@ -180,6 +175,11 @@ def post(request, *args, **kwargs) -> JsonResponse:
timezone=request.data.get("timezone") or "UTC",
config=config,
)

site_url = settings.SITE_URL
protocol = get_protocol(site_url)
world.domain = "{}://{}".format(protocol, domain_path)
return JsonResponse(model_to_dict(world, exclude=["roles"]), status=201)
except IntegrityError as e:
logger.error(f"Database integrity error while saving world: {e}")
return JsonResponse(
Expand All @@ -196,11 +196,6 @@ def post(request, *args, **kwargs) -> JsonResponse:
return JsonResponse(
{"error": "An unexpected error occurred"}, status=500
)

site_url = settings.SITE_URL
protocol = CreateWorldView.get_protocol(site_url)
world.domain = "{}://{}".format(protocol, domain_path)
return JsonResponse(model_to_dict(world, exclude=["roles"]), status=201)
else:
return JsonResponse(
{"error": "World cannot be created due to missing permission"},
Expand Down

0 comments on commit 77c1c4b

Please sign in to comment.