Implement viewing live and DB information from account

This commit is contained in:
2022-10-21 23:57:32 +01:00
parent 1bdd49ee6a
commit 572b839c2c
10 changed files with 125 additions and 20 deletions

View File

@@ -18,6 +18,48 @@ def get_accounts(user):
accounts = Account.objects.filter(user=user)
return accounts
class AccountInfo(LoginRequiredMixin, View):
VIEWABLE_FIELDS_MODEL = ["name", "exchange", "api_key", "sandbox"]
allowed_types = ["modal", "widget", "window", "page"]
window_content = "window-content/account-info.html"
def get(self, request, type, account_id):
"""
Get the account details.
:param account_id: The id of the account.
"""
if type not in self.allowed_types:
return HttpResponseBadRequest
template_name = f"wm/{type}.html"
unique = str(uuid.uuid4())[:8]
try:
account = Account.objects.get(id=account_id, user=request.user)
except Account.DoesNotExist:
message = "Account does not exist"
message_class = "danger"
context = {
"message": message,
"message_class": message_class,
"window_content": self.window_content,
}
return render(request, template_name, context)
live_info = dict(account.get_account())
account_info = account.__dict__
account_info = {k:v for k,v in account_info.items() if k in self.VIEWABLE_FIELDS_MODEL}
if type == "page":
type = "modal"
context = {
"db_info": account_info,
"live_info": live_info,
"account_id": account_id,
"type": type,
"unique": unique,
"window_content": self.window_content,
}
return render(request, template_name, context)
class Accounts(LoginRequiredMixin, View):
allowed_types = ["modal", "widget", "window", "page"]