pluto/core/views/platforms.py

72 lines
2.0 KiB
Python
Raw Normal View History

2023-03-09 23:27:16 +00:00
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.views import View
from mixins.views import ( # ObjectRead,
ObjectCreate,
ObjectDelete,
ObjectList,
ObjectUpdate,
)
from two_factor.views.mixins import OTPRequiredMixin
2023-03-10 00:23:05 +00:00
from core.clients.platforms.agora import AgoraClient
2023-03-09 23:27:16 +00:00
from core.forms import PlatformForm
from core.models import Platform
from core.util import logs
2023-03-10 00:23:05 +00:00
from core.views.helpers import synchronize_async_helper
2023-03-09 23:27:16 +00:00
log = logs.get_logger(__name__)
2023-03-10 00:23:05 +00:00
class PlatformTrades(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/platform-trades.html"
page_title = "List of trades"
list_url_name = "trades"
list_url_args = ["type"]
context_object_name_singular = "trade"
context_object_name = "trades"
def get_queryset(self, **kwargs):
platforms = Platform.get_for_user(self.request.user)
total_trades = {}
for platform in platforms:
run = synchronize_async_helper(AgoraClient(platform))
dash = synchronize_async_helper(run.wrap_dashboard())
print("DASH", dash)
total_trades[platform.name] = dash
return total_trades
2023-03-09 23:27:16 +00:00
class PlatformList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/platform-list.html"
model = Platform
page_title = "List of platform connections"
list_url_name = "platforms"
list_url_args = ["type"]
submit_url_name = "platform_create"
class PlatformCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
model = Platform
form_class = PlatformForm
submit_url_name = "platform_create"
class PlatformUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
model = Platform
form_class = PlatformForm
submit_url_name = "platform_update"
class PlatformDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
model = Platform