Skip to content

Commit

Permalink
fix flake8, isort, black code style
Browse files Browse the repository at this point in the history
  • Loading branch information
lcduong committed Oct 10, 2024
1 parent dc8212b commit d9b7427
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
3 changes: 2 additions & 1 deletion server/venueless/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import include, path, re_path
from rest_framework import routers

from . import views

world_router = routers.DefaultRouter()
Expand All @@ -15,6 +16,6 @@
"worlds/<str:world_id>/favourite-talk/",
views.UserFavouriteView.as_view(),
),
path('create-world/', views.CreateWorldView.as_view()),
path("create-world/", views.CreateWorldView.as_view()),
path("worlds/<str:world_id>/export-talk", views.ExportView.as_view()),
]
70 changes: 42 additions & 28 deletions server/venueless/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
from contextlib import suppress
from urllib.parse import urlparse

import jwt
import requests
from asgiref.sync import async_to_sync
from django.conf import settings
from django.core import exceptions
from django.db import transaction
from django.forms.models import model_to_dict
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.utils.crypto import get_random_string
from django.utils.timezone import now
from rest_framework import viewsets
from rest_framework.authentication import get_authorization_header
from rest_framework.decorators import api_view, permission_classes
from rest_framework.response import Response
from rest_framework.views import APIView
from django.forms.models import model_to_dict

from venueless.api.auth import (
ApiAccessRequiredPermission,
Expand All @@ -28,9 +31,6 @@
from venueless.core.services.world import notify_schedule_change, notify_world_change

from ..core.models import Room, World
import jwt
from django.conf import settings
from django.utils.crypto import get_random_string

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,30 +142,44 @@ def post(request, *args, **kwargs) -> JsonResponse:

# if world already exists, update it, otherwise create a new world
try:
if World.objects.filter(id=request.data.get('id')).exists():
world = World.objects.get(id=request.data.get('id'))
world.title = request.data.get('title')[request.data.get('locale')] or request.data.get('title')[
'en']
world.domain = '{}{}/{}'.format(settings.DOMAIN_PATH, settings.BASE_PATH, request.data.get('id'))
world.locale = request.data.get('locale')
world.timezone = request.data.get('timezone')
if World.objects.filter(id=request.data.get("id")).exists():
world = World.objects.get(id=request.data.get("id"))
world.title = (
request.data.get("title")[request.data.get("locale")]
or request.data.get("title")["en"]
)
world.domain = "{}{}/{}".format(
settings.DOMAIN_PATH, settings.BASE_PATH, request.data.get("id")
)
world.locale = request.data.get("locale")
world.timezone = request.data.get("timezone")
world.save()
else:
world = World.objects.create(
id=request.data.get('id'),
title=request.data.get('title')[request.data.get('locale')] or request.data.get('title')['en'],
domain='{}{}/{}'.format(settings.DOMAIN_PATH, settings.BASE_PATH, request.data.get('id')),
locale=request.data.get('locale'),
timezone=request.data.get('timezone'),
id=request.data.get("id"),
title=request.data.get("title")[request.data.get("locale")]
or request.data.get("title")["en"],
domain="{}{}/{}".format(
settings.DOMAIN_PATH,
settings.BASE_PATH,
request.data.get("id"),
),
locale=request.data.get("locale"),
timezone=request.data.get("timezone"),
config=config,
)
except Exception as e:
logger.error(f"An error occurred while creating a world: %s" % e)
return JsonResponse({'error': 'Unable to create or update world'}, status=400)
logger.error("An error occurred while creating a world: {}".format(e))
return JsonResponse(
{"error": "Unable to create or update world"}, status=400
)

return JsonResponse(model_to_dict(world, exclude=['roles']), status=201)
return JsonResponse(model_to_dict(world, exclude=["roles"]), status=201)
else:
return JsonResponse({'error': 'World cannot be created due to missing permission'}, status=403)
return JsonResponse(
{"error": "World cannot be created due to missing permission"},
status=403,
)

@staticmethod
def get_payload_from_token(request):
Expand Down Expand Up @@ -251,19 +265,19 @@ def get(request, *args, **kwargs):
talk_config = world.config.get("pretalx")
user = User.objects.filter(token_id=request.user)
talk_base_url = (
talk_config.get("domain")
+ "/"
+ talk_config.get("event")
+ "/schedule/export/"
talk_config.get("domain")
+ "/"
+ talk_config.get("event")
+ "/schedule/export/"
)
export_endpoint = "schedule." + export_type
talk_url = talk_base_url + export_endpoint
if "my" in export_type and user:
user_state = user.first().client_state
if (
user_state
and user_state.get("schedule")
and user_state.get("schedule").get("favs")
user_state
and user_state.get("schedule")
and user_state.get("schedule").get("favs")
):
talk_list = user_state.get("schedule").get("favs")
talk_list_str = ",".join(talk_list)
Expand Down Expand Up @@ -299,7 +313,7 @@ def schedule_update(request, **kwargs):

pretalx_config = request.world.config.get("pretalx", {})
if domain != get_domain(
pretalx_config.get("domain")
pretalx_config.get("domain")
) or event != pretalx_config.get("event"):
return Response("Incorrect domain or event data", status=401)

Expand Down
4 changes: 3 additions & 1 deletion server/venueless/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"VENUELESS_DJANGO_SECRET", config.get("django", "secret", fallback="")
)
BASE_PATH = config.get("venueless", "base_path", fallback="")
DOMAIN_PATH = config.get("venueless", "domain_path", fallback="https://app.eventyay.com")
DOMAIN_PATH = config.get(
"venueless", "domain_path", fallback="https://app.eventyay.com"
)
if not SECRET_KEY:
SECRET_FILE = os.path.join(DATA_DIR, ".secret")
if os.path.exists(SECRET_FILE):
Expand Down

0 comments on commit d9b7427

Please sign in to comment.